Dim VOL_PROD_KEY
If WScript.arguments.Count<1 Then
VOL_PROD_KEY = InputBox("您當前的Windows系統序號為:" & GetWindowsSN & String(5, vbCrLf) & "請輸入新的Windows序號:", "Windows序號更換器", SN_2003_1)
If VOL_PROD_KEY = "" Or Len(VOL_PROD_KEY)<>29 Then
WScript.echo "您選擇了取消 或 Windows序號為空白 或 Windows序號位元有誤 ——》退出"
WScript.Quit
End If
Else
VOL_PROD_KEY = WScript.arguments.Item(0)
End If
VOL_PROD_KEY = Replace(VOL_PROD_KEY, "-", "") 'remove hyphens if any
For Each Obj in GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf ("win32_WindowsProductActivation")
result = Obj.SetProductKey (VOL_PROD_KEY)
If Err = 0 Then
WScript.echo "Windows序號替換成功。"
Else
WScript.echo "Windows序號替換失敗!您輸入的序號有誤。"
Err.Clear
End If
Next
'取得當前Windows序號函數
Function GetWindowsSN()
Const HKEY_LOCAL_MACHINE = &H80000002
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
strValueName = "DigitalProductId"
strComputer = "."
Dim iValues()
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
oReg.GetBinaryValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, iValues
Dim arrDPID
arrDPID = Array()
For i = 52 To 66
ReDim Preserve arrDPID( UBound(arrDPID) + 1 )
arrDPID( UBound(arrDPID) ) = iValues(i)
Next
' <--------------- Create an array to hold the valid characters for a microsoft Product Key -------------------------->
Dim arrChars
arrChars = Array("B", "C", "D", "F", "G", "H", "J", "K", "M", "P", "Q", "R", "T", "V", "W", "X", "Y", "2", "3", "4", "6", "7", "8", "9")
' <--------------- The clever bit !!! (Decrypt the base24 encoded binary data)-------------------------->
For i = 24 To 0 Step -1
k = 0
For j = 14 To 0 Step -1
k = k * 256 Xor arrDPID(j)
arrDPID(j) = Int(k / 24)
k = k Mod 24
Next
strProductKey = arrChars(k) & strProductKey
' <------- add the "-" between the groups of 5 Char -------->
If i Mod 5 = 0 And i <> 0 Then strProductKey = "-" & strProductKey
Next
GetWindowsSN = strProductKey
End Function