Changing Privileges 
Author Message
 Changing Privileges

Is there a namespace where you can query/change the privileges of an
application? As I need to give my application privileges to shutdown the
system and wondered if there was a way of doing this in .NET rather than
reverting to the windows API.

Adam



Sat, 08 Jan 2005 16:40:18 GMT  
 Changing Privileges
If you mean, enable/disable and query token privileges, your only option is using PInvoke (or managed extensions for C++), none of
the WIN32 security API's are currently accessible through the FCL classes.

As for your question on shutdown and shutdown privileges, you can use the Management classes (WMI wrapper) to shutdown, reboot a
system.

Following is a sample using System.Management and WMI:

using System.Management;
....
    // Query the WMI namespace for Win32_OperatingSystem making sure only the current instance is returned
    SelectQuery query = new SelectQuery("select name from Win32_OperatingSystem where primary=true");
    ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
    foreach(ManagementObject os in searcher.Get())
    {
     // Enable SeShutdownPrivilege, the calling process must have SeShutdownPrivilege
     os.Scope.Options.EnablePrivileges = true;
     ManagementBaseObject outParams = os.InvokeMethod("Shutdown", null, null);
    }

Willy.

Quote:

> Is there a namespace where you can query/change the privileges of an
> application? As I need to give my application privileges to shutdown the
> system and wondered if there was a way of doing this in .NET rather than
> reverting to the windows API.

> Adam



Sat, 08 Jan 2005 17:59:07 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. changing privileges in a user process

2. Changing access privileges on a token??

3. WMI Privilege Problem on Reboot call

4. Execute command which requried root privileges.

5. Privilege not held on InvokeMethod

6. Privilege-escalation attacks on NT-based Windows are unfixable

7. principle of least privilege....

8. Privileged winforms deployment via IE

9. Registering a COM dll without administrator privileges

10. HELP, (EXCEPTION) Privileged instruction

11. IE and downloaded controls & privileges

12. DCOM Questions -- Privileges

 

 
Powered by phpBB® Forum Software