Vbscript VBS脚本-需要将msgbox更改为echo

Vbscript VBS脚本-需要将msgbox更改为echo,vbscript,output,echo,msgbox,Vbscript,Output,Echo,Msgbox,我很难将此脚本转换为echo而不是msgbox输出 我需要输出到C:\key.log中的文本文件,而不是带有密钥的消息框 有人知道怎么做吗?谢谢 Set WshShell = CreateObject("WScript.Shell") MsgBox ConvertToKey(WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId")) Function ConvertToKey(K

我很难将此脚本转换为echo而不是msgbox输出

我需要输出到C:\key.log中的文本文件,而不是带有密钥的消息框

有人知道怎么做吗?谢谢

Set WshShell = CreateObject("WScript.Shell")
MsgBox ConvertToKey(WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"))

Function ConvertToKey(Key)
Const KeyOffset = 52
i = 28
Chars = "BCDFGHJKMPQRTVWXY2346789"
Do
Cur = 0
x = 14
Do
Cur = Cur * 256
Cur = Key(x + KeyOffset) + Cur
Key(x + KeyOffset) = (Cur \ 24) And 255
Cur = Cur Mod 24
x = x -1
Loop While x >= 0
i = i -1
KeyOutput = Mid(Chars, Cur + 1, 1) & KeyOutput
If (((29 - i) Mod 6) = 0) And (i <> -1) Then
i = i -1
KeyOutput = "-" & KeyOutput
End If
Loop While i >= 0
ConvertToKey = KeyOutput
End Function
Set WshShell=CreateObject(“WScript.Shell”)
MsgBox ConvertToKey(WshShell.regrad(“HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId”))
功能转换键(键)
常数KeyOffset=52
i=28
Chars=“BCDFGHJKMPQRTVWXY2346789”
做
Cur=0
x=14
做
Cur=Cur*256
Cur=键(x+键偏移量)+Cur
键(x+KeyOffset)=(Cur\24)和255
Cur=Cur Mod 24
x=x-1
当x>=0时循环
i=i-1
KeyOutput=Mid(字符、电流+1、1)和KeyOutput
如果((29-i)Mod 6)=0)和(i-1),则
i=i-1
KeyOutput=“-”&KeyOutput
如果结束
当i>=0时循环
CONVERTOKEY=KeyOutput
端函数

下面的代码将echo语句替换为对(FSO)的调用。此对象可以在Web服务器或桌面上添加、移动、更改、创建或删除文件夹(目录)和文件。我们特别感兴趣的方法是

DIM fso、新闻文件、WshShell
设置WshShell=CreateObject(“WScript.Shell”)
设置fso=CreateObject(“Scripting.FileSystemObject”)
设置write2File=fso.CreateTextFile(“C:\key.log”,True)
write2File.WriteLine(ConvertToKey(WshShell.regrad(“HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId”))
write2File.Close
功能转换键(键)
常数KeyOffset=52
i=28
Chars=“BCDFGHJKMPQRTVWXY2346789”
做
Cur=0
x=14
做
Cur=Cur*256
Cur=键(x+键偏移量)+Cur
键(x+KeyOffset)=(Cur\24)和255
Cur=Cur Mod 24
x=x-1
当x>=0时循环
i=i-1
KeyOutput=Mid(字符、电流+1、1)和KeyOutput
如果((29-i)Mod 6)=0)和(i-1),则
i=i-1
KeyOutput=“-”&KeyOutput
如果结束
当i>=0时循环
CONVERTOKEY=KeyOutput
端函数
使用wscript运行时输出msgbox,在命令提示下使用cscript运行时回显到STDOUT

cmd /c cscript //nologo c:\somepath\somefile.vbs > file.txt
试着这样做:

Option Explicit
Dim WshShell,RegKey,WindowsKey,LogFile,fso
Set WshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
RegKey = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"
WindowsKey = ConvertToKey(WshShell.RegRead(RegKey))
LogFile = "c:\key.log"
if fso.FileExists(LogFile) Then 
    fso.DeleteFile LogFile
end If
MsgBox WindowsKey,VbInformation,WindowsKey 
Call WriteLog(WindowsKey,LogFile)
WshShell.Run LogFile
'***********************************************************************************************************
Function ConvertToKey(Key)
    Const KeyOffset = 52
    Dim i,Chars,Cur,x,KeyOutput
    i = 28
    Chars = "BCDFGHJKMPQRTVWXY2346789"
    Do
        Cur = 0
        x = 14
        Do
            Cur = Cur * 256
            Cur = Key(x + KeyOffset) + Cur
            Key(x + KeyOffset) = (Cur \ 24) And 255
            Cur = Cur Mod 24
            x = x -1
        Loop While x >= 0
        i = i -1
        KeyOutput = Mid(Chars, Cur + 1, 1) & KeyOutput
        If (((29 - i) Mod 6) = 0) And (i <> -1) Then
            i = i -1
            KeyOutput = "-" & KeyOutput
        End If
    Loop While i >= 0
    ConvertToKey = KeyOutput
End Function
'*************************************************************************************************************
Sub WriteLog(strText,LogFile)
    Dim fs,ts 
    Const ForAppending = 8
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set ts = fs.OpenTextFile(LogFile,ForAppending,True)
    ts.WriteLine strText
    ts.Close
End Sub
'**************************************************************************************************************
选项显式
Dim WshShell、RegKey、WindowsKey、日志文件、fso
设置WshShell=CreateObject(“WScript.Shell”)
设置fso=CreateObject(“Scripting.FileSystemObject”)
RegKey=“HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId”
WindowsKey=ConvertToKey(WshShell.regrad(RegKey))
LogFile=“c:\key.log”
如果存在fso.files(日志文件),则
fso.DeleteFile日志文件
如果结束
MsgBox WindowsKey,VbInformation,WindowsKey
调用WriteLog(WindowsKey,日志文件)
运行日志文件
'***********************************************************************************************************
功能转换键(键)
常数KeyOffset=52
尺寸i、字符、电流、x、按键输出
i=28
Chars=“BCDFGHJKMPQRTVWXY2346789”
做
Cur=0
x=14
做
Cur=Cur*256
Cur=键(x+键偏移量)+Cur
键(x+KeyOffset)=(Cur\24)和255
Cur=Cur Mod 24
x=x-1
当x>=0时循环
i=i-1
KeyOutput=Mid(字符、电流+1、1)和KeyOutput
如果((29-i)Mod 6)=0)和(i-1),则
i=i-1
KeyOutput=“-”&KeyOutput
如果结束
当i>=0时循环
CONVERTOKEY=KeyOutput
端函数
'*************************************************************************************************************
子写入日志(strText,日志文件)
暗fs,ts
出现的常数=8
设置fs=CreateObject(“Scripting.FileSystemObject”)
设置ts=fs.OpenTextFile(LogFile,ForAppending,True)
ts.WriteLine strText
关闭
端接头
'**************************************************************************************************************

