Exemplo n.º 1
0
        public void ChangeConfig(
            SERVICE_TYPE serviceType,
            SERVICE_START_TYPE startType,
            SERVICE_ERROR_CONTROL errorControl,
            string binaryPathName,
            string loadOrderGroup,
            IntPtr tagId,
            IEnumerable <string> dependencies,
            string serviceStartName,
            string password,
            string displayName)
        {
            var dependenciesString = dependencies == null ? null : string.Join("\0", dependencies) + "\0"; // Collection of strings separated by null and terminated by double null

            if (!NativeMethods.ChangeServiceConfig(
                    handle,
                    (uint)serviceType,
                    (uint)startType,
                    (uint)errorControl,
                    binaryPathName,
                    loadOrderGroup,
                    tagId,
                    dependenciesString,
                    serviceStartName,
                    password,
                    displayName))
            {
                throw new Win32Exception();
            }
        }
Exemplo n.º 2
0
        public Task <bool> SetConnectionString(string value)
        {
            _class      = null;
            _wfsDataset = null;
            switch (ConfigTextStream.ExtractValue(value, "service").ToUpper())
            {
            case "WMS":
                _type       = SERVICE_TYPE.WMS;
                _connection = ConfigTextStream.ExtractValue(value, "wms");
                _class      = new WMSClass(this);
                break;

            case "WFS":
                _type       = SERVICE_TYPE.WFS;
                _wfsDataset = new WFSDataset(this, ConfigTextStream.ExtractValue(value, "wfs"));
                break;

            case "WMS_WFS":
                _type       = SERVICE_TYPE.WMS_WFS;
                _connection = ConfigTextStream.ExtractValue(value, "wms");
                _class      = new WMSClass(this);
                _wfsDataset = new WFSDataset(this, ConfigTextStream.ExtractValue(value, "wfs"));
                break;

            default:
                return(Task.FromResult(false));
            }
            _connectionString = value;

            return(Task.FromResult(true));
        }
Exemplo n.º 3
0
        public IEnumerable <ENUM_SERVICE_STATUS_PROCESS> EnumServicesStatusEx(SERVICE_TYPE serviceType, SERVICE_STATE_FLAGS serviceStateFlags)
        {
            int  needed           = 0;
            int  servicesReturned = 0;
            uint resumeHandle     = 0;

            if (NativeMethods.EnumServicesStatusEx(
                    handle,
                    SC_ENUM_PROCESS_INFO,
                    serviceType,
                    serviceStateFlags,
                    IntPtr.Zero,
                    0,
                    ref needed,
                    ref servicesReturned,
                    ref resumeHandle,
                    null))
            {
                throw new Win32Exception(0, $"Unexpected success in {nameof(ServiceControlManager)}.{nameof(EnumServicesStatusEx)}");
            }

            // We expect an ERROR_MORE_DATA error as the buffer size passed in was zero, otherwise something strage is going on
            if (Marshal.GetLastWin32Error() != ERROR_MORE_DATA)
            {
                throw new Win32Exception();
            }

            IntPtr bufferPtr = Marshal.AllocHGlobal(needed);
            var    ptr       = bufferPtr;

            try
            {
                if (!NativeMethods.EnumServicesStatusEx(
                        handle,
                        SC_ENUM_PROCESS_INFO,
                        serviceType,
                        serviceStateFlags,
                        bufferPtr,
                        needed,
                        ref needed,
                        ref servicesReturned,
                        ref resumeHandle,
                        null))
                {
                    throw new Win32Exception();
                }

                for (int i = 0; i < servicesReturned; i++)
                {
                    yield return((ENUM_SERVICE_STATUS_PROCESS)Marshal.PtrToStructure(ptr, typeof(ENUM_SERVICE_STATUS_PROCESS)));

                    ptr += Marshal.SizeOf(typeof(ENUM_SERVICE_STATUS_PROCESS));
                }
            }
            finally
            {
                Marshal.FreeHGlobal(bufferPtr);
            }
        }
Exemplo n.º 4
0
 public static bool GetLogStatusPerType(SERVICE_TYPE serviceType)
 {
     if (_serviceLocatorInstance)
     {
         return(_serviceLocatorInstance.GetLoggedStatusPerType(serviceType));
     }
     return(false);
 }
