Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using Win32 API's or equivalent function

0 views
Skip to first unread message

Abhi

unread,
Nov 29, 2001, 3:17:32 PM11/29/01
to
I need to use ExitWindows API to remotely shut down a computer on my
network. Now I read that it is very difficult to use Win32 API's in C#, is
there any equivalent function for any class in C#, if not how can I use
native win32 API's in C#.
Please advice.

Abhi


Willy Denoyette

unread,
Nov 29, 2001, 3:17:57 PM11/29/01
to
This has been posted by me in this NG a while ago.
Following is a sample using the Management namespace classes.

using System;
using System.Management;

using System.Runtime.InteropServices;
// Shutdown a system using WMI (management classes)
public class Wmis {
public static void Main() {
ManagementObject o;
ManagementPath path = new ManagementPath( );
path.Server = "."; // . for the local server or the server name if a remote server
path.NamespacePath = @"root\CIMV2";
// check your boot.ini file for the correct operating system entry & boot partition
path.RelativePath = @"Win32_OperatingSystem.Name=""Microsoft Windows XP
Professional|C:\\WINNT|\\Device\\Harddisk0\\Partition1""";
o = new ManagementObject(path);
ManagementBaseObject inParams = null;
bool EnablePrivileges = o.Scope.Options.EnablePrivileges; // set required privileges
o.Scope.Options.EnablePrivileges = true;
// Invoke method (shutdown or reboot)
ManagementBaseObject outParams = o.InvokeMethod("Shutdown", inParams, null);
o.Scope.Options.EnablePrivileges = EnablePrivileges; // restore privs (optional)
}
}

Willy.

"Abhi" <source...@hotmail.com> wrote in message news:#4Vj7IReBHA.552@tkmsftngp02...

0 new messages