Inheritance: Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid
コード例 #1
0
 public void Install()
 {
     using (var servicemanager = NativeServiceManager.Open())
     {
         using (var service = servicemanager.CreateService(this.ServiceName, this.ServiceName, "\"" + Assembly.GetExecutingAssembly().Location + "\" -service", ServiceRights.AllAccess))
         {
             service.Start(new string[] { });
         }
     }
 }
コード例 #2
0
        public static NativeServiceManager Open()
        {
            NativeServiceManager handle = OpenSCManager(null, null, ServiceManagerRights.Connect | ServiceManagerRights.CreateService);

            if (handle.IsClosed || handle.IsInvalid)
            {
                Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
            }
            return(handle);
        }
コード例 #3
0
 public void Uninstall()
 {
     using (var servicemanager = NativeServiceManager.Open())
     {
         using (var service = servicemanager.OpenService(this.ServiceName, ServiceRights.AllAccess))
         {
             service.Stop();
             service.Delete();
         }
     }
 }
コード例 #4
0
 protected static extern NativeService CreateService(
     NativeServiceManager hSCManager,
     string lpServiceName,
     string lpDisplayName,
     ServiceRights dwDesiredAccess,
     ServiceType dwServiceType,
     ServiceStartType dwStartType,
     ServiceErrorControl dwErrorControl,
     string lpBinaryPathName,
     string lpLoadOrderGroup,
     IntPtr lpdwTagId,
     string lpDependencies,
     string lpServiceStartName,
     string lpPassword
     );
コード例 #5
0
 protected static extern NativeService OpenService(
     NativeServiceManager hSCManager,
     string lpServiceName,
     ServiceRights dwDesiredAccess
 );
コード例 #6
0
 protected static extern NativeService CreateService(
     NativeServiceManager hSCManager,
     string lpServiceName,
     string lpDisplayName,
     ServiceRights dwDesiredAccess,
     ServiceType dwServiceType,
     ServiceStartType dwStartType,
     ServiceErrorControl dwErrorControl,
     string lpBinaryPathName,
     string lpLoadOrderGroup,
     IntPtr lpdwTagId,
     string lpDependencies,
     string lpServiceStartName,
     string lpPassword
 );
コード例 #7
0
 protected static extern NativeService OpenService(
     NativeServiceManager hSCManager,
     string lpServiceName,
     ServiceRights dwDesiredAccess
     );