运行此.VBS脚本时出现以下错误。-Char:1错误:需要对象:“WshShell”代码:800A01A8来源:Microsoft VBScript运行时错误他忘记添加此行:Set WshShell=CreateObject(“WScript.Shell”),因此如果添加此行,它应该可以工作;)@WorkSmarter,你应该得到我的+1;)@WorkSmarter我使用此脚本作为在后台工作的辅助选项,非常感谢!因此,您只需将
msgbox
替换为
wscript.echo
,并正确启动它。这太棒了,我最终使用了这个脚本,因为它在为用户提取Windows密钥后打开了文本文件。非常感谢。
cmd /c cscript //nologo c:\somepath\somefile.vbs > file.txt
Option Explicit
Dim WshShell,RegKey,WindowsKey,LogFile,fso
Set WshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
RegKey = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"
WindowsKey = ConvertToKey(WshShell.RegRead(RegKey))
LogFile = "c:\key.log"
if fso.FileExists(LogFile) Then 
    fso.DeleteFile LogFile
end If
MsgBox WindowsKey,VbInformation,WindowsKey 
Call WriteLog(WindowsKey,LogFile)
WshShell.Run LogFile
'***********************************************************************************************************
Function ConvertToKey(Key)
    Const KeyOffset = 52
    Dim i,Chars,Cur,x,KeyOutput
    i = 28
    Chars = "BCDFGHJKMPQRTVWXY2346789"
    Do
        Cur = 0
        x = 14
        Do
            Cur = Cur * 256
            Cur = Key(x + KeyOffset) + Cur
            Key(x + KeyOffset) = (Cur \ 24) And 255
            Cur = Cur Mod 24
            x = x -1
        Loop While x >= 0
        i = i -1
        KeyOutput = Mid(Chars, Cur + 1, 1) & KeyOutput
        If (((29 - i) Mod 6) = 0) And (i <> -1) Then
            i = i -1
            KeyOutput = "-" & KeyOutput
        End If
    Loop While i >= 0
    ConvertToKey = KeyOutput
End Function
'*************************************************************************************************************
Sub WriteLog(strText,LogFile)
    Dim fs,ts 
    Const ForAppending = 8
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set ts = fs.OpenTextFile(LogFile,ForAppending,True)
    ts.WriteLine strText
    ts.Close
End Sub
'**************************************************************************************************************