• C# 启动进程和杀死进程


         /// <summary>
            /// 杀死进程
            /// </summary>
            private void KillProcesses()
            {
                var cfn = GetAppsettingStr("checkin-filefolder-name");
                var ofn = GetAppsettingStr("outmoney-filefolder-name");
                var ifn = GetAppsettingStr("inmoney-filefolder-name");
                foreach (var p in Process.GetProcesses())
                {
                    if (p.ProcessName == cfn || p.ProcessName == ofn || p.ProcessName == ifn)
                    {
                        p.Kill();
                    }
                }
            }
    
            /// <summary>
            /// 启动进程
            /// </summary>
            private void StartProcesses()
            {
                var list = new List<string>();
                var cfn = GetAppsettingStr("checkin-filefolder") + GetAppsettingStr("checkin-filefolder-name");
                var ofn = GetAppsettingStr("outmoney-filefolder") + GetAppsettingStr("outmoney-filefolder-name");
                var ifn = GetAppsettingStr("inmoney-filefolder") + GetAppsettingStr("inmoney-filefolder-name");
                list.Add(ofn);
                list.Add(ifn);
                list.Add(cfn);
                
                foreach (var li in list)
                {
                    Process.Start(li + ".exe");
                }
            }

    再加上从app.config 文件里获取数据

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <configSections>
            <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
                <section name="StartUpgrade.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
            </sectionGroup>
        </configSections>
      <appSettings>
        <!-- checkin 文件夹和文件名 -->
        <add key="checkin-filefolder" value="D:NotePad++"/>
        <add key="checkin-filefolder-name" value="npp.6.1.3.Installer"/>
        
        <!-- 出钞 文件夹和文件名 -->
        <add key="outmoney-filefolder" value="D:NotePad++"/>
        <add key="outmoney-filefolder-name" value="npp.6.1.3.Installer"/>
        
        <!-- 入钞 文件夹和文件名 -->
        <add key="inmoney-filefolder" value="D:NotePad++"/>
        <add key="inmoney-filefolder-name" value="npp.6.1.3.Installer"/>
        
        <!-- 字节数组 -->
        <add key="bytearrary" value="10240"/>
        <add key="upload-path" value="E:ProjectsHotelsStartUpgradeStartUpgradeFile"/>
        <add key="upload-url" value="http://192.168.1.200:8077/UpgradeFiles/"/>
        
        <!-- 机器id -->
        <add key="machineid" value="888"/>
      </appSettings>
        <system.serviceModel>
          <bindings />
          <client />
        </system.serviceModel>
        <applicationSettings>
          <StartUpgrade.Properties.Settings>
                <setting name="StartUpgrade_IStartUpgrade_UpgradeFile" serializeAs="String">
                    <value>http://192.168.1.155:8013/DataService/WebService/Interface/UpgradeFile.asmx</value>
                </setting>
            </StartUpgrade.Properties.Settings>
        </applicationSettings>
     
    </configuration>

    是这样获取app.config数据的:

            /// <summary>
            /// 获取配置文件里appsettings的数据
            /// </summary>
            /// <param name="str"></param>
            /// <returns></returns>
            public string GetAppsettingStr(string str)
            {
                var appReader = new AppSettingsReader();
                return appReader.GetValue(str, typeof(string)).ToString();
            }    
  • 相关阅读:
    存储型 XSS 原理复现
    反射型 XSS 原理复现
    HTTP 简易理解
    Markdown 流程图语法
    Dirsearch 快速开始
    sqlmap 快速开始
    SQL 注入原理
    XSS 原理
    51nod 1835 完全图
    11.5 AM 请求
  • 原文地址:https://www.cnblogs.com/zhangwei595806165/p/3517785.html
Copyright © 2020-2023  润新知