Avatar of Steynsk
Steynsk
Flag 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

VB ScriptShell Scripting

Avatar of undefined
Last Comment
RobSampson

8/22/2022 - Mon
yehudaha

try to increase

WScript.Sleep 200

to

WScript.Sleep 1000 or 2000

yehudaha

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

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
yehudaha

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
RobSampson

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Steynsk

ASKER
Excellent thank you
RobSampson

No problem. Thanks for the grade.

Regards,

Rob.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.