Exemplo n.º 5
0
 public bool GetLoggedStatusPerType(SERVICE_TYPE serviceType)
 {
     if (loggedServiceStatusMap.ContainsKey(serviceType))
     {
         return(logStatusPerServiceType[loggedServiceStatusMap[serviceType]].isLogged);
     }
     return(false);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Dummy parsovanie
        /// </summary>
        /// <param name="req_s"> string predstavujuci sparsovany objekt</param>
        /// <returns></returns>
        public static Response ConvertToResponse(string req_s)
        {
            XElement     tree = XElement.Parse(req_s);
            SERVICE_TYPE t    = (SERVICE_TYPE)Enum.Parse(typeof(SERVICE_TYPE), tree.Attribute("type").Value);
            RESULT_CODE  r    = (RESULT_CODE)Enum.Parse(typeof(RESULT_CODE), tree.Attribute("code").Value);
            string       data = tree.Value;

            return(new Response(t, data, r));
        }
Exemplo n.º 7
0
 void OnServiceReady(SERVICE_TYPE serviceType, bool isConnectedSucc)
 {
     Debug.Log("OnServiceReady---------------------" + serviceType + "," + isConnectedSucc);
     if (serviceType == SERVICE_TYPE.SIX_DOF)
     {
         bool support6DOF = NxrViewer.Instance.GetNibiruService().IsSupport6DOF();
         Debug.Log("Six Dof Support Status : " + (support6DOF ? 1 : 0));
     }
 }
Exemplo n.º 8
0
 internal static extern bool EnumServicesStatus(
     IntPtr serviceControlObject,
     SERVICE_TYPE serviceType,
     SERVICE_STATE_FLAGS serviceState,
     IntPtr bufferPtr,
     Int32 bufferSize,
     ref Int32 bufferNeeded,
     ref Int32 servicesReturned,
     ref UInt32 resumeHandle);
Exemplo n.º 9
0
 internal static extern bool EnumServicesStatus(
     IntPtr hSCManager,
     SERVICE_TYPE dwServiceType,
     SERVICE_ACTIVE_STATE dwServiceState,
     IntPtr lpServices,
     int cbBufSize,
     out int pcbBytesNeeded,
     out int lpServicesReturned,
     ref int lpResumeHandle);
Exemplo n.º 10
0
        /// <summary>
        /// Vlozenie a zabalenie spravy podla zadaneho typu
        /// do urcenej struktury
        /// </summary>
        /// <param name="type"> typ requestu</param>
        /// <param name="data"> data requestu</param>
        /// <return>Message</return>
        public Message Wrap(MESSAGE_TYPE m, SERVICE_TYPE type, string data)
        {
            string message_content = "";

            if (m == MESSAGE_TYPE.REQUEST)
            {
                message_content = new Request(type, data, DataSet.Instance().loged_user).ToString();
            }

            return(new Message(m, message_content));
        }
Exemplo n.º 11
0
 internal static extern bool EnumServicesStatusEx(IntPtr hSCManager,
                                                  int infoLevel,
                                                  SERVICE_TYPE serviceType,
                                                  SERVICE_STATE_FLAGS serviceState,
                                                  IntPtr services,
                                                  Int32 bufSize,
                                                  ref Int32 bytesNeeded,
                                                  ref Int32 servicesReturned,
                                                  ref UInt32 resumeHandle,
                                                  string groupName
                                                  );
Exemplo n.º 12
0
 private Service FindServiceOfType(SERVICE_TYPE type, ref Service[] services)
 {
     for (int i = 0; i < services.Length; ++i)
     {
         if (services[i].GetServiceType() == type)
         {
             return(services[i]);
         }
     }
     return(null);
 }
Exemplo n.º 13
0
 internal static extern bool EnumServicesStatusEx(
     IntPtr hSCManager,
     INFO_LEVEL infoLevel,
     SERVICE_TYPE dwServiceType,
     SERVICE_ACTIVE_STATE dwServiceState,
     IntPtr lpServices,
     int cbBufSize,
     out int pcbBytesNeeded,
     out int lpServicesReturned,
     ref int lpResumeHandle,
     string pszGroupName);
Exemplo n.º 14
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.º 15
0
            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.º 16
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.º 17
0
 internal static extern IntPtr CreateService(
     IntPtr hSCManager,
     string lpServiceName,
     string lpDisplayName,
     SERVICE_ACCESS dwDesiredAccess,
     SERVICE_TYPE dwServiceType,
     SERVICE_START_TYPE dwStartType,
     SERVICE_ERROR dwErrorControl,
     string lpBinaryPathName,
     string lpLoadOrderGroup,
     IntPtr lpdwTagId,
     string lpDependencies,
     string lpServiceStartName,
     string lpPassword);
Exemplo n.º 18
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.º 19
0
            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.º 20
0
        public IService CreateService(
            string serviceName,
            string displayName,
            SERVICE_ACCESS desiredAccess,
            SERVICE_TYPE serviceType,
            SERVICE_START_TYPE startType,
            SERVICE_ERROR_CONTROL errorControl,
            string binaryPathName,
            string loadOrderGroup,
            IntPtr tagId,
            ICollection <string> dependencies,
            string serviceStartName,
            string password)
        {
            string deps = (dependencies?.Any() ?? false) ? string.Join("\0", dependencies) : null;

            var serviceHandle = NativeMethods.CreateService(
                handle,
                serviceName,
                displayName,
                (uint)desiredAccess,
                (uint)serviceType,
                (uint)startType,
                (uint)errorControl,
                binaryPathName,
                loadOrderGroup,
                tagId,
                deps,
                serviceStartName,
                password
                );

            if (serviceHandle == IntPtr.Zero)
            {
                throw new Win32Exception();
            }

            return(new Service(serviceHandle));
        }
Exemplo n.º 21
0
        /// <summary>
        /// Dummy parsovanie
        /// </summary>
        /// <param name="req_s"> string predstavujuci sparsovany objekt</param>
        /// <returns></returns>
        public static Request ConvertToRequest(string req_s)
        {
            try
            {
                XElement     tree = XElement.Parse(req_s);
                SERVICE_TYPE t    = (SERVICE_TYPE)Enum.Parse(typeof(SERVICE_TYPE), tree.Attribute("type").Value);

                XElement user_element = tree.Element("user");
                string   username     = user_element.Attribute("username").Value;
                int      hash         = Int32.Parse(user_element.Attribute("password_hash").Value);
                Account  user         = new Account()
                {
                    Is_LogedOn = false, password_hash = hash, user_name = username
                };

                string data = tree.Element("data").Value;
                return(new Request(t, data, user));
            }
            catch (Exception) {
                return(null);
            }
        }
Exemplo n.º 22
0
    void CreateNullService(SERVICE_TYPE serviceType)
    {
        switch (serviceType)
        {
        case SERVICE_TYPE.EXAMPLE:
        {
            serviceMaps[serviceType] = ExampleBaseService.GetNullService(GetLoggedStatusPerType(serviceType));
            break;
        }

        case SERVICE_TYPE.NONE:
        {
            serviceMaps[serviceType] = GetNullService();
            break;
        }

        case SERVICE_TYPE.TOTAL:
        {
            serviceMaps[serviceType] = GetServiceOfType(SERVICE_TYPE.NONE);
            break;
        }
        }
    }
Exemplo n.º 23
0
    public Service GetServiceOfType(SERVICE_TYPE serviceType)
    {
        if (Application.isPlaying)
        {
            Service currentService = null;
            //check if we have it already
            if (serviceMaps.TryGetValue(serviceType, out currentService))
            {
                //if we do, check if its null
                if (currentService == null)
                {
                    CreateNullService(serviceType);
                }
            }
            else
            {
                CreateNullService(serviceType);
            }

            return(serviceMaps[serviceType]);
        }
        return(null);
    }
Exemplo n.º 24
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);
                }
            }
        }
