Link to home
Create AccountLog in
Avatar of Steynsk
SteynskFlag for Netherlands

asked on

Use RUNAS to register a OCX

Hi Experts,

I would like to register a OCX using a RUNAS script but it keeps comming and does not work.
Please help!
Option explicit
Dim oShell, password, username
set oShell= wscript.CreateObject("WScript.Shell")
username = InputBox("Please profide a username".")
password = InputBox("Please profide the password for user " & username & ".") 
oShell.Run "runas /noprofile /user:" & username & " RegSvr32 /s " & chr(34) & "C:\windows\system32\TWIZ32.OCX" & chr(34)
WScript.Sleep 200
oShell.Sendkeys password & "~"
wscript.Quit

Open in new window

Avatar of yehudaha
yehudaha
Flag of Israel image

try to increase

WScript.Sleep 200

to

WScript.Sleep 1000 or 2000

the password part is wrong and you forgot the enter
the password need to be in ""

oShell.Sendkeys "password"   'your password
oShell.Sendkeys "{ENTER}"

the password can be like this
oShell.Sendkeys chr(34) & password & chr(34)
Avatar of Steynsk

ASKER

Thanks for your kind response. I've added the changes but It does not close the script.
If I enter the password it flashes very quicky a screen and then asks for the username again. So it does not finish the script but re-runs it.

Thanks
Option explicit
Dim oShell, password, username
set oShell= wscript.CreateObject("WScript.Shell")
username = InputBox("Please profide a username.")
password = InputBox("Please profide the password for user " & username & ".") 
oShell.Run "runas /noprofile /user:" & username & " RegSvr32 /s " & chr(34) & "C:\windows\system32\TWIZ32.OCX" & chr(34)
WScript.Sleep 200
oShell.Sendkeys chr(34) & password & chr(34)
oShell.Sendkeys "{ENTER}"
wscript.Quit
 

Open in new window

it's sound like a syntax problem.

run this in command line window put the user name you want and check if it runs ok :

runas /noprofile /user:yousername RegSvr32 /s "C:\windows\system32\TWIZ32.OCX"
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Steynsk

ASKER

Excellent thank you
No problem. Thanks for the grade.

Regards,

Rob.