Jump to content

VBS script changes Windows XP CD Key


 Share

Recommended Posts

I've got a VBS script which changes Windows XP CD Key. I'm putting together a script to install a bunch of updates, registry tweaks, security patches, etc... During this I'd like to change the Windows key to our VLK.

Right now I'm using the below VBS script outside of AutoIT. I'd like to have AutoIT do it so everyting is compact and easy. Can AutoIT change my Windows CD Key? If so how would I go about that?

ON ERROR RESUME NEXT

Dim VOL_PROD_KEY
if Wscript.arguments.count<1 then
 Const ForAppending = 8 

 Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objFile = objFSO.CreateTextFile("C:\ScriptLog.txt") 
 Set objFile = objFSO.OpenTextFile("C:\ScriptLog.txt", ForAppending) 

 objFile.WriteLine GetWindowsSN  

 objFile.Close 
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)
Next 


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 
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") 
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 
If i Mod 5 = 0 And i <> 0 Then strProductKey = "-" & strProductKey 
Next 
GetWindowsSN = strProductKey 
End Function
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...