Date: 10/05/07 (C Sharp) Keywords: no keywords Hey guys. I know I've seen this before, but I can't, for the life of me, remember how to do it or where I saw it . . .
public class ServiceInternalInstaller {
[DllImport( "advapi32.dll" )]
public static extern IntPtr OpenSCManager( string lpMachineName, string lpSCDB, int scParameter );
private IntPtr m_pSCM = IntPtr.Zero;
public ServiceInternalInstaller() {
const int SC_MANAGER_CREATE_SERVICE = 0x00000002;
try {
m_pSCM = OpenSCManager( null, null, SC_MANAGER_CREATE_SERVICE );
if( m_pSCM == 0 ) {
throw new Exception( GetLastErrorMessage() );
}
} catch( Exception e ) {
Console.Error.WriteLine( e.Message );
}
}
}
...
ServiceInternalInstaller oInstall = new ServiceInternalInstaller();
if( oInstall == null ) return;
I left a few things out for the sake of brevity. It's a little crude, but that should give you the idea. Thanks.
|