Set previlege with Windows Management

G

Guest

Hi,

Here is text copy/paste from the WMI SDK reference

Use the Win32_OperatingSystem class and the Win32Shutdown method. You must
include the RemoteShutdown privilege when connecting to WMI. For more
information, see Executing Privileged Operations. Unlike the Shutdown method
on Win32_OperatingSystem, the Win32Shutdown method allows you to set flags to
control the shutdown behavior.
strComputer = "atl-dc-01"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Shutdown(1)
Next


My question is what is the equivalent of
"{impersonationLevel=impersonate,(Shutdown)}!\\" in .NET/C#. Is setting
EnablePrivilege = true good enough?

Thanks.
 
W

Willy Denoyette [MVP]

Yes, setting EnablePrivilege to "true" should 'enable' all privileges
required to execute a specific WMI class methods.
Note that the principal must have been granted the required privilege (see
local security policies).

Note however that this fails when run on .NET v1.1 SP1.

Willy.
PS.Please post System.Management (WMI) related questions to
microsoft.public.dotnet.framework.wmi.

Willy.
 
G

Guest

Hi Willy,

Thanks for the reply.

You mentioned "Note however that this fails when run on .NET v1.1 SP1."

So what is the "suggested" approach that works both now and with .NET v1.1
SP1?

Or is the SP1 considered a new version that will be installed side-by-side
with v1.1 so the current codes will continue to run with v1.1?

Best,

David
 
W

Willy Denoyette [MVP]

David Shen said:
Hi Willy,

Thanks for the reply.

You mentioned "Note however that this fails when run on .NET v1.1 SP1."

So what is the "suggested" approach that works both now and with .NET v1.1
SP1?

Or is the SP1 considered a new version that will be installed side-by-side
with v1.1 so the current codes will continue to run with v1.1?


David,

SP1 is a service pack for .NET v1.1 not a new version of 1.1, so it wont run
side-by-side.
Search the microsoft.public.dotnet.framework.wmi for a bypass I posted for
this issue

Willy.
 

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

Similar Threads

Converting Filesystem trough VBScript not working 13
reboot? 3
Reboot specific systems WMI script 0
Name of reboot program? 1
logon and move cn script 2
HTA's in Vista 3
WMI Conversion 2
Script 2

Top