Jeffery Posted April 9, 2014 Share Posted April 9, 2014 (edited) HI,I'm trying to migrate 2 VBScripts that i found on the internet into one script.The first Scripts checks if the user has Admin Rights and the second script is a Key Changer.But if i migrate this 2 scripts into one script and when i then execute it then it wants to add "relaunch" as a Key. '-> Begin of the Admin Right Check ScriptSet reg = GetObject("winmgmts://./root/default:StdRegProv")rc = reg.GetStringValue(&h80000003, "S-1-5-19\Environment", "TEMP", val)If rc = 5 Then If WScript.Arguments.Count = 0 Then CreateObject("Shell.Application").ShellExecute "wscript.exe" _ , Chr(34) & WScript.ScriptFullName & Chr(34) & " relaunch", "", "runas", 1 WScript.Quit Else WScript.Echo "Cannot acquire admin privileges." WScript.Quit End IfElse'-> Begin of the Key Changer ScriptOn Error Resume NextIf WScript.Arguments.Count<1 Then VOL_PROD_KEY = InputBox ("This script will change the product key of:"&vbCr&"Windows XP SP1, SP2 and SP3."&vbCr&vbCr&"Enter a correct CD-Key in the blank field below:","Windows XP Key Changer") If VOL_PROD_KEY = "" Then WScript.Quit End IfElse VOL_PROD_KEY = WScript.Arguments.Item(0)End IfVOL_PROD_KEY = Replace(VOL_PROD_KEY,"-","")for each Obj in GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf ("win32_WindowsProductActivation") result = Obj.SetProductKey (VOL_PROD_KEY) If Err.Number = 0 Then WScript.Echo "Windows XP Product Key was changed successfuly." End If If Err.Number <> 0 Then WScript.Echo "Error entering new product key: "&VOL_PROD_KEY&""&vbCr&vbCr&"Please verify that this Product Key was entered correctly and if it is a valid key." Err.Number.Clear End IfNextWScript.Quit Edited April 9, 2014 by Jeffery Link to comment Share on other sites More sharing options...
bphlpt Posted April 9, 2014 Share Posted April 9, 2014 How, EXACTLY, are you launching the script, ie what is the command line you are using? What were you expecting to happen? Also, for reference, give us the link(s) where you found these scripts? Is there a particular reason you were trying to combine these into a single script?Cheers and Regards Link to comment Share on other sites More sharing options...
Jeffery Posted April 9, 2014 Author Share Posted April 9, 2014 (edited) When double clicking on the script an input box should appear to enter a key and if the user has no admin rights then the Windows RunAs option should appear first.The RunAs script i found at stackoverflow.com and the Key Changer script i found at pastebin. Edited April 9, 2014 by Jeffery Link to comment Share on other sites More sharing options...
bphlpt Posted April 9, 2014 Share Posted April 9, 2014 Well other than missing the last line - End Ifthe above code looks fine to me and seems to run correctly. At least I get the input box when I tried it on my Win7 system. ( I cancelled it of course.)Cheers and Regards Link to comment Share on other sites More sharing options...
Jeffery Posted April 9, 2014 Author Share Posted April 9, 2014 Yes if you run only the Key Change Script but not if you migrate this 2 script i posted above into one. Link to comment Share on other sites More sharing options...
bphlpt Posted April 9, 2014 Share Posted April 9, 2014 Not what I meant. I copied your exact combined script from above and added the last line and it worked for me in Win7.Cheers and Regards Link to comment Share on other sites More sharing options...
Jeffery Posted April 9, 2014 Author Share Posted April 9, 2014 (edited) I did this too and i get the same results and i tried it on Windows 7 and Windows XP. It only works if i run then Key Changer script without the RunAs script.Are you sure the UAC option is on in your Windows 7 because if it is not then the RunAs Script will not run completely. Edited April 9, 2014 by Jeffery Link to comment Share on other sites More sharing options...
bphlpt Posted April 9, 2014 Share Posted April 9, 2014 I also used the "original" RunAs Script, and added some extra Echo'ed messages to make sure it got where I thought it was:Set reg = GetObject("winmgmts://./root/default:StdRegProv")rc = reg.GetStringValue(&h80000003, "S-1-5-19\Environment", "TEMP", val)If rc = 5 Then 'return code 5 == access denied 're-launch script only when it was run without arguments, so we don't go 'in circles when admin privileges can't be acquired If WScript.Arguments.Count = 0 Then 're-launch as administrator; the additional argument is a guard to make 'sure the script is re-launched only once WScript.Echo "Relaunch." CreateObject("Shell.Application").ShellExecute "wscript.exe" _ , Chr(34) & WScript.ScriptFullName & Chr(34) & " relaunch", "", "runas", 1 WScript.Quit 0 Else WScript.Echo "Cannot acquire admin privileges." WScript.Quit 1 End IfElse WScript.Echo "Have Admin." '-> Begin of the Key Changer Script ... the rest of your script here ... But no, I'm an admin and I have UAC disabled, but I still got the "Have Admin" message then the input box was displayed.Cheers and Regards Link to comment Share on other sites More sharing options...
Jeffery Posted April 9, 2014 Author Share Posted April 9, 2014 (edited) The problem occurs if you have UAC enabled or if you are on a guest account. You have UAC disabled that's why you don't get the same results as me. Edited April 9, 2014 by Jeffery Link to comment Share on other sites More sharing options...
bphlpt Posted April 9, 2014 Share Posted April 9, 2014 Then the problem is not the combining of the two scripts, but rather the function of the UAC script. Looks like you need to modify it in some way.Cheers and Regards Link to comment Share on other sites More sharing options...
Jeffery Posted April 9, 2014 Author Share Posted April 9, 2014 I tested the RunAs script also combined with another script and it works like it should there is only a conflict if i use it with the Key Changer script.The point of the RunAs script is to check if a user has admin rights and if not then it promotes the user for elevated (Windows 7) or it promotes the user to run the script with a account which has admin privileges.. Link to comment Share on other sites More sharing options...
bphlpt Posted April 9, 2014 Share Posted April 9, 2014 (edited) So it works in all cases UNLESS:1) you have UAC enabled or if you are on a guest account- and -2) you run the the RunAs script- combined only with -3) the Key Changer scriptBut otherwise both scripts work? Very specific, weird circumstances.If nothing else I would suggest adding several echo messages to determine exactly where it goes wrong.Cheers and Regards Edited April 9, 2014 by bphlpt Link to comment Share on other sites More sharing options...
gunsmokingman Posted April 9, 2014 Share Posted April 9, 2014 Here is what I can confirm1:\ Windows 7 UAC enable2:\ Created A User level account called Jake3:\ Ran the from script StackoverflowSet reg = GetObject("winmgmts://./root/default:StdRegProv")rc = reg.GetStringValue(&h80000003, "S-1-5-19\Environment", "TEMP", val)If rc = 5 Then 'return code 5 == access denied 're-launch script only when it was run without arguments, so we don't go 'in circles when admin privileges can't be acquired If WScript.Arguments.Count = 0 Then 're-launch as administrator; the additional argument is a guard to make 'sure the script is re-launched only once CreateObject("Shell.Application").ShellExecute "wscript.exe" _ , Chr(34) & WScript.ScriptFullName & Chr(34) & " relaunch", "", "runas", 1 WScript.Quit 0 Else WScript.Echo "Cannot acquire admin privileges." WScript.Quit 1 End IfElse 'your code here CreateObject("Wscript.Shell").Run("C:\Users\Jake\Desktop\RegistrationChanger.hta"),1,True 'WScript.Echo "Code Here With Admin Rights"End If4:\ I was able to make reg changes that required admin rights, I had to supplythe admin right threw the standard UAC GUI.Before ChangesAfter Changes Link to comment Share on other sites More sharing options...
Yzöwl Posted April 9, 2014 Share Posted April 9, 2014 Can somebody please tell me why UAC is an issue for a script intended for Windows XP? Link to comment Share on other sites More sharing options...
gunsmokingman Posted April 9, 2014 Share Posted April 9, 2014 Maybe because of this I did this too and i get the same results and i tried it on Windows 7 and Windows XP. Link to comment Share on other sites More sharing options...
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