d0rkye Posted January 26, 2011 Posted January 26, 2011 I just started laying around with autoit and this is the first program i'm trying to make. I know the code is a bit messy but i'm still posting it so that i can get some feedback from you guys. The goal of tis program is tho backup your windows 7 activation data so that you can activate it after reinstalling your system, even if you are offline. YOU WILL NEED A LEGITIMATE WINDOWS 7 COPYI wouldn't recommend using it just yet because it needs some error handling and stuff. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1_1 = GUICreate("Token Tool", 272, 236, 343, 259) $backup = GUICtrlCreateButton("Backup", 8, 200, 75, 25) $Button1 = GUICtrlCreateButton("Restore", 184, 200, 75, 25) $browse = GUICtrlCreateButton("Browse", 168, 8, 83, 17) $input = GUICtrlCreateInput(@ScriptDir & "/", 8, 8, 153, 21) GUICtrlSetState(-1, $GUI_DISABLE) $Label1 = GUICtrlCreateLabel("Are the tokens present: ", 8, 32, 117, 17) $present1 = GUICtrlCreateLabel("", 180, 56, 84, 20) $present2 = GUICtrlCreateLabel("", 180, 86, 84, 20) $Label2 = GUICtrlCreateLabel("pkeyconfig.xrm-ms -->", 8, 56, 106, 17) $Label3 = GUICtrlCreateLabel("tokens.dat -->", 8, 88, 69, 17) $Check = GUICtrlCreateButton("Check", 128, 32, 91, 17) $Group1 = GUICtrlCreateGroup("Status", 8, 152, 257, 41) $status = GUICtrlCreateLabel("Idle", 24, 168, 229, 17, $SS_CENTER) GUICtrlCreateGroup("", -99, -99, 1, 1) $Label4 = GUICtrlCreateLabel("Win Key:", 8, 122, 47, 17) $key = GUICtrlCreateInput("XXXXX-XXXXX-XXXXX-XXXXX-XXXXX", 56, 120, 209, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER)) $about = GUICtrlCreateButton("About", 96, 200, 75, 25) GUISetState(@SW_SHOW) #requireadmin local $Destination While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $browse _BackupDestination() Case $backup _BackupToken() Case $Button1 _chekkey() $changeling = 'net stop sppsvc /y' GuiCtrlSetData($status, "Stoping sppsvc") _RestoreToken() $changeling = 'takeown /f "%WinDir%\System32\spp\tokens\pkeyconfig\pkeyconfig.xrm-ms' _RestoreToken() $changeling = 'cacls "%WinDir%\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform\tokens.dat" /e /g everyone:f' _RestoreToken() $changeling = 'cacls "%WinDir%\System32\spp\tokens\pkeyconfig\pkeyconfig.xrm-ms" /e /g everyone:f' _RestoreToken() $changeling = 'ren "%WinDir%\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform\tokens.dat" "tokens.bak"' _RestoreToken() $changeling = 'ren "%WinDir%\System32\spp\tokens\pkeyconfig\pkeyconfig.xrm-ms" "pkeyconfig.bak"' _RestoreToken() $changeling = 'copy ' & $Destination & 'tokens.dat "%WinDir%\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform\" & pause' _RestoreToken() $changeling = 'copy ' & $Destination & 'pkeyconfig.xrm-ms "%WinDir%\System32\spp\tokens\pkeyconfig\" & pause' _RestoreToken() $changeling = 'del "%WinDir%\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform\tokens .bak"' _RestoreToken() $changeling = 'del "%WinDir%\System32\spp\tokens\pkeyconfig\pkeyconfig.bak"' _RestoreToken() $changeling = 'net start sppsvc' GuiCtrlSetData($status, "Stopping sppsvc") _RestoreToken() $changeling = 'cscript %windir%\system32\slmgr.vbs -ipk ' & $key & '' GuiCtrlSetData($status, "Installing new key") _RestoreToken() $changeling = 'cscript %windir%\system32\slmgr.vbs -ato' GuiCtrlSetData($status, "Activating") _RestoreToken() _Complete() Case $Check _CheckToken() Case $about ShellExecute("http://www.zsenialis.com") EndSwitch WEnd Func _chekkey() if GUICtrlRead($key) = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX" Then MsgBox(0, "Error", "Please enter a valid key. Stopping Program :)") Exit EndIf EndFunc ;==>_chekkey Func _BackupDestination() $Destination = FileSelectFolder("Select backup destination", "", 7) GUICtrlSetData($input, $Destination) EndFunc ;==>_BackupDestination Func _BackupToken() FileCopy(@SystemDir & "\spp\tokens\pkeyconfig\pkeyconfig.xrm-ms", $Destination & "\pkeyconfig.xrm-ms") FileCopy(@WindowsDir & "\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform\tokens.dat", $Destination & "\tokens.dat") EndFunc ;==>_BackupToken Func _RestoreToken() RunWait(@ComSpec & " /c " & $changeling, @SystemDir, @SW_HIDE) EndFunc ;==>_RestoreToken Func _CheckToken() If FileExists(@SystemDir & "\spp\tokens\pkeyconfig\pkeyconfig.xrm-ms") Then GUICtrlSetData($present1, "YES") Else GUICtrlSetData($present1, "NO") EndIf If FileExists(@WindowsDir & "\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform\tokens.dat") Then GUICtrlSetData($present2, "YES") Else GUICtrlSetData($present2, "NO") EndIf EndFunc ;==>_CheckToken Func _Complete() MsgBox(0, "Complete", "Restore complete. Save your data WINDOWS WILL NOW RESTART") Shutdown(2) EndFunc ;==>_CompleteAny suggestions are welcome .
d0rkye Posted January 26, 2011 Author Posted January 26, 2011 (edited) So the script is ready at-least i tested it on my pc and it worked. Please if you see anything that cold be made better tel me. I put in some error management expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #requireadmin If @OSVersion <> "WIN_7" Then Msgbox(0, "Os Missmach", "Tis program is for windows 7") Exit EndIf $Form1_1 = GUICreate("Token Tool", 272, 236, 343, 259) $backup = GUICtrlCreateButton("Backup", 8, 200, 75, 25) $Button1 = GUICtrlCreateButton("Restore", 184, 200, 75, 25) $browse = GUICtrlCreateButton("Browse", 168, 8, 83, 17) $input = GUICtrlCreateInput(@ScriptDir & "\", 8, 8, 153, 21) GUICtrlSetState(-1, $GUI_DISABLE) $Label1 = GUICtrlCreateLabel("Are the tokens present: ", 8, 32, 117, 17) $present1 = GUICtrlCreateLabel("", 180, 56, 84, 20) $present2 = GUICtrlCreateLabel("", 180, 86, 84, 20) $Label2 = GUICtrlCreateLabel("pkeyconfig.xrm-ms -->", 8, 56, 106, 17) $Label3 = GUICtrlCreateLabel("tokens.dat -->", 8, 88, 69, 17) $Check = GUICtrlCreateButton("Check", 128, 32, 91, 17) $Group1 = GUICtrlCreateGroup("Status", 8, 152, 257, 41) $status = GUICtrlCreateLabel("Idle", 24, 168, 229, 17, $SS_CENTER) GUICtrlCreateGroup("", -99, -99, 1, 1) $Label4 = GUICtrlCreateLabel("Win Key:", 8, 122, 47, 17) $key = GUICtrlCreateInput("XXXXX-XXXXX-XXXXX-XXXXX-XXXXX", 56, 120, 209, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) $about = GUICtrlCreateButton("About", 96, 200, 75, 25) GUISetState(@SW_SHOW) local $Destination local $changeling While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $browse _BackupDestination() Case $backup _BackupToken() Case $Button1 _Key() _restore() Case $Check _CheckToken() Case $about ShellExecute("http://www.zsenialis.com") EndSwitch WEnd func _Key() If GUICtrlRead($key) = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX" Then $msg = MsgBox(0, "Error", "Enter a valid product key") if $msg = 1 Then EndIf EndIf EndFunc ;==>_Key Func _restore() if GUICtrlRead($key) <> "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX" and FileExists(GUICtrlRead($input) & "\pkeyconfig.xrm-ms") = 1 and FileExists(GUICtrlRead($input) & "\tokens.dat") = 1 Then $changeling = 'net stop sppsvc /y' GuiCtrlSetData($status, "Stoping sppsvc") _RestoreToken() $changeling = 'takeown /f "%WinDir%\System32\spp\tokens\pkeyconfig\pkeyconfig.xrm-ms' _RestoreToken() $changeling = 'cacls "%WinDir%\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform\tokens.dat" /e /g everyone:f' _RestoreToken() $changeling = 'cacls "%WinDir%\System32\spp\tokens\pkeyconfig\pkeyconfig.xrm-ms" /e /g everyone:f' _RestoreToken() $changeling = 'ren "%WinDir%\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform\tokens.dat" "tokens.bak"' _RestoreToken() $changeling = 'ren "%WinDir%\System32\spp\tokens\pkeyconfig\pkeyconfig.xrm-ms" "pkeyconfig.bak"' _RestoreToken() $changeling = 'copy ' & $Destination & 'tokens.dat "%WinDir%\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform\" ' _RestoreToken() $changeling = 'copy ' & $Destination & 'pkeyconfig.xrm-ms "%WinDir%\System32\spp\tokens\pkeyconfig\" ' _RestoreToken() $changeling = 'del "%WinDir%\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform\tokens .bak"' _RestoreToken() $changeling = 'del "%WinDir%\System32\spp\tokens\pkeyconfig\pkeyconfig.bak"' GuiCtrlSetData($status, "Starting sppsvc") _RestoreToken() $changeling = 'net start sppsvc' GuiCtrlSetData($status, "Installing new key") _RestoreToken() $changeling = 'cscript %windir%\system32\slmgr.vbs -ipk ' & $key & '' GuiCtrlSetData($status, "Activating") _RestoreToken() $changeling = 'cscript %windir%\system32\slmgr.vbs -ato' GuiCtrlSetData($status, "Idle") _Complete() EndIf if not FileExists(GUICtrlRead($input) & "\pkeyconfig.xrm-ms") Then MsgBox(0, "Error", "Token file missing : pkeyconfig.xrm-ms ") EndIf If Not FileExists(GUICtrlRead($input) & "\tokens.dat") Then MsgBox(0, "Error", "Token file missing : Token.dat") EndIf EndFunc ;==>_restore Func _BackupDestination() $Destination = FileSelectFolder("Select backup destination", "", 7) GUICtrlSetData($input, $Destination) EndFunc ;==>_BackupDestination Func _BackupToken() FileCopy(@SystemDir & "\spp\tokens\pkeyconfig\pkeyconfig.xrm-ms", $Destination & "\pkeyconfig.xrm-ms") FileCopy(@WindowsDir & "\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform\tokens.dat", $Destination & "\tokens.dat") EndFunc ;==>_BackupToken Func _RestoreToken() RunWait(@ComSpec & " /c " & $changeling, @SystemDir, @SW_HIDE) EndFunc ;==>_RestoreToken Func _CheckToken() If FileExists(@SystemDir & "\spp\tokens\pkeyconfig\pkeyconfig.xrm-ms") Then GUICtrlSetData($present1, "YES") Else GUICtrlSetData($present1, "NO") EndIf If FileExists(@WindowsDir & "\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform\tokens.dat") Then GUICtrlSetData($present2, "YES") Else GUICtrlSetData($present2, "NO") EndIf EndFunc ;==>_CheckToken Func _Complete() MsgBox(0, "Complete", "Restore complete. Save your data WINDOWS WILL NOW RESTART") Shutdown(2) EndFunc ;==>_Complete Edited January 26, 2011 by d0rkye
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now