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

标签 vbscript output echo msgbox

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

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

有人知道该怎么做吗?谢谢!

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

最佳答案

尝试这样:

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
'**************************************************************************************************************

关于vbscript - VBS 脚本 - 需要将 msgbox 更改为 echo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29662785/

相关文章:

使用 getc() 和 putc() 在 C 中复制文件文本 - 输出文件中的二进制代码

linux - 为所有后续调用更改 shell 内置函数(例如 echo)的定义,但仅限于当前 shell 的范围内

linux - echo bash 中出现额外的百分号

xml - 使用 vbscript 递归 XML 文件

xml - Powershell自动使用新行

windows - 远程窗口上临时文件夹的位置

java - java中的控制台是什么?

PHP 如果简写并在一行中回显 - 可能吗?

mysql - 从 vbscript 连接到 mysql 时用户对数据库的访问被拒绝

vbscript - 使用 VBScript 从 ZIP 文件中提取文件