Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runas in a script

Status
Not open for further replies.

djbourne

Technical User
May 1, 2003
66
0
0
GB
Hello I have created a basic script for installing some printers see below

Dim multiPrinter, UNCpath1, UNCpath2
UNCpath1 = "\\server\printer1"
UNCpath2 = "\\server\printer2"
Set multiPrinter = CreateObject("WScript.Network")
multiPrinter.AddWindowsPrinterConnection UNCpath1
multiPrinter.AddWindowsPrinterConnection UNCpath2
WScript.Quit


This works fine for those with admin rights but doesn’t run well with those without.
I read that runas doesn’t work in srpits and found a vbs to exe convertor then tried this script below. Which I had edited from one found on microsoft’s website.

set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.run "runas /user:Domain\User" 'Open command prompt
WScript.Sleep 1000
WshShell.SendKeys "password" 'send password
WshShell.SendKeys "{ENTER}"
WScript.Sleep 1000

'Run Copiers
WshShell.SendKeys "D:\copiers.EXE"
WshShell.SendKeys "{ENTER}"

set wshshell = nothing


This doesn’t work.

Can someone help by pointing out my failings or if there is another way to do the script as runas please.
I cant use ad or gpo for it and I want the users to run from their machine when able.
I have also got the vbs to vbe convertor to make the file secure.

It will run from a shared folder on the server.

Many thanks
Darren
 
I have also tried this one

set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.run "runas /user:domain\user %comspec%" 'Open command prompt
WScript.Sleep 1000
WshShell.SendKeys "password" 'send password
WshShell.SendKeys "{ENTER}"
WScript.Sleep 1000

'Run Copiers
WshShell.SendKeys Chr(34) + "\\server\hemelcopiers.exe" + Chr(34)

WshShell.SendKeys "{ENTER}"

WshShell.SendKeys "exit" 'Close command prompt
WshShell.SendKeys "{ENTER}"
WScript.Sleep 1000


set wshshell = nothing
 
use Microsoft's PS Tools.
psexec.exe \\machine_name -s -c c:\path\to\script.vbs

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Would that be me pushing the script to each user with psexec? I am looking at hundreds of users in an XP and windows 7 environment thats why I want them to run it when they are in otherwise I would be running a push everyday for weeks.
 
Everyday for weeks on 100's of XP/7 machines? Does your environment use Active Directory? If so, your best bet would be to utilize the logon script option in each user's AD account (under the profile tab). That way, when a user logons on the a machine, the logon script is executed.

We use AD in our environment and each user account has the same logon script, logon.vbs. It is within that script that you can put the code your want to run.

logon.vbs
Code:
sub djbourne
   msgbox "Mashed Potatoes"
end sub

msgbox "Guess my favorite carb?"
djbourne

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top