Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Photo

Trying to migrate 2 VBScripts into one.

- - - - -

  • Please log in to reply
30 replies to this topic

#1
Jeffery

Jeffery

    Newbie

  • Member
  • 15 posts
  • OS:Windows 7 x64
  • Country: Country Flag

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. :wacko:

'-> Begin of the Admin Right Check Script
Set 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 If
Else

'-> Begin of the Key Changer Script
On Error Resume Next

If 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 If
Else
  VOL_PROD_KEY = WScript.Arguments.Item(0)
End If

VOL_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 If
Next

WScript.Quit

Edited by Jeffery, 08 April 2014 - 08:31 PM.



How to remove advertisement from MSFN

#2
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,798 posts
  • OS:none specified
  • Country: Country Flag

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


Posted Image


#3
Jeffery

Jeffery

    Newbie

  • Member
  • 15 posts
  • OS:Windows 7 x64
  • Country: Country Flag

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 by Jeffery, 08 April 2014 - 11:45 PM.


#4
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,798 posts
  • OS:none specified
  • Country: Country Flag

Well other than missing the last line - 

 

End If

 

the 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


Posted Image


#5
Jeffery

Jeffery

    Newbie

  • Member
  • 15 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Yes if you run only the Key Change Script but not if you migrate this 2 script i posted above into one.



#6
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,798 posts
  • OS:none specified
  • Country: Country Flag

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


Posted Image


#7
Jeffery

Jeffery

    Newbie

  • Member
  • 15 posts
  • OS:Windows 7 x64
  • Country: Country Flag

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 by Jeffery, 09 April 2014 - 01:36 AM.


#8
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,798 posts
  • OS:none specified
  • Country: Country Flag

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 If
Else
  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


Posted Image


#9
Jeffery

Jeffery

    Newbie

  • Member
  • 15 posts
  • OS:Windows 7 x64
  • Country: Country Flag

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 by Jeffery, 09 April 2014 - 02:58 AM.


#10
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,798 posts
  • OS:none specified
  • Country: Country Flag

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


Posted Image


#11
Jeffery

Jeffery

    Newbie

  • Member
  • 15 posts
  • OS:Windows 7 x64
  • Country: Country Flag

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..



#12
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,798 posts
  • OS:none specified
  • Country: Country Flag

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 script

But 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 by bphlpt, 09 April 2014 - 01:15 PM.

Posted Image


#13
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,418 posts
  • OS:none specified
  • Country: Country Flag
Here is what I can confirm
1:\ Windows 7 UAC enable
2:\ Created A User level account called Jake
3:\ Ran the from script Stackoverflow
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
    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 If
Else
  'your code here
  CreateObject("Wscript.Shell").Run("C:\Users\Jake\Desktop\RegistrationChanger.hta"),1,True
  'WScript.Echo "Code Here With Admin Rights"
End If
4:\ I was able to make reg changes that required admin rights, I had to supply
the admin right threw the standard UAC GUI.
Before Changes
Attached File  ScriptWorks1.png   82.64KB   1 downloads
After Changes
Attached File  ScriptWorks2.png   88.24KB   1 downloads


GunSmokingMan



#14
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,534 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

Can somebody please tell me why UAC is an issue for a script intended for Windows XP?



#15
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,418 posts
  • OS:none specified
  • Country: Country Flag
Maybe because of this

I did this too and i get the same results and i tried it on Windows 7 and Windows XP.




GunSmokingMan



#16
Jeffery

Jeffery

    Newbie

  • Member
  • 15 posts
  • OS:Windows 7 x64
  • Country: Country Flag

To simulate this problem it is important to migrate the RunAs script and the Key Changer together and on Windows 7 UAC needs to be turned on or you have to be on a guest account without admin rights to simulate this problem.

Run_As_and_Key_Changer_script.jpg



#17
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,418 posts
  • OS:none specified
  • Country: Country Flag
I tried my test on Win 7 UAC enable on account that had only user rights. The hta in my
script needed an admin account to make the changes to the registry keys, I was able to
make the changes on that regular user account.


GunSmokingMan



#18
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,798 posts
  • OS:none specified
  • Country: Country Flag

And it seems that the only difference between GSM's tests and that of Jeffery, is that GSM calls the external KeyChanger script while Jeffery tried to put it inline. Do I understand that correctly? Jeffery, if you try to break the KeyChanger script out into a separate file does that work correctly? I know you want it as a single file, but does it work as two files?

