1

我想更改 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
4

1 回答 1

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
于 2013-06-06T13:52:25.617 回答