Beispiel #1
0
        private void SetAccount(string username, string password)
        {
            CheckControlPermission();

            IntPtr oServiceHandle = GetServiceHandle(WindowsServicesHelper.SERVICE_QUERY_CONFIG | WindowsServicesHelper.SERVICE_CHANGE_CONFIG);

            try
            {
                if (!WindowsServicesHelper.ChangeServiceConfig(
                        oServiceHandle,
                        WindowsServicesHelper.SERVICE_NO_CHANGE, WindowsServicesHelper.SERVICE_NO_CHANGE,

                        WindowsServicesHelper.SERVICE_NO_CHANGE,
                        null,
                        null,
                        IntPtr.Zero,
                        null,
                        username,
                        password,
                        null
                        ))
                {
                    throw CreateSafeWin32Exception();
                }
            }
            finally
            {
                WindowsServicesHelper.CloseServiceHandle(oServiceHandle);
            }
        }
Beispiel #2
0
        private void SetStartMode(ServiceStartMode eStartMode)
        {
            if (m_bStartModeAvailable && (eStartMode == m_eStartMode))
            {
                return;
            }

            CheckControlPermission();

            IntPtr oServiceHandle = GetServiceHandle(WindowsServicesHelper.SERVICE_QUERY_CONFIG | WindowsServicesHelper.SERVICE_CHANGE_CONFIG);

            try
            {
                if (!WindowsServicesHelper.ChangeServiceConfig(
                        oServiceHandle,
                        WindowsServicesHelper.SERVICE_NO_CHANGE,
                        (int)eStartMode,
                        WindowsServicesHelper.SERVICE_NO_CHANGE,
                        null,
                        null,
                        IntPtr.Zero,
                        null,
                        null,
                        null,
                        null
                        ))
                {
                    throw CreateSafeWin32Exception();
                }

                m_eStartMode          = eStartMode;
                m_bStartModeAvailable = true;
            }
            finally
            {
                WindowsServicesHelper.CloseServiceHandle(oServiceHandle);
            }
        }