473,569 Members | 2,542 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Set previlege with Windows Management

Hi,

Here is text copy/paste from the WMI SDK reference

Use the Win32_Operating System 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_Operating System, the Win32Shutdown method allows you to set flags to
control the shutdown behavior.
strComputer = "atl-dc-01"
Set objWMIService = GetObject("winm gmts:" _
& "{impersonation Level=impersona te,(Shutdown)}! \\" & _
strComputer & "\root\cimv 2")
Set colOperatingSys tems = objWMIService.E xecQuery _
("Select * from Win32_Operating System")
For Each objOperatingSys tem in colOperatingSys tems
ObjOperatingSys tem.Shutdown(1)
Next
My question is what is the equivalent of
"{impersonation Level=impersona te,(Shutdown)}! \\" in .NET/C#. Is setting
EnablePrivilege = true good enough?

Thanks.
Jul 21 '05 #1
3 2668
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.Manageme nt (WMI) related questions to
microsoft.publi c.dotnet.framew ork.wmi.

Willy.

"David Shen" <Da*******@disc ussions.microso ft.com> wrote in message
news:7B******** *************** ***********@mic rosoft.com...
Hi,

Here is text copy/paste from the WMI SDK reference

Use the Win32_Operating System 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_Operating System, the Win32Shutdown method allows you to set flags
to
control the shutdown behavior.
strComputer = "atl-dc-01"
Set objWMIService = GetObject("winm gmts:" _
& "{impersonation Level=impersona te,(Shutdown)}! \\" & _
strComputer & "\root\cimv 2")
Set colOperatingSys tems = objWMIService.E xecQuery _
("Select * from Win32_Operating System")
For Each objOperatingSys tem in colOperatingSys tems
ObjOperatingSys tem.Shutdown(1)
Next
My question is what is the equivalent of
"{impersonation Level=impersona te,(Shutdown)}! \\" in .NET/C#. Is setting
EnablePrivilege = true good enough?

Thanks.

Jul 21 '05 #2


"David Shen" <Da*******@disc ussions.microso ft.com> wrote in message
news:64******** *************** ***********@mic rosoft.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.publi c.dotnet.framew ork.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.Manageme nt (WMI) related questions to
microsoft.publi c.dotnet.framew ork.wmi.

Willy.

"David Shen" <Da*******@disc ussions.microso ft.com> wrote in message
news:7B******** *************** ***********@mic rosoft.com...
Hi,

Here is text copy/paste from the WMI SDK reference

Use the Win32_Operating System 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_Operating System, the Win32Shutdown method allows you to set flags
to
control the shutdown behavior.
strComputer = "atl-dc-01"
Set objWMIService = GetObject("winm gmts:" _
& "{impersonation Level=impersona te,(Shutdown)}! \\" & _
strComputer & "\root\cimv 2")
Set colOperatingSys tems = objWMIService.E xecQuery _
("Select * from Win32_Operating System")
For Each objOperatingSys tem in colOperatingSys tems
ObjOperatingSys tem.Shutdown(1)
Next
My question is what is the equivalent of
"{impersonation Level=impersona te,(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
7190
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 was amazed how easy it became to access just about anything under the hood (later versions of NT, 2000, XP) using a couple of lines of code! If you...
16
34543
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. I am trying to organise a navigation structure between two windows with content from the same host.. I have been trying the following:
0
1921
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 once it tries to access System.Management.Dll. The service is run using a Domain Admin acoount. The code is trying to set permissions for a file...
2
11391
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, OpenProcessToken, LookupPrivilegeValue, AdjustTokenPrivilegese, ExitWindowsEx. I am trying to avoid using any API calls if possible and to use...
10
3471
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 local machine or somewhere on the network. I use the Management Base Object to set these permissions which works perfectly when the windows service is...
2
5917
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 couple of machines will be running my Windows Services to handle certain parts of our application, these machines will be located in the server room....
2
286
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. For more information, see Executing Privileged Operations. Unlike the Shutdown method on Win32_OperatingSystem, the Win32Shutdown method allows you...
1
3653
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 referenced by the main application compiles properly. When I compile the main application, I have the following message: Cannot copy assembly 'MyLib'...
2
4768
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 are in the same Active Directory domain, so I create special active directory user and impersonate to it before invoke WMI. My code looks like:
0
7700
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7614
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7676
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7974
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.