インストール起動Windowsサービスのアンインストールを停止c#

4217 ワード

質問:windowsサービスのインストール中、エラー:System.ComponentModel.Win 32 Exception:アカウント名が無効または存在しません.
解決:serviceProcessInstaller 1->Accoutプロパティを:LocalSystem(デフォルトはUser)に設定します.
実行:Installuitlプログラム名.exe、インストールに成功しました.
アンインストールはInstalluitl/uプログラム名です.exe 
 
質問:InstallUtilインストールを使用せずにWindowsサービスのアンインストールを停止するにはどうすればいいですか?
解决:システムを使う.Configuration.Install.AssemblyInstallerクラスは、プログラムセットをロードし、そのインストーラを実行します.[C#]//インストールサービスpublic static void InstallService(string filepath,string serviceName,string[]options){try{if(!IsServiceExisted){IDictionary mySavedState=new Hashtable();                AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();                myAssemblyInstaller.UseNewContext = true;                myAssemblyInstaller.Path = filepath;                myAssemblyInstaller.CommandLine = options;                myAssemblyInstaller.Install(mySavedState);                myAssemblyInstaller.Commit(mySavedState);                myAssemblyInstaller.Dispose();            }        }        catch (Exception ex)        {            throw new Exception("Install Service Error"+ ex.Message);}//アンインストールサービスpublic static void UnInstallService(string filepath,string serviceName,string[]options){try{if(IsServiceExisted){AssemblyInstaller myAssemblyInstaller=new AssemblyInstaller();                myAssemblyInstaller.UseNewContext = true;                myAssemblyInstaller.Path = filepath;                myAssemblyInstaller.CommandLine = options;                myAssemblyInstaller.Uninstall(null);                myAssemblyInstaller.Dispose();            }        }        catch (Exception ex)        {            throw new Exception("UnInstall Service Error"+ ex.Message);}//public static bool IsServiceExisted(string serviceName){ServiceController[]services=ServiceController.GetServices();foreach(ServiceController s in services){if(s.ServiceName==serviceName)}{                return true;            }        }        return false;}//サービス開始public static void StartService(string serviceName){if(IsServiceExisted){System.ServiceProcess.ServiceController service=new System.ServiceProcess.ServiceController(serviceName);if(service.Status != System.ServiceProcess.ServiceControllerStatus.Running &&                service.Status != System.ServiceProcess.ServiceControllerStatus.StartPending)            {                service.Start();                service.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(60));}}}//サービス停止public static void StopService(string serviceName){if(IsServiceExisted){System.ServiceProcess.ServiceController service=new System.ServiceProcess.ServiceController(serviceName);if(service.Status == System.ServiceProcess.ServiceControllerStatus.Running)            {                service.Stop();                service.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(60));            }        }    }
質問:「ベース接続がオフになっています.SSL/TLSセキュリティチャネルの信頼関係が確立されていません.」
public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{   //         
      return true;
} 

送信要求の前に次の行のコードを追加します.
ServicePointManager.ServerCertificateValidationCallback = CheckValidationResult;

質問:バッチファイルを作成してサービスのインストールとアンインストールを実現する方法
インストール
%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil.exe %~dp0\yourService.exe
Net Start yourService
sc config
yourService start= auto
pause
tip:
1:%~dp0
2:installutil.exe                ,       %~dp0\installutil.exe %~dp0\yourService.exe  
3:

アンインストール
%~dp0\InstallUtil.exe %~dp0\yourService.exe -upause