예제 #1
0
 public static extern int CreateServiceA(
     int hSCManager,
     string lpServiceName,
     string displayName,
     ApiEnums.ServiceControlManagerType dwDesiredAccess,
     ApiEnums.ServiceType dwServiceType,
     ApiEnums.ServiceStartType dwStartType,
     ApiEnums.ServiceErrorControl dwErrorControl,
     string lpBinaryPathName, string lpLoadOrderGroup,
     string lpdwTagId,
     string lpDependencies, string lpServiceStartName, string lpPassword);
예제 #2
0
        public void Install(string arguments)
        {
            string location = Assembly.GetEntryAssembly().Location;

            if (location.Contains(" "))
            {
                location = "\"" + location + "\"";
            }

            string imagePath = string.IsNullOrEmpty(arguments) ? location : string.Format("{0} {1}", location, arguments);

            ApiEnums.ServiceType serviceType = ApiEnums.ServiceType.SERVICE_WIN32_OWN_PROCESS;
            using (WinServiceNative native = new WinServiceNative())
            {
                native.Lock();
                native.Create(this.ServiceName, this.DisplayName, imagePath, serviceType);
            }
        }
예제 #3
0
        public void Create(string name, string displayName, string imagePath, ApiEnums.ServiceType serviceType)
        {
            this.Close();

            m_service = ApiAdvapi32.CreateServiceA(
                m_manager,
                name,
                displayName,
                ApiEnums.ServiceControlManagerType.SC_MANAGER_ALL_ACCESS,
                serviceType,
                ApiEnums.ServiceStartType.SERVICE_AUTO_START,
                ApiEnums.ServiceErrorControl.SERVICE_ERROR_NORMAL,
                imagePath,
                null,
                null,
                null, null, null);

            if (m_service == 0)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "Unable to install the service.");
            }
        }
예제 #4
0
 public static extern bool ChangeServiceConfigA(
     int hService, ApiEnums.ServiceType dwServiceType, int dwStartType,
     int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup,
     int lpdwTagId, string lpDependencies, string lpServiceStartName,
     string lpPassword, string lpDisplayName);