473,388 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Set previlege with Windows Management

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.
Jul 21 '05 #1
3 2653
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.

"David Shen" <Da*******@discussions.microsoft.com> wrote in message
news:7B**********************************@microsof t.com...
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.

Jul 21 '05 #2


"David Shen" <Da*******@discussions.microsoft.com> wrote in message
news:64**********************************@microsof t.com...
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.
Jul 21 '05 #3
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

"Willy Denoyette [MVP]" wrote:
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.

"David Shen" <Da*******@discussions.microsoft.com> wrote in message
news:7B**********************************@microsof t.com...
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.


Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Colin Brown | last post by:
Recently I was looking for remote management tools and came across "Windows Management Instrumentation". There is a python interface available: http://tgolden.sc.sabren.com/python/wmi.html I...
16
by: Robert Mark Bram | last post by:
Hi All! Is there a way to reference a window by name without doing something like this: open (, 'windowName'); The open method will open a blank window if there is no window with such a name....
0
by: Ger | last post by:
Hi, I have a problem with a Windows Service that I have created accessing System.Management.dll on a W2k3 environment. The Service runs fine on an XP machine but the same Service causes an error...
2
by: Brian Worth | last post by:
I have just upgraded from VB 4.0 to VB .NET 2002. One program under VB 4.0 was able to shut down or restart the (windows XP) machine using a series of API calls. (Getlasterror, GetCurrentProcess,...
10
by: Ger | last post by:
I am having problems using VB.Net's Management base object on a machine hosting Windows Server 2003. I am trying to set file permissions from a Windows Service. These files may be loacted on a...
2
by: Chris Podmore | last post by:
I don't know if this is the correct newsgroup but I couldn't find one for Windows Services Is it possible to check that a Windows Service is still running from another machine The idea being a...
2
by: David Shen | last post by:
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....
1
by: =?Utf-8?B?UGllcnJl?= | last post by:
Hello, I have an simle application that uses a referenced library of my own. It's been a year now that I have no problems until a few days. Here is the details of my problem: The library...
2
by: Vadim Malishev | last post by:
Hello, Can anybody help to solve the following problem? My Windows Service trying to access remote machine to get WindowsDirectory Property over Win32_OperatingSystem WMI class. Both servers...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.