Cheers and Regards


Posted Image


#19
Jeffery

Jeffery

    Newbie

  • Member
  • 15 posts
  • OS:Windows 7 x64
  • Country: Country Flag

If i break the KeyChanger script out into a separate file then it works but as soon as i put them together in one file then they won't love each other anymore.



#20
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,418 posts
  • OS:none specified
  • Country: Country Flag
Since I dont want to write the whole things for you, not my job I will point you in a direction that might help you. I added a function to the script from Stackoverflow that I called Input.
 Dim A
 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
    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 If
Else
  'your code here
 ' CreateObject("Wscript.Shell").Run("C:\Users\Gunsmokingman\Desktop\RegistrationChanger.hta"),1,True
  ' CreateObject("Wscript.Shell").Run("powerCfg -H Off")
   Input()
   WScript.Echo A
End If


   Function Input() 
    Input=InputBox( _
     "Type In The New Key In This Format 12345-54321-12345-ABCDE-1A2B3.") 
    If Len(Input) = 29 Then A = Input
     If Not Len(Input) = 29 Then   
      If MsgBox( _
      "Does Not Appear To Have 29 Characters : " & Len(Input) & vbCrLf & _
      "Would You Like To Redo Your Input, Yes To Redo," & vbCrLf & _
      "No To Exit And Do Nothing?",4132,"Redo Or Quit") = 6 Then
      Input()           
     Else     
      WScript.Quit 
     End If 
    End If 
   End Function



GunSmokingMan



#21
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,534 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

Nobody has yet answered my basic question!

What is the point of the flow of this Topic? A Windows XP key changing script on Windows 7

#22
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,376 posts
  • OS:none specified
  • Country: Country Flag
To expand on Yzöwl's question, according to this:
http://msdn.microsof...0(v=vs.85).aspx
 

Requirements
Minimum supported client Windows XP

Minimum supported server Windows Server 2003

End of client support Windows XP

End of server support Windows Server 2003 R2

the win32_WindowsProductActivation class is non-existing on non-XP/2003.
 
jaclaz

#23
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,418 posts
  • OS:none specified
  • Country: Country Flag

Nobody has yet answered my basic question!

What is the point of the flow of this Topic? A Windows XP key changing script on Windows 7

1:\ The user was asking for help on how to make the script work correct.
2:\ My understanding is that the user want to change some product keys on some OS that seems to have UAC enable.
3:\ Jaclaz your wrong List Windows Product Activation Status


GunSmokingMan



#24
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,534 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

I do hope that both parties are sure of their facts...

 

...I'm staying out of this, but I know which one is correct! :whistle:



#25
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,376 posts
  • OS:none specified
  • Country: Country Flag

2:\ My understanding is that the user want to change some product keys on some OS that seems to have UAC enable.

My understanding is very similar to yours, though I suspect that the OP is slipping (and indirectly bringing down you with him :ph34r:) on a chocolate-covered banana :w00t:, just in case:
http://homepage.ntlw...red-banana.html

 

3:\ Jaclaz your wrong List Windows Product Activation Status

I may be (rare, but it can happen ;)), but  I did not actually state anything, I simply reported a source "as is".
Just for the record here:
http://gallery.techn...6a-575226b6e8ed
there is this text:

Verified on the following platforms
Windows Server 2012 No
Windows Server 2008 R2 No
Windows Server 2008 No
Windows Server 2003 Yes
Windows 8 No
Windows 7 No
Windows Vista No
Windows XP Yes
Windows 2000 No

which may also be "wrong", but it is possibly a hint that the referenced page is actually "right" :whistle:

And, JFYI:
http://sqlblog.com/b...n-en-masse.aspx

Whenever I do anything with this number of machines, I assume there's an easy way to do it in PowerShell. My searching throughout the 'toobz led to many promising scripts; unfortunately, most dealt with the old WMI class used prior to Windows 7 and Windows Server 2008 R2: Win32_WindowsProductActivation. In the latest versions of the operating system, trying to utilize this class leads to generic "Invalid Class" errors; the methods and properties associated with this class have been split out into two new classes: SoftwareLicensingProduct and SoftwareLicensingService (did I mention I'm really glad they're moving away from the Win32_ prefix?).

 
jaclaz


Edited by jaclaz, 10 April 2014 - 09:44 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users



How to remove advertisement from MSFN