在Windows XP中更改产品密钥

时间:2013-06-06 13:26:37

标签: vbscript windows-xp

我想更改Windows XP SP3机器的产品密钥。我找到了下面的代码,但我想要一个对话框,要求换一个新的产品密钥并替换旧的产品密钥。

' 
' WMI Script - ChangeVLKey.vbs
'
' This script changes the product key on the computer
'
'***************************************************************************

ON ERROR RESUME NEXT


if Wscript.arguments.count<1 then
  Wscript.echo "Script can't run without VolumeProductKey argument"
  Wscript.echo "Correct usage: Cscript ChangeVLKey.vbs ABCDE-FGHIJ-KLMNO-PRSTU-WYQZX"
  Wscript.quit
end if

Dim VOL_PROD_KEY
VOL_PROD_KEY = Wscript.arguments.Item(0)
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 Err.Description, "0x" & Hex(Err.Number)
    Err.Clear
  end if

Next

1 个答案:

答案 0 :(得分:0)

替换

VOL_PROD_KEY = Wscript.arguments.Item(0)

用这个:

VOL_PROD_KEY = InputBox("Enter the new product key.")

请注意,您应添加代码以处理用户点击Cancel或输入格式错误的产品密钥的情况。

Set re = New RegExp
re.Pattern = "^[a-z0-9]{5}(-[a-z0-9]{5}){4}$"
re.IgnoreCase = True

If IsEmpty(VOL_PROD_KEY) Then
  'user pressed Cancel
ElseIf Not re.Test(VOL_PROD_KEY) Then
  'malformed product key
Else
  'product key OK
End If