/// <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:\Projects\Hotels\StartUpgrade\StartUpgrade\File\"/> <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(); }