最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

c# 將Minio.exe注冊(cè)成windows服務(wù)

 更新時(shí)間:2020年11月12日 10:17:28   作者:easten  
這篇文章主要介紹了c# 如何將Minio.exe注冊(cè)成windows服務(wù),幫助大家更好的理解和使用c#,感興趣的朋友可以了解下

minio 注冊(cè)成windows 服務(wù)的工具開發(fā)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
  public partial class Main : Form
  {
    public Main()
    {
      InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
      // 注冊(cè)服務(wù)
      var script= this.CreateXmlContent();

      try
      {
        using (Runspace runspace = RunspaceFactory.CreateRunspace())
        {
          runspace.Open();
          PowerShell ps = PowerShell.Create();
          ps.Runspace = runspace;
          ps.AddScript(script);
          ps.Invoke();
        }

        Thread.Sleep(2000);
        // 啟動(dòng)服務(wù)
        StartService();

        MessageBox.Show(@"服務(wù)啟動(dòng)成功");
      }
      catch (Exception ex)
      {
        MessageBox.Show(@"注冊(cè)失敗");
      }
    }

    private string CreateXmlContent()
    {
      var filePath = Path.Combine(Directory.GetCurrentDirectory(), "minio-service.ps1");
      if (!File.Exists(filePath))
      {
        File.Create(filePath).Close();
      }

      var content =
        "if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] \"Administrator\")) { Start-Process powershell.exe \"-NoProfile -ExecutionPolicy Bypass -File `\"$PSCommandPath`\"\" -Verb RunAs; exit }";
      content += "Set-Location -Path $PSScriptRoot\r\n\r\n";
      content += "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12\r\n";
      content += "$config = @'\r\n";
      content += "<service>\r\n";
      content += $" <id>{textBox1.Text}</id>\r\n";
      content += $" <name>{textBox1.Text}</name>\r\n";
      content += " <description>MinIO server is a nb oss server</description>\r\n";
      content += " <executable>minio.exe</executable>\r\n";
      content += $@" <env name=""MINIO_ACCESS_KEY"" value=""{textBox5.Text}"" />" + "\r\n";
      content += $@" <env name=""MINIO_SECRET_KEY"" value =""{textBox4.Text}"" />" + "\r\n";
      content += $@" <arguments>server --address 0.0.0.0:{textBox2.Text} {textBox3.Text}</arguments>" + "\r\n";
      content += @" <logmode>rotate</logmode>" + "\r\n";
      content += @" </service>" + "\r\n";
      content += @"'@" + "\r\n\r\n";
      content += @"Set-Content ""minio-service.xml"" $config" + "\r\n";
      content += @"Start-Process -WorkingDirectory $PSScriptRoot -FilePath ""$($PSScriptRoot)\minio-service.exe"" -ArgumentList ""install"" -NoNewWindow -PassThru -Wait" + "\r\n";
      content += @"Write-Host ""Installation done""";

      File.WriteAllText(filePath, content, Encoding.Default);

      return filePath;
    }

    private void Main_Load(object sender, EventArgs e)
    {
      textBox3.Text = Path.Combine(Directory.GetCurrentDirectory(), "minio");
      // 獲取資源
      var minio_service = MinioTool.Properties.Resources.minio_service;
      var exePath = Path.Combine(Directory.GetCurrentDirectory(), "minio-service.exe");
      if (!File.Exists(exePath))
      {
        File.Create(exePath).Close();
      }
      File.WriteAllBytes(exePath, minio_service);
    }

    /// <summary>
    /// 啟動(dòng)服務(wù)
    /// </summary>
    private void StartService()
    {
      ServiceController[] services = ServiceController.GetServices();
      foreach (ServiceController service in services)
      {
        if (service.ServiceName == textBox1.Text)
        {
          if (service.Status != ServiceControllerStatus.Running)
          {
            service.Start();
          }
        }
      }
    }
  }
}

軟件截圖:

以上就是c# 將Minio.exe注冊(cè)成windows服務(wù)的詳細(xì)內(nèi)容,更多關(guān)于Minio.exe注冊(cè)成windows服務(wù)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • C#調(diào)用打印機(jī)實(shí)現(xiàn)打印

    C#調(diào)用打印機(jī)實(shí)現(xiàn)打印

    這篇文章介紹了C#調(diào)用打印機(jī)實(shí)現(xiàn)打印的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-04-04
  • 詳解c# 并行計(jì)算

    詳解c# 并行計(jì)算

    本文主要介紹了并行計(jì)算的簡單使用,并行循環(huán)的中斷和跳出、并行循環(huán)中為數(shù)組/集合添加項(xiàng)、返回集合運(yùn)算結(jié)果/含有局部變量的并行循環(huán)、、PLinq(Linq的并行計(jì)算)等相關(guān)內(nèi)容。
    2020-12-12
  • Unity調(diào)取移動(dòng)端的麥克風(fēng)進(jìn)行錄音并播放

    Unity調(diào)取移動(dòng)端的麥克風(fēng)進(jìn)行錄音并播放

    這篇文章主要為大家詳細(xì)介紹了Unity調(diào)取移動(dòng)端的麥克風(fēng)進(jìn)行錄音并播放,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-06-06
  • WinForm實(shí)現(xiàn)為ComboBox綁定數(shù)據(jù)源并提供下拉提示功能

    WinForm實(shí)現(xiàn)為ComboBox綁定數(shù)據(jù)源并提供下拉提示功能

    這篇文章主要介紹了WinForm實(shí)現(xiàn)為ComboBox綁定數(shù)據(jù)源并提供下拉提示功能,是非常實(shí)用的功能,需要的朋友可以參考下
    2014-08-08
  • C#中調(diào)用DLL時(shí)未能加載文件或程序集錯(cuò)誤的處理方法(詳解)

    C#中調(diào)用DLL時(shí)未能加載文件或程序集錯(cuò)誤的處理方法(詳解)

    下面小編就為大家?guī)硪黄狢#中調(diào)用DLL時(shí)未能加載文件或程序集錯(cuò)誤的處理方法(詳解)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-02-02
  • WPF實(shí)現(xiàn)Interaction框架的Behavior擴(kuò)展

    WPF實(shí)現(xiàn)Interaction框架的Behavior擴(kuò)展

    這篇文章介紹了WPF實(shí)現(xiàn)Interaction框架Behavior擴(kuò)展的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-06-06
  • C#實(shí)現(xiàn)過濾sql特殊字符的方法集合

    C#實(shí)現(xiàn)過濾sql特殊字符的方法集合

    這篇文章主要介紹了C#實(shí)現(xiàn)過濾sql特殊字符的方法,以實(shí)例形式分析總結(jié)了C#針對(duì)SQL危險(xiǎn)字符的幾種常用的過濾技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-11-11
  • 最新評(píng)論

    吉安县| 灵丘县| 永靖县| 永仁县| 芷江| 鹿邑县| 贵阳市| 精河县| 和田市| 龙岩市| 华安县| 郓城县| 三门县| 阿拉善左旗| 合川市| 会东县| 永胜县| 华蓥市| 福清市| 汽车| 德钦县| 南澳县| 萍乡市| 无锡市| 甘德县| 金昌市| 婺源县| 平谷区| 武山县| 柯坪县| 巴塘县| 东阿县| 青铜峡市| 光泽县| 治多县| 临邑县| 和静县| 如东县| 郁南县| 林周县| 金平|