public ServiceHandle CreateService(string name, string displayName,
                SERVICE_TYPE type, SERVICE_START_TYPE startType, SERVICE_ERROR_CONTROL errorControl,
                string binaryPath, string group, string accountName, string password)
            {
                int service;

                if ((service = Win32.CreateService(this, name, displayName, SERVICE_RIGHTS.SERVICE_ALL_ACCESS,
                    type, startType, errorControl, binaryPath, group, 0, 0, accountName, password)) == 0)
                    ThrowLastWin32Error();

                return new ServiceHandle(service, true);
            }
Exemplo n.º 2
0
 public static extern int CreateService(int SCManager,
     string ServiceName,
     string DisplayName,
     SERVICE_RIGHTS DesiredAccess, 
     SERVICE_TYPE ServiceType,
     SERVICE_START_TYPE StartType,
     SERVICE_ERROR_CONTROL ErrorControl,
     string BinaryPathName,
     string LoadOrderGroup,
     int TagID, 
     int Dependencies,
     string ServiceStartName,
     string Password
     );
Exemplo n.º 3
0
 public static extern bool ChangeServiceConfig(
     int Service,
     SERVICE_TYPE ServiceType, 
     SERVICE_START_TYPE StartType,
     SERVICE_ERROR_CONTROL ErrorControl, 
     string BinaryPath, 
     string LoadOrderGroup,
     int TagID, 
     int Dependencies,
     string StartName,
     string Password,
     string DisplayName
     );
Exemplo n.º 4
0
		private static extern bool EnumServicesStatusEx (
			IntPtr hSCManager,
			int InfoLevel,
			SERVICE_TYPE dwServiceType,
			SERVICE_STATE_REQUEST dwServiceState,
			IntPtr lpServices,
			uint cbBufSize,
			out uint pcbBytesNeeded,
			out uint lpServicesReturned,
			ref uint lpResumeHandle,
			string pszGroupName);
Exemplo n.º 5
0
		private static ServiceController [] GetServices (string machineName, SERVICE_TYPE serviceType, string group)
		{
			IntPtr scHandle = IntPtr.Zero;
			IntPtr buffer = IntPtr.Zero;

			try {
#if NET_2_0
				scHandle = OpenServiceControlManager (machineName, 
					SERVICE_MANAGER_RIGHTS.SC_MANAGER_ENUMERATE_SERVICE);
#else
				scHandle = OpenServiceControlManager (machineName,
					SERVICE_MANAGER_RIGHTS.SC_MANAGER_ENUMERATE_SERVICE, true);
#endif

				uint bufferSize = 0;
				uint bytesNeeded = 0;
				uint servicesReturned = 0;
				uint resumeHandle = 0;

				ServiceController [] services;

				while (true) {
					if (!EnumServicesStatusEx (scHandle, SC_ENUM_PROCESS_INFO, serviceType, SERVICE_STATE_REQUEST.SERVICE_STATE_ALL, buffer, bufferSize, out bytesNeeded, out servicesReturned, ref resumeHandle, group)) {
						int err = Marshal.GetLastWin32Error ();
						if (err == ERROR_MORE_DATA) {
							buffer = Marshal.AllocHGlobal ((int) bytesNeeded);
							bufferSize = bytesNeeded;
						} else {
							throw new Win32Exception (err);
						}
					} else {
						int iPtr = buffer.ToInt32 ();

						services = new ServiceController [servicesReturned];
						for (int i = 0; i < servicesReturned; i++) {
							ENUM_SERVICE_STATUS_PROCESS serviceStatus = (ENUM_SERVICE_STATUS_PROCESS) Marshal.PtrToStructure (
								new IntPtr (iPtr), typeof (ENUM_SERVICE_STATUS_PROCESS));
							// TODO: use internal ctor that takes displayname too
							services [i] = new ServiceController (serviceStatus.pServiceName,
								machineName);
							// move on to the next services
							iPtr += ENUM_SERVICE_STATUS_PROCESS.SizeOf;
						}

						// we're done, so exit the loop
						break;
					}
				}

				return services;
			} finally {
				if (scHandle != IntPtr.Zero)
					CloseServiceHandle (scHandle);
				if (buffer != IntPtr.Zero)
					Marshal.FreeHGlobal (buffer);
			}
		}
 public ServiceHandle CreateService(string name, string displayName,
     SERVICE_TYPE type, SERVICE_START_TYPE startType, string binaryPath)
 {
     return this.CreateService(name, displayName, type, startType,
         SERVICE_ERROR_CONTROL.Ignore, binaryPath, null, null, null);
 }