zoukankan      html  css  js  c++  java
  • C# 根据服务名打开所在文件夹

    using System.Management;

    private string button_open_Click(object sender, EventArgs e)
    {
      try
      {
        string servicename = this.listView_serverlist.FocusedItem.SubItems[0].Text;

        string RetString = string.Empty;
        string query = "select PathName from Win32_Service where name ='" + servicename + "'";
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
        foreach (ManagementObject ob in searcher.Get())
        {
        RetString = ob["PathName"].ToString();
        break;
        }
      searcher.Dispose();
      return RetString; // RetString直接到文件名
      // RetString = RetString.Substring(0, RetString.LastIndexOf('\') + 1); // RetString 是目录
      // Process.Start("explorer.exe", RetString); // 通过程序打开文件夹
      }
      catch (Exception)
      {

      }
    }

  • 相关阅读:
    栈和队列
    数组的遍历查找
    字符串的子串
    两个字符串
    字符串的遍历
    字符串的替换
    数组和矩阵
    Django 自带的ORM增删改查
    what's the CRSF ??
    Rabbitmq -Publish_Subscribe模式- python编码实现
  • 原文地址:https://www.cnblogs.com/wa502/p/11603335.html
Copyright © 2011-2022 走看看