Link to home
Start Free TrialLog in
Avatar of 1bigdork
1bigdork

asked on

Executing vbscript commands with alternate credentials

Is there a way to authenticate to windows within a vbscript and then run commands using those credentials?  For example if I had the following simple code could I authenticate to windows with a local account and it execute the code with those credentials?

Set objShell = CreateObject("Wscript.Shell")
objShell.Run  strCmd,0,True

SOLUTION
Avatar of chandru_sol
chandru_sol
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of William Elliott
what exactly are you trying to do?
are you trying to run an external program via VB,. or acruire information via VB?
here is one to get information from another system using credentials in the script..

if i ned to run a script locally on a box and needs to use alternative credentials. i use CPAU to encapsulate the script and run it with another id.


http://www.joeware.net/freetools/tools/cpau/index.htm


strComputer ="ComputerA" 'give the computername here
strUser = "administrator"
strPassword = "password" 'give the password here
 
Set objLocator = CreateObject( "WbemScripting.SWbemLocator" )
Set objWMIService = objLocator.ConnectServer ( strComputer,
"root/cimv2", strUser, strPassword )
objWMIService.Security_.impersonationlevel = 3
Set colShares = objWMIService.ExecQuery( "Select * from
Win32_processor" )
 
for each objitem in colshares
wscript.echo objitem.name 'or whatever method u want to use..
next.

Open in new window

Avatar of 1bigdork
1bigdork

ASKER

I'm trying to run an external program (or msi in actualilty) via the vbscript.
I've always just used cpau in the past for something like this but this time i'm having some trouble getting all the quotes right in passing the path to the file to cpau.  This mostly stems from the file name having a space in the name and for some reason if I change the name the msi  won't completely uninstall everything properly so that the updated version can be installed.

Just running the file without using cpau requires me to put three quotes on each side of the path before it can find the file.

oshell.run """.\aFolderName\file name.msi"""

So how do I do this when I pass the file path to cpau?

oshell.run "%SystemRoot%\System32\cpau -u username -p password -ex "".\aFolderName\file name.msi"" -wait -profile", , True


ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Using the chr(34) doesn't seem to fix the problem.   I think there may just be an issue with the way in which cpau handles strings.  I guess I'll have to find a different way.   Thanks for the help.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
"WbemScripting.SWbemLocator" cannot be used for connecting WMI on local system; How can we connect to WMI on local system using alternate credentials?