Example #1
0
        /// <summary>
        /// 安裝 uvnc_service 服務 <br/>
        /// 權限不夠時: <br/>
        /// 1. 從當前user temp文件夾下讀取文件 <br/>
        /// 2. 檢查 UVncOption.AdminUser 和 UVncOption.AdminPasswd <br/>
        /// 3. 驗證不通過 則 彈出 賬戶密碼 輸入框
        /// </summary>
        /// <param name="waitSecond">等待秒數</param>
        /// <returns></returns>
        public bool InstallVncServiceWait_Authorize(int waitSecond)
        {
            if (VncServiceExist())
            {
                return(true);
            }

            if (InvokeValidateAccountOrOpenInputAccountBox())
            {
                var cmd = new CMDHelper();
                if (cmd.CreateProcessExeAsUser(_winvncExe, "-install", UVncOption.AdminUser, UVncOption.AdminPasswd))
                {
                    for (int i = 0; i < waitSecond; i++)
                    {
                        Thread.Sleep(1000);
                        if (VncServiceExist())
                        {
                            using var service = new ServiceController(_vncServiceName);
                            if (service.Status == ServiceControllerStatus.Running || service.Status == ServiceControllerStatus.StartPending)
                            {
                                return(true);
                            }

                            string arg = "start " + _vncServiceName;
                            cmd.CreateProcessExeAsUser(_scExe, arg, UVncOption.AdminUser, UVncOption.AdminPasswd);
                            service.WaitForStatus(ServiceControllerStatus.Running, _waitServiceTime);
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Example #2
0
        /// <summary>
        /// 刪除 uvnc_service 服務 <br/>
        /// 權限不夠時: <br/>
        /// 1. 從當前user temp文件夾下讀取文件 <br/>
        /// 2. 檢查 UVncOption.AdminUser 和 UVncOption.AdminPasswd <br/>
        /// 3. 驗證不通過 則 彈出 賬戶密碼 輸入框
        /// </summary>
        /// <param name="waitSecond">等待秒數</param>
        /// <returns></returns>
        public bool UninstallVncServiceWait_Authorize(int waitSecond)
        {
            if (!VncServiceExist())
            {
                return(true);
            }

            if (InvokeValidateAccountOrOpenInputAccountBox())
            {
                var cmd = new CMDHelper();
                if (cmd.CreateProcessExeAsUser(_winvncExe, "-uninstall", UVncOption.AdminUser, UVncOption.AdminPasswd))
                {
                    for (int i = 0; i < waitSecond; i++)
                    {
                        Thread.Sleep(1000);
                        if (!VncServiceExist())
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }