Discussion:
Newbie, confused: winmgmts or WbemScripting.SWbemLocator
(too old to reply)
cbodnar
2005-08-26 14:00:31 UTC
Permalink
I'm new to VBscript so be kind:

It seems to me that you can do the same thing with both of these
examples:

Ex1:

Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_Service",,48)

Ex2:

Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService =
SWBemlocator.ConnectServer(strComputer,"\root\CIMV2",UserName,Password)
Set colItems = objWMIService.ExecQuery("Select * from
Win32_Service",,48)

Can someone point me to a good source for the difference between the
two? When to use one over the other?

I apprecaite any replies.

Thanks

Chris
Björn Holmgren
2005-08-27 08:24:49 UTC
Permalink
Post by cbodnar
It seems to me that you can do the same thing with both of these
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_Service",,48)
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService =
SWBemlocator.ConnectServer(strComputer,"\root\CIMV2",UserName,Password)
Set colItems = objWMIService.ExecQuery("Select * from
Win32_Service",,48)
Can someone point me to a good source for the difference between the
two? When to use one over the other?
I apprecaite any replies.
Thanks
Chris
The main reason, imo, for using the wbem locator, is that you can connect
using alternate credentials.

The following article explains this (and other) difference(s):
http://www.microsoft.com/technet/scriptcenter/guide/sas_wmi_ciga.mspx
--
Björn Holmgren
Csaba Gabor
2005-08-27 10:17:31 UTC
Permalink
Post by Björn Holmgren
The main reason, imo, for using the wbem locator, is that you can connect
using alternate credentials.
http://www.microsoft.com/technet/scriptcenter/guide/sas_wmi_ciga.mspx
That was a good tip. In that article it says:
To run a script under alternate credentials, include the user name and
password as additional parameters passed to ConnectServer

Later, it says:
WMI scripts that connect to the WMI service on the local computer
always connect using the security context of the logged on user. You
cannot use the SWbemLocator ConnectServer method to specify user and
password credentials for a local connection.

I have a different question than the OP that does not concern remote
computers. What is the the most reasonable method to use to run a
(.exe) program (with command line parameters) as an Administrator on
the local machine, given that it's to be invoked by a script started by
a Service (under SystemLocal (or under a non Administrator login, if
it's not possible with SystemLocal))? If Win API are required, I can
create the appropriate .OCX.

Thanks,
Csaba Gabor from Vienna

The reason for this is that I'd like the started up program to be able
to communicate with a background process running as the Administrator
(specifically, they should be able to share COM objects).
This is on a Win XP Pro, SP2 system where I'm the Administrator/sole
user.

Loading...