Getting VBS Cpu Usage with Impersonation using alternative credentials

C

Christopher Attard

Hi,
I have this moniker string:

GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer &"\root\cimv2:Win32_Processor='" & strCPU & "'")

and I want to adapt it so that I can connect to a remote host using alternative credentials (i.e., using ConnectServer( ) ).

I'm trying this:


Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objSWbemLocator.ConnectServer(strComputer, "root\cimv2:Win32_Processor='" & strCPU & "'", strUsername, strPassword)

objWMIService.Security_.ImpersonationLevel = 3


but it seems not working. Any ideas why? How should the moniker string be written when using ConnectServer( ) ?


Thanks,

Chris Attard
 
V

vish

Hi,

try this out.


--------------------------------------------------
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.
------------------------------------------
try this code snippent out and it shld work for u. this code is
basically to show how to connect to a remote computer.
use ur own methods and classes according to ur needs.

bye.
vish.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top