Login | |
|
 |
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?
|
|
| |
|
|
|
|
|