i wouldn't be exposing admin credentials either way, I running all my scripts hidden :)
Main Topics
Browse All TopicsHello Experts,
I need to create a login script that will unregister an ocx file, then copy down a new one, then register said new one. My problem is not the commands in the script but how to run it as a user with sufficient rights. Some users that are made to execute the script below are nowhere near local admins, they are very restricted users. Basically what I need is a "run as" command within the script.
This is what I have so far
regsvr32 -u "%systemroot%\Downloaded Program Files\phone.ocx"
copy "\\10.168.0.62\activex\pho
regsvr32 "%systemroot%\Downloaded Program Files\phone.ocx"
Thanks!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
The source still sits on your network though, doesn't it?
I'm against using runas for this type of solution...for that purpose...
But, if you insist...
(not fully tested, so try it out and let me know - or you can wait till I post back that I've tested it here)
Dim oShell
Set oShell = WScript.CreateObject ("WScript.shell")
set strReg="%systemroot%\Downl
strAdmin="Domain\Admin"
strPW="Password"
oShell.run "cmd /c runas /user:" & strAdmin & "regsvr32 -u " & strReg
wscript.Sleep 1000
oShell.SendKeys strPW
oShell.Run "copy "\\10.168.0.62\activex\pho
WScript.Sleep 5000
oShell.run "cmd /c runas /user:" & strAdmin & "regsvr32 " & strReg
wscript.Sleep 1000
oShell.SendKeys strPW
set oShell=Nothing
Slight correction - added comments as well....save as NewOCXreg.vbs
'NewOCXreg.vbs
Dim oShell, oEnv 'Declarations
Set oShell = WScript.CreateObject ("WScript.shell") 'connect to shell
Set oEnv = oShell.Environment("Proces
set strReg="%systemroot%\Downl
strAdmin="Domain\Admin" 'Admin logon name
strPW="Password" 'Admin password
'Unregister file
oShell.run "cmd /c runas /user:" & strAdmin & " " & chr(34) & "regsvr32 -u " & strReg & chr(34)
wscript.Sleep 1000 'wait
oShell.AppActivate oEnv("SystemRoot") & "\system32\runas.exe" 'find runas
wscript.slee 2000 'wait
oShell.SendKeys strPW & "~" 'send password and Enter
wscript.sleep 30000 'wait 30 seconds before proceeding to give the system time to unregister the file
'Copy file
oShell.Run "copy "\\10.168.0.62\activex\pho
WScript.Sleep 10000 'wait 10 seconds for the file to be copied
'Register file
oShell.run "cmd /c runas /user:" & strAdmin & " " & chr(34) & "regsvr32 " & strReg & chr(34)
wscript.Sleep 1000 'wait
oShell.AppActivate oEnv("SystemRoot") & "\system32\runas.exe" 'find runas
wscript.slee 2000 'wait
oShell.SendKeys strPW & "~" 'send password and Enter
wscript.sleep 30000 'wait 30 seconds before proceeding to give the system time to register the file
set oEnv=Nothing
set oShell=Nothing
Any questions, let me know.
Please test it on a test machine before deploying...
One problem, I misspelled sleep:
wscript.slee 2000 'wait 'should be sleep
but that doesn't look like line 20
Presumably it's the copy...
oShell.Run "copy "\\10.168.0.62\activex\pho
Shell the shell :)
oShell.Run "cmd /c copy "\\10.168.0.62\activex\pho
and it should work...
still getting error
Line: 20
Char: 27
this is how it looks (changed admin/pass) :
'NewOCXreg.vbs
Dim oShell, oEnv 'Declarations
Set oShell = WScript.CreateObject ("WScript.shell") 'connect to shell
Set oEnv = oShell.Environment("Proces
set strReg="%systemroot%\Downl
strAdmin="domain\admin" 'Admin logon name
strPW="password" 'Admin password
'Unregister file
oShell.run "cmd /c runas /user:" & strAdmin & " " & chr(34) & "regsvr32 -u " & strReg & chr(34)
wscript.Sleep 1000 'wait
oShell.AppActivate oEnv("SystemRoot") & "\system32\runas.exe" 'find runas
wscript.sleep 2000 'wait
oShell.SendKeys strPW & "~" 'send password and Enter
wscript.sleep 30000 'wait 30 seconds before proceeding to give the system time to unregister the file
'Copy file
oShell.Run "cmd /c copy "\\10.168.0.62\activex\pho
WScript.Sleep 10000 'wait 10 seconds for the file to be copied
'Register file
oShell.run "cmd /c runas /user:" & strAdmin & " " & chr(34) & "regsvr32 " & strReg & chr(34)
wscript.Sleep 1000 'wait
oShell.AppActivate oEnv("SystemRoot") & "\system32\runas.exe" 'find runas
wscript.sleep 2000 'wait
oShell.SendKeys strPW & "~" 'send password and Enter
wscript.sleep 30000 'wait 30 seconds before proceeding to give the system time to register the file
set oEnv=Nothing
set oShell=Nothing
OH - now I see it...
You can't have multiple quotes...have to use chr instead...
This
oShell.Run "cmd /c copy "\\10.168.0.62\activex\pho
should be
oShell.Run "cmd /c copy \\10.168.0.62\activex\phon
Try this and let me know...
Dim objFSO, oShell, oEnv 'Declarations
Set oShell = CreateObject("WScript.shel
Set oEnv = oShell.Environment("Proces
Set objFSO = CreateObject("Scripting.Fi
'Grab the short path name for Downloaded Program Files
If objFSO.FolderExists(oShell
Set objFolder = objFSO.GetFolder(oShell.Ex
strDPF = objFolder.ShortPath
End If
strReg = strDPF & "\phone.ocx" 'path to ocx
strAdmin = "domain\admin" 'Admin logon name
strPW = "password" 'Admin password
'Unregister file
oShell.Run "cmd /k runas /user:" & strAdmin & " " & Chr(34) & "regsvr32 -u " & strReg & Chr(34)
wscript.sleep 1000 'wait
oShell.AppActivate oEnv("SystemRoot") & "\system32\runas.exe" 'find runas
wscript.sleep 2000 'wait
oShell.SendKeys strPW & "~" 'send password and Enter
wscript.sleep 30000 'wait 30 seconds before proceeding to give the system time to unregister the file
'Copy file
oShell.Run "cmd /c copy \\10.168.0.62\activex\phon
wscript.sleep 10000 'wait 10 seconds for the file to be copied
'Register file
oShell.Run "cmd /k runas /user:" & strAdmin & " " & Chr(34) & "regsvr32 " & strReg & Chr(34)
wscript.sleep 1000 'wait
oShell.AppActivate oEnv("SystemRoot") & "\system32\runas.exe" 'find runas
wscript.sleep 2000 'wait
oShell.SendKeys strPW & "~" 'send password and Enter
wscript.sleep 30000 'wait 30 seconds before proceeding to give the system time to register the file
Set oEnv = Nothing
Set oShell = Nothing
Set objFSO=Nothing
this is the script in its entirety as I have it:
__________________________
Dim objFSO, oShell, oEnv 'Declarations
Set oShell = CreateObject("WScript.shel
Set oEnv = oShell.Environment("Proces
Set objFSO = CreateObject("Scripting.Fi
'Grab the short path name for Downloaded Program Files
If objFSO.FolderExists(oShell
Set objFolder = objFSO.GetFolder(oShell.Ex
strDPF = objFolder.ShortPath
End If
strReg = strDPF & "\phone.ocx" 'path to ocx
strAdmin = "DINT000\PHONEM" 'Admin logon name
strPW = "adm*Cnm#" 'Admin password
'Unregister file
oShell.Run "cmd /k runas /user:" & strAdmin & " " & Chr(34) & "regsvr32 -u " & strReg & Chr(34)
wscript.sleep 1000 'wait
oShell.AppActivate oEnv("SystemRoot") & "\system32\runas.exe" 'find runas
wscript.sleep 2000 'wait
oShell.SendKeys strPW & "~" 'send password and Enter
wscript.sleep 30000 'wait 30 seconds before proceeding to give the system time to unregister the file
'Copy file
oShell.Run "cmd /c copy \\10.168.0.62\activex\phon
wscript.sleep 10000 'wait 10 seconds for the file to be copied
'Register file
oShell.Run "cmd /k runas /user:" & strAdmin & " " & Chr(34) & "regsvr32 " & strReg & Chr(34)
wscript.sleep 1000 'wait
oShell.AppActivate oEnv("SystemRoot") & "\system32\runas.exe" 'find runas
wscript.sleep 2000 'wait
oShell.SendKeys strPW & "~" 'send password and Enter
wscript.sleep 30000 'wait 30 seconds before proceeding to give the system time to register the file
Set oEnv = Nothing
Set oShell = Nothing
Set objFSO=Nothing
Replace it for this...
Dim objFSO, oShell, oEnv 'Declarations
Set oShell = CreateObject("WScript.shel
Set oEnv = oShell.Environment("Proces
Set objFSO = CreateObject("Scripting.Fi
'Grab the short path name for Downloaded Program Files
If objFSO.FolderExists(oShell
Set objFolder = objFSO.GetFolder(oShell.Ex
strDPF = objFolder.ShortPath
msgbox "strDPF=" & strDPF
End If
strReg = strDPF & "\phone.ocx" 'path to ocx
strAdmin = "DINT000\PHONEM" 'Admin logon name
strPW = "adm*Cnm#" 'Admin password
'Unregister file
wscript.echo "Unregistering with: " & "cmd /k runas /user:" & strAdmin & " " & Chr(34) & "regsvr32 -u " & strReg & Chr(34)
oShell.Run "cmd /k runas /user:" & strAdmin & " " & Chr(34) & "regsvr32 -u " & strReg & Chr(34)
wscript.sleep 1000 'wait
oShell.AppActivate oEnv("SystemRoot") & "\system32\runas.exe" 'find runas
wscript.sleep 2000 'wait
oShell.SendKeys strPW & "~" 'send password and Enter
wscript.sleep 30000 'wait 30 seconds before proceeding to give the system time to unregister the file
'Copy file
oShell.Run "cmd /c copy \\10.168.0.62\activex\phon
wscript.sleep 10000 'wait 10 seconds for the file to be copied
'Register file
wscript.echo "Registering file with: " & "cmd /k runas /user:" & strAdmin & " " & Chr(34) & "regsvr32 " & strReg & Chr(34)
oShell.Run "cmd /k runas /user:" & strAdmin & " " & Chr(34) & "regsvr32 " & strReg & Chr(34)
wscript.sleep 1000 'wait
oShell.AppActivate oEnv("SystemRoot") & "\system32\runas.exe" 'find runas
wscript.sleep 2000 'wait
oShell.SendKeys strPW & "~" 'send password and Enter
wscript.sleep 30000 'wait 30 seconds before proceeding to give the system time to register the file
Set oEnv = Nothing
Set oShell = Nothing
Set objFSO=Nothing
You'll get a few pop-ups - I need to know the text in those popups please..
This is the output you 'should' see...
Unregistering with: cmd /k runas /user:Domain\Admin "regsvr32 -u C:\Windows\Downlo~1\phone.
When you posted
Unegistering with: cmd /k runas /user:DOMAIN\USER "regsvr32 -u strDPF=C:\WINDOWS\DOWNLO~1
Presumably you didn't change Domain\User ?
Something's amiss, because it's passing the variable 'and' it's value...plus it's not placing the last quote mark on that line...
That's the problem - why it's occurring is a mystery...
Well I did change the domain\user. Yea from what I can see it should work
On a PC where I have admin rights I do get Unegistering with: cmd /k runas /user:DOMAIN\USER "regsvr32 -u strDPF=C:\WINDOWS\DOWNLO~1
after that, I do get the command that it is trying to register the file, and that too succeeds.
"On a PC where I have admin rights I do get Unegistering with: cmd /k runas /user:DOMAIN\USER "regsvr32 -u strDPF=C:\WINDOWS\DOWNLO~1
You shouldn't even see that though...it's not working like that on my PC...and I'm stumped as to why it would work on yours...
the strDP= shouldn't even be there at all... :(
Try it with this...
Dim objFSO, oShell, oEnv 'Declarations
Set oShell = CreateObject("WScript.shel
Set oEnv = oShell.Environment("Proces
Set objFSO = CreateObject("Scripting.Fi
'Grab the short path name for Downloaded Program Files
If objFSO.FolderExists(oShell
Set objFolder = objFSO.GetFolder(oShell.Ex
strDPF = objFolder.ShortPath
End If
strReg = "\phone.ocx" 'path to ocx
strAdmin = "DINT000\PHONEM" 'Admin logon name
strPW = "adm*Cnm#" 'Admin password
'Unregister file
wscript.echo "Unregistering with: " & "cmd /k runas /user:" & strAdmin & " " & Chr(34) & "regsvr32 -u " & strDPF & strReg & Chr(34)
oShell.Run "cmd /k runas /user:" & strAdmin & " " & Chr(34) & "regsvr32 -u " & strDPF & strReg & Chr(34)
wscript.sleep 1000 'wait
oShell.AppActivate oEnv("SystemRoot") & "\system32\runas.exe" 'find runas
wscript.sleep 2000 'wait
oShell.SendKeys strPW & "~" 'send password and Enter
wscript.sleep 30000 'wait 30 seconds before proceeding to give the system time to unregister the file
'Copy file
oShell.Run "cmd /c copy \\10.168.0.62\activex\phon
wscript.sleep 10000 'wait 10 seconds for the file to be copied
'Register file
wscript.echo "Registering file with: " & "cmd /k runas /user:" & strAdmin & " " & Chr(34) & "regsvr32 " & strDPF & strReg & Chr(34)
oShell.Run "cmd /k runas /user:" & strAdmin & " " & Chr(34) & "regsvr32 " & strDPF & strReg & Chr(34)
wscript.sleep 1000 'wait
oShell.AppActivate oEnv("SystemRoot") & "\system32\runas.exe" 'find runas
wscript.sleep 2000 'wait
oShell.SendKeys strPW & "~" 'send password and Enter
wscript.sleep 30000 'wait 30 seconds before proceeding to give the system time to register the file
Set oEnv = Nothing
Set oShell = Nothing
Set objFSO=Nothing
This is line 18...
oShell.Run "cmd /k runas /user:" & strAdmin & " " & Chr(34) & "regsvr32 -u " & strDPF & strReg & Chr(34)
and it works fine here. :(
Sure would be easier to trouble shoot this if I were on site! lol
I've thought of another idea - hate to keep posting 'non-working' code for you...Give me a bit and I'll come up with something else...
Well, at least it's shorter... :^)
Let me know!
Dim objFSO, oShell, oEnv 'Declarations
Set oShell = CreateObject("WScript.shel
Set oEnv = oShell.Environment("Proces
Set objFSO = CreateObject("Scripting.Fi
'Grab the short path name for Downloaded Program Files
If objFSO.FolderExists(oShell
Set objFolder = objFSO.GetFolder(oShell.Ex
strDPF = objFolder.ShortPath
End If
strReg = "\phone.ocx" 'path to ocx
strAdmin = "DINT000\PHONEM" 'Admin logon name
strPW = "adm*Cnm#" 'Admin password
'Unregister file
Set objOutput = objFSO.CreateTextFile(oEnv
objOutput.WriteLine "regsvr32 -u " & strDPF & strReg
objOutput.WriteLine "copy \\10.168.0.62\activex\phon
objOutput.WriteLine "regsvr32 " & strDPF & strReg
objOutput.Close
wscript.sleep 1000 'wait
oShell.Run "cmd /k runas /user:" & strAdmin & " " & oEnv("TEMP") & "\RegisterPhone.bat"
wscript.sleep 1000 'wait
oShell.AppActivate oEnv("SystemRoot") & "\system32\runas.exe" 'find runas
wscript.sleep 2000 'wait
oShell.SendKeys strPW & "~" 'send password and Enter
Set oEnv = Nothing
Set oShell = Nothing
Set objFSO = Nothing
This version leaves the cmd window open - so that you can view any errors, if any...
If there are none, you can switch the /k to a /c to have it close afterwards...and if it works, we can hide the window altogether...
I have a feeling it has to do with the vast limitations I have set on this user through group policy. I have just consulted with the programmer in charge of this phone.ocx and he stated that it would not be a bad idea if we use the scheduler. He sayd we could time the scheduler with the release. It would be a pain, but its a way to do it.
So how would I use the scheduler with group policy to push out to everyone?
Not wasting my time - it's just a bit aggrivating that it's not working on your end...if you're up for it, I'm more than willing to get it working.
Unfortunately, I'm not too good with GPOs....our org deparmentalizes those functions and even though I'm "the server guy", we don't really do a lot of AD administration.
You don't have Remote Assistance capability there do you? :^)
As for the scheduled solution - if you can deploy the bat file in your netlogon share, you can schedule it via the login script with
schtasks /create /ru Domain\Admin /rp Password /sc onstart /tn NewPhone /tr "cmd /c \\server\netlogon\newphone
sc can also be /sc onlogon
Business Accounts
Answer for Membership
by: sirbountyPosted on 2007-01-05 at 07:06:02ID: 18251595
One method comes to mind...use schtasks, if you're using xp clients...
deploy a batch file with those commands in it, and you can set the task to run as an admin account without exposing any admin credentials...
If that would work for you, post back and I'll show you how to script it...