1 (изменено: ddp, 2013-01-12 13:41:12)

Тема: VBS - запись ключа windows в текстовый файл

Добрый день. Подскажите пожалуйста, имеется vbs скрипт для определения ключа продукта Windows. Он выводит его в сообщение [MsgBox(Win8ProductKey)]. Как сделать, чтобы он записал его в текстовый файл во временную папку (скажем %TEMP%\1.txt)? Заранее спасибо.

Скрипт:

Set WshShell = CreateObject("WScript.Shell")
regKey = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
DigitalProductId = WshShell.RegRead(regKey & "DigitalProductId")
 
Win8ProductName = "Windows Product Name: " & WshShell.RegRead(regKey & "ProductName") & vbNewLine
Win8ProductID = "Windows Product ID: " & WshShell.RegRead(regKey & "ProductID") & vbNewLine
Win8ProductKey = ConvertToKey(DigitalProductId)
strProductKey ="Windows 8 Key: " & Win8ProductKey 
Win8ProductID = Win8ProductName & Win8ProductID & strProductKey 
 
MsgBox(Win8ProductKey)

 
Function ConvertToKey(regKey)
    Const KeyOffset = 52
    isWin8 = (regKey(66) \ 6) And 1
    regKey(66) = (regKey(66) And &HF7) Or ((isWin8 And 2) * 4)
    j = 24
    Chars = "BCDFGHJKMPQRTVWXY2346789"
    Do
        Cur = 0
        y = 14
        Do
            Cur = Cur * 256
            Cur = regKey(y + KeyOffset) + Cur
            regKey(y + KeyOffset) = (Cur \ 24)
            Cur = Cur Mod 24
            y = y -1
        Loop While y >= 0
        j = j -1
        winKeyOutput = Mid(Chars, Cur + 1, 1) & winKeyOutput
        Last = Cur
    Loop While j >= 0
    If (isWin8 = 1) Then
        keypart1 = Mid(winKeyOutput, 2, Last)
        insert = "N"
        winKeyOutput = Replace(winKeyOutput, keypart1, keypart1 & insert, 2, 1, 0)
        If Last = 0 Then winKeyOutput = insert & winKeyOutput
    End If
    a = Mid(winKeyOutput, 1, 5)
    b = Mid(winKeyOutput, 6, 5)
    c = Mid(winKeyOutput, 11, 5)
    d = Mid(winKeyOutput, 16, 5)
    e = Mid(winKeyOutput, 21, 5)
    ConvertToKey = a & "-" & b & "-" & c & "-" & d & "-" & e
End Function

2 (изменено: omegastripes, 2013-01-12 23:16:13)

Re: VBS - запись ключа windows в текстовый файл

with createobject("scripting.filesystemobject").createtextfile(createobject("wscript.shell").expandenvironmentstrings("%TEMP%\1.txt"), true)
    .write(Win8ProductKey)
    .close
end with

или читабельный вариант:

dim shell, filename, fso, textfile
set shell = createobject("wscript.shell")
filename = shell.expandenvironmentstrings("%TEMP%\1.txt")
set shell = nothing
set fso = createobject("scripting.filesystemobject")
set textfile = fso.createtextfile(filename, true)
textfile.write(win8productkey)
textfile.close
set textfile = nothing
set fso = nothing
Щт Уккщк Куыгьу Туче
’ҐЄгй п Є®¤®ў п бва Ёж : 1251

3

Re: VBS - запись ключа windows в текстовый файл

OFF:

omegastripes пишет:

или читабельный вариант:

На мой взгляд, первый вариант на порядок понятнее.