|
Can anyone help me with this this to run under alternate credentials. What would be proper syntax for that. pls explain and show me how if you can. -
Set GetWMIRegProvider=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & StrLine & "\root\default:StdRegProv")
-
Thanks
| |
Share:
Expert 1GB |
Can anyone help me with this this to run under alternate credentials. What would be proper syntax for that. pls explain and show me how if you can. -
Set GetWMIRegProvider=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & StrLine & "\root\default:StdRegProv")
-
Thanks
Hi there,
Am not trying to be rude here, pls explain to me on how are you come up with such a line of code without properly understanding / uncertain about syntax? Are you copying it from somewhere on the net?
| | |
Hi Sashi,
Well, I have a scripts that collect the remote computer monitor information remotely but it only works now if you log on to a machine with administrator and if the remote machine and local machine has same administrator password. The script is too long, thats why i could not paste it here. But I will now in two separate post. pls have a look.
First Half -
Const DISPLAY_REGKEY="HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\"
-
-
Const DEBUGFILE="NUL"
-
-
Const DEBUGMODE=0
-
-
CompName = Trim(inputbox("Enter name or IP address of local or remote computer"))
-
-
Set objArgs = WScript.Arguments
-
-
Set objFS = CreateObject("Scripting.FileSystemObject")
-
Set objNewFile = objFS.CreateTextFile("monitor_Output.txt")
-
-
DebugOut "Execution Started " & cstr(now)
-
-
'------------------------------------------------------------------------
-
GetMonitorInfo() 'just write the output to screen
-
DebugOut "Execution Completed " & cstr(now)
-
-
-
Function GetMonitorInfo()
-
debugout "Getting all display devices"
-
arrAllDisplays=GetAllDisplayDevicesInReg()
-
debugout "Filtering display devices to monitors"
-
arrAllMonitors=GetAllMonitorsFromAllDisplays(arrAllDisplays)
-
debugout "Filtering monitors to active monitors"
-
arrActiveMonitors=GetActiveMonitorsFromAllMonitors(arrAllMonitors)
-
if ubound(arrActiveMonitors)=0 and arrActiveMonitors(0)="{ERROR}" then
-
debugout "No active monitors found"
-
strFormattedMonitorInfo="[Monitor_1]" & vbcrlf & "Monitor=Not Found" & vbcrlf & vbcrlf
-
else
-
debugout "Found active monitors"
-
debugout "Retrieving EDID for all active monitors"
-
arrActiveEDID=GetEDIDFromActiveMonitors(arrActiveMonitors)
-
debugout "Parsing EDID/Windows data"
-
arrParsedMonitorInfo=GetParsedMonitorInfo(arrActiveEDID,arrActiveMonitors)
-
debugout "Formatting parsed data"
-
strFormattedMonitorInfo=GetFormattedMonitorInfo(arrParsedMonitorInfo)
-
end if
-
debugout "Data retrieval completed"
-
GetMonitorInfo=strFormattedMonitorInfo
-
end function
-
-
Function GetFormattedMonitorInfo(arrParsedMonitorInfo)
-
for tmpctr=0 to ubound(arrParsedMonitorInfo)
-
tmpResult=split(arrParsedMonitorInfo(tmpctr),"|||")
-
tmpOutput=tmpOutput & CompName & " monitor" & vbcrlf & vbcrlf
-
tmpOutput=tmpOutput & "ManufacturerID = " & tmpResult(1) & vbcrlf
-
tmpOutput=tmpOutput & "ManufactureDate = " & tmpResult(2) & vbcrlf
-
tmpOutput=tmpOutput & "SerialNumber = " & tmpResult(0) & vbcrlf
-
tmpOutput=tmpOutput & "ModelName = " & tmpResult(4) & vbcrlf
-
next
-
GetFormattedMonitorInfo=tmpOutput
-
objNewFile.WriteLine CompName & " monitor" & vbcrlf & vbcrlf
-
objNewFile.WriteLine "ManufacturerID = " & tmpResult(1) & vbcrlf
-
objNewFile.WriteLine "ManufactureDate = " & tmpResult(2) & vbcrlf
-
objNewFile.WriteLine "SerialNumber = " & tmpResult(0) & vbcrlf
-
objNewFile.WriteLine "ModelName = " & tmpResult(4) & vbcrlf
-
Set objShell = Wscript.Createobject("Wscript.Shell")
-
objShell.Run "monitor_output.txt"
-
End Function
-
-
Function GetAllDisplayDevicesInReg()
-
dim arrResult()
-
redim arrResult(0)
-
intArrResultIndex=-1
-
arrtmpkeys=RegEnumKeys(DISPLAY_REGKEY)
-
if vartype(arrtmpkeys)<>8204 then
-
arrResult(0)="{ERROR}"
-
GetAllDisplayDevicesInReg=false
-
debugout "Display=Can't enum subkeys of display regkey"
-
else
-
for tmpctr=0 to ubound(arrtmpkeys)
-
arrtmpkeys2=RegEnumKeys(DISPLAY_REGKEY & arrtmpkeys(tmpctr))
-
for tmpctr2 = 0 to ubound(arrtmpkeys2)
-
intArrResultIndex=intArrResultIndex+1
-
redim preserve arrResult(intArrResultIndex)
-
arrResult(intArrResultIndex)=DISPLAY_REGKEY & arrtmpkeys(tmpctr) & "\" & arrtmpkeys2(tmpctr2)
-
debugout "Display=" & arrResult(intArrResultIndex)
-
next
-
next
-
end if
-
GetAllDisplayDevicesInReg=arrResult
-
End Function
-
-
Function GetAllMonitorsFromAllDisplays(arrRegKeys)
-
dim arrResult()
-
redim arrResult(0)
-
intArrResultIndex=-1
-
for tmpctr=0 to ubound(arrRegKeys)
-
if IsDisplayDeviceAMonitor(arrRegKeys(tmpctr)) then
-
intArrResultIndex=intArrResultIndex+1
-
redim preserve arrResult(intArrResultIndex)
-
arrResult(intArrResultIndex)=arrRegKeys(tmpctr)
-
debugout "Monitor=" & arrResult(intArrResultIndex)
-
end if
-
next
-
if intArrResultIndex=-1 then
-
arrResult(0)="{ERROR}"
-
debugout "Monitor=Unable to locate any monitors"
-
end if
-
GetAllMonitorsFromAllDisplays=arrResult
-
End Function
-
-
Function IsDisplayDeviceAMonitor(strDisplayRegKey)
-
arrtmpResult=RegGetMultiStringValue(strDisplayRegKey,"HardwareID")
-
strtmpResult="|||" & join(arrtmpResult,"|||") & "|||"
-
if instr(lcase(strtmpResult),"|||monitor\")=0 then
-
debugout "MonitorCheck='" & strDisplayRegKey & "'|||is not a monitor"
-
IsDisplayDeviceAMonitor=false
-
else
-
debugout "MonitorCheck='" & strDisplayRegKey & "'|||is a monitor"
-
IsDisplayDeviceAMonitor=true
-
end if
-
End Function
-
-
Function GetActiveMonitorsFromAllMonitors(arrRegKeys)
-
dim arrResult()
-
redim arrResult(0)
-
intArrResultIndex=-1
-
for tmpctr=0 to ubound(arrRegKeys)
-
if IsMonitorActive(arrRegKeys(tmpctr)) then
-
intArrResultIndex=intArrResultIndex+1
-
redim preserve arrResult(intArrResultIndex)
-
arrResult(intArrResultIndex)=arrRegKeys(tmpctr)
-
debugout "ActiveMonitor=" & arrResult(intArrResultIndex)
-
end if
-
next
-
-
if intArrResultIndex=-1 then
-
arrResult(0)="{ERROR}"
-
debugout "ActiveMonitor=Unable to locate any active monitors"
-
end if
-
GetActiveMonitorsFromAllMonitors=arrResult
-
End Function
-
-
Function IsMonitorActive(strMonitorRegKey)
-
arrtmpResult=RegEnumKeys(strMonitorRegKey)
-
strtmpResult="|||" & join(arrtmpResult,"|||") & "|||"
-
if instr(lcase(strtmpResult),"|||control|||")=0 then
-
debugout "ActiveMonitorCheck='" & strMonitorRegKey & "'|||is not active"
-
IsMonitorActive=false
-
else
-
debugout "ActiveMonitorCheck='" & strMonitorRegKey & "'|||is active"
-
IsMonitorActive=true
-
end if
-
End Function
-
-
Function GetEDIDFromActiveMonitors(arrRegKeys)
-
dim arrResult()
-
redim arrResult(0)
-
intArrResultIndex=-1
-
for tmpctr=0 to ubound(arrRegKeys)
-
strtmpResult=GetEDIDForMonitor(arrRegKeys(tmpctr))
-
intArrResultIndex=intArrResultIndex+1
-
redim preserve arrResult(intArrResultIndex)
-
arrResult(intArrResultIndex)=strtmpResult
-
debugout "GETEDID=" & arrRegKeys(tmpctr) & "|||EDID,Yes"
-
next
-
-
if intArrResultIndex=-1 then
-
arrResult(0)="{ERROR}"
-
debugout "EDID=Unable to retrieve any edid"
-
end if
-
GetEDIDFromActiveMonitors=arrResult
-
End Function
-
-
Function GetEDIDForMonitor(strMonitorRegKey)
-
arrtmpResult=RegGetBinaryValue(strMonitorRegKey & "\Device Parameters","EDID")
-
if vartype(arrtmpResult) <> 8204 then
-
debugout "GetEDID=No EDID Found|||" & strMonitorRegKey
-
GetEDIDForMonitor="{ERROR}"
-
else
-
for each bytevalue in arrtmpResult
-
strtmpResult=strtmpResult & chr(bytevalue)
-
next
-
debugout "GetEDID=EDID Found|||" & strMonitorRegKey
-
debugout "GetEDID_Result=" & GetHexFromString(strtmpResult)
-
GetEDIDForMonitor=strtmpResult
-
end if
-
End Function
-
-
Function GetHexFromString(strText)
-
for tmpctr=1 to len(strText)
-
tmpresult=tmpresult & right( "0" & hex(asc(mid(strText,tmpctr,1))),2) & ","
-
next
-
GetHexFromString=left(tmpresult,len(tmpresult)-1)
-
End Function
-
-
Function GetParsedMonitorInfo(arrActiveEDID,arrActiveMonitors)
-
dim arrResult()
-
for tmpctr=0 to ubound(arrActiveEDID)
-
strSerial=GetSerialFromEDID(arrActiveEDID(tmpctr))
-
strMfg=GetMfgFromEDID(arrActiveEDID(tmpctr))
-
strMfgDate=GetMfgDateFromEDID(arrActiveEDID(tmpctr))
-
strDev=GetDevFromEDID(arrActiveEDID(tmpctr))
-
strModel=GetModelFromEDID(arrActiveEDID(tmpctr))
-
strEDIDVer=GetEDIDVerFromEDID(arrActiveEDID(tmpctr))
-
strWinVesaID=GetWinVESAIDFromRegKey(arrActiveMonitors(tmpctr))
-
strWinPNPID=GetWinPNPFromRegKey(arrActiveMonitors(tmpctr))
-
redim preserve arrResult(tmpctr)
-
arrResult(tmpctr)=arrResult(tmpctr) & strSerial & "|||"
-
arrResult(tmpctr)=arrResult(tmpctr) & strMfg & "|||"
-
arrResult(tmpctr)=arrResult(tmpctr) & strMfgDate & "|||"
-
arrResult(tmpctr)=arrResult(tmpctr) & strDev & "|||"
-
arrResult(tmpctr)=arrResult(tmpctr) & strModel & "|||"
-
arrResult(tmpctr)=arrResult(tmpctr) & strEDIDVer & "|||"
-
arrResult(tmpctr)=arrResult(tmpctr) & strWinVesaID & "|||"
-
arrResult(tmpctr)=arrResult(tmpctr) & strWinPNPID
-
debugout arrResult(tmpctr)
-
next
-
GetParsedMonitorInfo=arrResult
-
End Function
-
-
Function GetWinVESAIDFromRegKey(strRegKey)
-
if strRegKey="{ERROR}" then
-
GetWinVESAIDFromRegKey="Bad Registry Info"
-
exit function
-
end if
-
strtmpResult=right(strRegKey,len(strRegkey)-len(DISPLAY_REGKEY))
-
strtmpResult=left(strtmpResult,instr(strtmpResult,"\")-1)
-
GetWinVESAIDFromRegKey=strtmpResult
-
End Function
-
-
Function GetWinPNPFromRegKey(strRegKey)
-
if strRegKey="{ERROR}" then
-
GetWinPNPFromRegKey="Bad Registry Info"
-
exit function
-
end if
-
strtmpResult=right(strRegKey,len(strRegkey)-len(DISPLAY_REGKEY))
-
strtmpResult=right(strtmpResult,len(strtmpResult)-instr(strtmpResult,"\"))
-
GetWinPNPFromRegKey=strtmpResult
-
End Function
-
| | |
Hi Sashi,
Here is the 2nd half -
Function GetSerialFromEDID(strEDID)
-
'a serial number descriptor will start with &H00 00 00 ff
-
strTag=chr(&H00) & chr(&H00) & chr(&H00) & chr(&Hff)
-
GetSerialFromEDID=GetDescriptorBlockFromEDID(strEDID,strTag)
-
End Function
-
-
Function GetModelFromEDID(strEDID)
-
-
strTag=chr(&H00) & chr(&H00) & chr(&H00) & chr(&Hfc)
-
GetModelFromEDID=GetDescriptorBlockFromEDID(strEDID,strTag)
-
End Function
-
-
Function GetDescriptorBlockFromEDID(strEDID,strTag)
-
if strEDID="{ERROR}" then
-
GetDescriptorBlockFromEDID="Bad EDID"
-
exit function
-
end if
-
-
dim arrDescriptorBlock(3)
-
arrDescriptorBlock(0)=mid(strEDID,&H36+1,18)
-
arrDescriptorBlock(1)=mid(strEDID,&H48+1,18)
-
arrDescriptorBlock(2)=mid(strEDID,&H5a+1,18)
-
arrDescriptorBlock(3)=mid(strEDID,&H6c+1,18)
-
-
if instr(arrDescriptorBlock(0),strTag)>0 then
-
strFoundBlock=arrDescriptorBlock(0)
-
elseif instr(arrDescriptorBlock(1),strTag)>0 then
-
strFoundBlock=arrDescriptorBlock(1)
-
elseif instr(arrDescriptorBlock(2),strTag)>0 then
-
strFoundBlock=arrDescriptorBlock(2)
-
elseif instr(arrDescriptorBlock(3),strTag)>0 then
-
strFoundBlock=arrDescriptorBlock(3)
-
else
-
GetDescriptorBlockFromEDID="Not Present in EDID"
-
exit function
-
end if
-
-
strResult=right(strFoundBlock,14)
-
-
if instr(strResult,chr(&H0a))>0 then
-
strResult=trim(left(strResult,instr(strResult,chr(&H0a))-1))
-
else
-
strResult=trim(strResult)
-
end if
-
-
if left(strResult,1)=chr(0) then strResult=right(strResult,len(strResult)-1)
-
-
GetDescriptorBlockFromEDID=strResult
-
End Function
-
-
Function GetMfgFromEDID(strEDID)
-
if strEDID="{ERROR}" then
-
GetMfgFromEDID="Bad EDID"
-
exit function
-
end if
-
-
tmpEDIDMfg=mid(strEDID,&H08+1,2)
-
Char1=0 : Char2=0 : Char3=0
-
Byte1=asc(left(tmpEDIDMfg,1)) 'get the first half of the string
-
Byte2=asc(right(tmpEDIDMfg,1)) 'get the first half of the string
-
-
if (Byte1 and 64) > 0 then Char1=Char1+16
-
-
if (Byte1 and 32) > 0 then Char1=Char1+8
-
-
if (Byte1 and 16) > 0 then Char1=Char1+4
-
if (Byte1 and 8) > 0 then Char1=Char1+2
-
if (Byte1 and 4) > 0 then Char1=Char1+1
-
-
if (Byte1 and 2) > 0 then Char2=Char2+16
-
if (Byte1 and 1) > 0 then Char2=Char2+8
-
-
if (Byte2 and 128) > 0 then Char2=Char2+4
-
if (Byte2 and 64) > 0 then Char2=Char2+2
-
if (Byte2 and 32) > 0 then Char2=Char2+1
-
-
Char3=Char3+(Byte2 and 16)
-
Char3=Char3+(Byte2 and 8)
-
Char3=Char3+(Byte2 and 4)
-
Char3=Char3+(Byte2 and 2)
-
Char3=Char3+(Byte2 and 1)
-
tmpmfg=chr(Char1+64) & chr(Char2+64) & chr(Char3+64)
-
GetMfgFromEDID=tmpmfg
-
End Function
-
-
Function GetMfgDateFromEDID(strEDID)
-
if strEDID="{ERROR}" then
-
GetMfgDateFromEDID="Bad EDID"
-
exit function
-
end if
-
-
tmpmfgweek=asc(mid(strEDID,&H10+1,1))
-
-
tmpmfgyear=(asc(mid(strEDID,&H11+1,1)))+1990
-
-
tmpmdt=month(dateadd("ww",tmpmfgweek,datevalue("1/1/" & tmpmfgyear))) & "/" & tmpmfgyear
-
GetMfgDateFromEDID=tmpmdt
-
End Function
-
-
Function GetDevFromEDID(strEDID)
-
if strEDID="{ERROR}" then
-
GetDevFromEDID="Bad EDID"
-
exit function
-
end if
-
tmpEDIDDev1=hex(asc(mid(strEDID,&H0a+1,1)))
-
tmpEDIDDev2=hex(asc(mid(strEDID,&H0b+1,1)))
-
if len(tmpEDIDDev1)=1 then tmpEDIDDev1="0" & tmpEDIDDev1
-
if len(tmpEDIDDev2)=1 then tmpEDIDDev2="0" & tmpEDIDDev2
-
tmpdev=tmpEDIDDev2 & tmpEDIDDev1
-
GetDevFromEDID=tmpdev
-
End Function
-
-
Function GetEDIDVerFromEDID(strEDID)
-
if strEDID="{ERROR}" then
-
GetEDIDVerFromEDID="Bad EDID"
-
exit function
-
end if
-
-
tmpEDIDMajorVer=asc(mid(strEDID,&H12+1,1))
-
-
tmpEDIDRev=asc(mid(strEDID,&H13+1,1))
-
-
tmpver=chr(48+tmpEDIDMajorVer) & "." & chr(48+tmpEDIDRev)
-
GetEDIDVerFromEDID=tmpver
-
End Function
-
-
Function RegEnumKeys(RegKey)
-
hive=SetHive(RegKey)
-
set objReg=GetWMIRegProvider(CompName)
-
strKeyPath = right(RegKey,len(RegKey)-instr(RegKey,"\"))
-
objReg.EnumKey Hive, strKeyPath, arrSubKeys
-
RegEnumKeys=arrSubKeys
-
End Function
-
-
Function RegGetStringValue(RegKey,RegValueName)
-
hive=SetHive(RegKey)
-
set objReg=GetWMIRegProvider(CompName)
-
strKeyPath = right(RegKey,len(RegKey)-instr(RegKey,"\"))
-
tmpreturn=objReg.GetStringValue(Hive, strKeyPath, RegValueName, RegValue)
-
if tmpreturn=0 then
-
RegGetStringValue=RegValue
-
else
-
RegGetStringValue="~{{}}~"
-
end if
-
End Function
-
-
Function RegGetMultiStringValue(RegKey,RegValueName)
-
hive=SetHive(RegKey)
-
set objReg=GetWMIRegProvider(CompName)
-
strKeyPath = right(RegKey,len(RegKey)-instr(RegKey,"\"))
-
tmpreturn=objReg.GetMultiStringValue(Hive, strKeyPath, RegValueName, RegValue)
-
if tmpreturn=0 then
-
RegGetMultiStringValue=RegValue
-
else
-
RegGetMultiStringValue="~{{}}~"
-
end if
-
End Function
-
-
Function RegGetBinaryValue(RegKey,RegValueName)
-
hive=SetHive(RegKey)
-
set objReg=GetWMIRegProvider(CompName)
-
strKeyPath = right(RegKey,len(RegKey)-instr(RegKey,"\"))
-
tmpreturn=objReg.GetBinaryValue(Hive, strKeyPath, RegValueName, RegValue)
-
if tmpreturn=0 then
-
RegGetBinaryValue=RegValue
-
else
-
RegGetBinaryValue="~{{}}~"
-
end if
-
End Function
-
-
On Error Resume Next
-
Function GetWMIRegProvider(CompName)
-
-
Set GetWMIRegProvider=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & CompName & "\root\default:StdRegProv")
-
End Function
-
-
Function SetHive(RegKey)
-
HKEY_CLASSES_ROOT=&H80000000
-
HKEY_CURRENT_USER=&H80000001
-
HKEY_CURRENT_CONFIG=&H80000005
-
HKEY_LOCAL_MACHINE=&H80000002
-
HKEY_USERS=&H80000003
-
strHive=left(RegKey,instr(RegKey,"\"))
-
if strHive="HKCR\" or strHive="HKR\" then SetHive=HKEY_CLASSES_ROOT
-
if strHive="HKCU\" then SetHive=HKEY_CURRENT_USER
-
if strHive="HKCC\" then SetHive=HKEY_CURRENT_CONFIG
-
if strHive="HKLM\" then SetHive=HKEY_LOCAL_MACHINE
-
if strHive="HKU\" then SetHive=HKEY_USERS
-
End Function
-
-
Sub Pause
-
set objStdin=wscript.stdin
-
set objStdout=wscript.stdout
-
objStdout.write "Press ENTER to continue..."
-
strtmp=objStdin.readline
-
end Sub
-
-
Sub DebugOut(strDebugInfo)
-
if DEBUGMODE=0 then exit sub
-
strCurrScriptHost=lcase(right(wscript.fullname,len(wscript.fullname)-len(wscript.path)-1))
-
if strCurrScriptHost="cscript.exe" then wscript.echo "Debug: " & strDebugInfo
-
AppendFileMode=8
-
set objDebugFSO=CreateObject("Scripting.FileSystemObject")
-
set objDebugStream=objDebugFSO.OpenTextFile(DEBUGFILE,AppendFileMode,True,False)
-
objDebugStream.writeline strDebugInfo
-
objDebugStream.Close
-
set objDebugStream=Nothing
-
set objDebugFSO=Nothing
-
End Sub
-
| | Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
4 posts
views
Thread by VR |
last post: by
|
1 post
views
Thread by Eric Lindsay |
last post: by
|
1 post
views
Thread by Tedmond |
last post: by
|
3 posts
views
Thread by Daniel Greene |
last post: by
|
1 post
views
Thread by adiel_g |
last post: by
|
2 posts
views
Thread by sweetpotatop |
last post: by
|
reply
views
Thread by Hayato Iriumi |
last post: by
|
2 posts
views
Thread by Michael Bray |
last post: by
| | | | | | | | | | | |