Exemplo n.º 25
0
 public static extern SafeServiceHandle CreateService(SafeServiceHandle hSCManager,
                                                      string lpServiceName, string lpDisplayName, SERVICE_ACCESS dwDesiredAccess,
                                                      SERVICE_TYPE dwServiceType, ServiceStartType dwStartType, SERVICE_ERROR dwErrorControl,
                                                      string lpBinaryPathName, string lpLoadOrderGroup, IntPtr lpdwTagId,
                                                      char[] lpDependencies, string lpServiceStartName, string lpPassword);
Exemplo n.º 26
0
 public Response(SERVICE_TYPE type, string data, RESULT_CODE r)
 {
     this.type = type;
     this.data = data;
     this.code = r;
 }
 public static extern IntPtr CreateService(IntPtr SC_HANDLE, string lpSvcName, string lpDisplayName,
                                           SERVICE_DESIRED_ACCESS dwDesiredAccess, SERVICE_TYPE dwServiceType, START_TYPE dwStartType, ERROR_CONTROL_TYPE dwErrorControl, string lpPathName,
                                           string lpLoadOrderGroup, int lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword);
Exemplo n.º 28
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.º 29
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.º 30
0
 public T GetServiceOfType <T>(SERVICE_TYPE serviceType) where T : Service
 {
     return((T)GetServiceOfType(serviceType));
 }
Exemplo n.º 31
0
 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);
 }
Exemplo n.º 32
0
 public Request(SERVICE_TYPE type, string data, Account user)
 {
     this.type = type;
     this.data = data;
     this.user = user;
 }
Exemplo n.º 33
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);
			}
		}
Exemplo n.º 34
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.º 35
0
 internal static extern bool ChangeServiceConfig(SafeServiceHandle service, SERVICE_TYPE serviceType, SERVICE_STARTTYPE startType,
                                                 SERVICE_ERRORCONTROL errorControl, String binaryPathName, String loadOrderGroup, IntPtr pdwTagId, String dependencies, String serviceStartName,
                                                 String password, String displayName);
Exemplo n.º 36
0
 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));
 }