Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


wmi how to run as different user

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,1713
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> wmi how to run as different user
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 wmi how to run as different user - 12/16/2004 6:03:11 AM   
  hughewil

 

Posts: 27
Score: 0
Joined: 12/11/2004
From:
Status: offline
I have written a script to pull information from our network servers, but it runs as impersanationlevel=impersonate.

The problem is the logon credentials on the server it will be running on are not domain admin level.

I have a id and password that will give me authority to all machines but I can't figure out how to tell the script to run as that user. here is the code.

Set svConn = CreateObject("ADODB.Connection")
Set dbConn = CreateObject("ADODB.Connection")
svConn.Open "driver={SQL server};SERVER=sname;DATABASE=db;uid=uid"
dbConn.Open "driver ={SQL server};SERVER=sname;DATABASE=db;uid=uid"
Set dbRS = CreateObject("ADODB.Recordset")
Set dsvRS = CreateObject("ADODB.Recordset")
dbsql = "select * from software"
svsql = "select * from servers"
svrs.open svsql,svconn,2,1
do until svrs.eof
dbrs.open dbsql,dbconn,2,3,1
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = svrs.fields("computer_name").value
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
Set objRegistry = GetObject("winmgmts:" & _
"{impersonationLevel=Impersonate}!\\" & _
strcomputer & "\root\default:StdRegProv")
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKey, arrSubKeys
On Error Resume Next
For Each strSubKey In arrSubKeys
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, _
strKey & "\" & strSubKey, "DisplayName", strDisplayName
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, _
strKey & "\" & strSubKey, "DisplayVersion", strDisplayVersion
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, _
strKey & "\" & strSubKey, "HelpLink", strHelpLink
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, _
strKey & "\" & strSubKey, "InstallDate", strInstallDate
'tf.write(String(Len(strSubKey), "-") &vbcrlf)
if strdisplayname <> vbempty then
dbrs.addnew
dbrs.fields("server").value = strcomputer
dbrs.fields("description").value = strDisplayName
dbrs.fields("ver").value = strDisplayVersion
dbrs.fields("helplink").value = strHelpLink
dbrs.fields("installdate").value = strInstallDate
dbrs.update
end if
strDisplayName = vbEmpty
strDisplayVersion = vbEmpty
strHelpLink = vbEmpty
strInstallDate = vbEmpty
Next
dbrs.close
svrs.movenext
loop
svrs.close

so I need to replace impersonationlevel=impersonate with adminuid adminpwd

Any ideas?
 
 
Post #: 1
 
 Re: wmi how to run as different user - 12/16/2004 9:23:23 AM   
  netmarcos

 

Posts: 55
Score: 0
Joined: 12/7/2004
From: USA
Status: offline
You will need to write out the full connect string for WMI using WbemLocator rather than use the shorthand method.

Some relevant code pieces are:
      

The following script, designed to pass alternate credentials to a WMI call to reboot a machine is a good example.



      

(in reply to hughewil)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> wmi how to run as different user Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts