C# 运行指定程序,可以方便扩展
来源:互联网 发布:龙岩新罗天气预报软件 编辑:程序博客网 时间:2024/06/08 05:07
主要测试代码:
using System;using System.Collections.Generic;using System.Windows.Forms;using System.IO;using System.Diagnostics;namespace CallBat{/// <summary>/// 作者:Jave.Lin/// </summary>static class Program{/// <summary>/// 应用程序的主入口点。/// </summary>[STAThread]static void Main(string[] args){//Application.EnableVisualStyles();//Application.SetCompatibleTextRenderingDefault(false);//Application.Run(new Form1());if (args.Length == 0){Console.WriteLine("args.Length==0 error!");return;}string fileName = args[0];if (!File.Exists(fileName)){Console.WriteLine("fileName is not Exists error! the fileName is:\r\n"+fileName);return;}string fileNameNoExtension = Path.GetFileNameWithoutExtension(fileName);Process[] tps = Process.GetProcessesByName(fileNameNoExtension);if (tps != null){foreach (Process tp in tps){if (tp.ProcessName == fileNameNoExtension){try{Console.WriteLine("[" + fileNameNoExtension + "] process had run, and then will kill it!");tp.Kill();tp.Close();}catch{ }}}}string workDirectory = Path.GetDirectoryName(fileName);System.Diagnostics.Process p = new System.Diagnostics.Process();p.StartInfo.UseShellExecute = false;p.StartInfo.CreateNoWindow = true;//设置为false将会看到程序窗口 p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;//启动进程时窗口状态 p.StartInfo.RedirectStandardOutput = true;//p.StartInfo.FileName = Server.MapPath("a.bat"); p.StartInfo.FileName = fileName;//如果a.bat在System32文件夹中,此处只需填写文件名即可p.StartInfo.WorkingDirectory = workDirectory;if (args.Length > 1){string argsStr = string.Empty;for (int i = 1; i < args.Length; i++){argsStr += args[i] + " ";}p.StartInfo.Arguments = argsStr;}p.Start();p.Close(); }}}
- C# 运行指定程序,可以方便扩展
- 在C#中使用PrintDialog可以很方便的实现程序的打印功能。
- C#程序Debug文件夹可以运行,无法调试
- 多线程、方便扩展的Windows服务程序
- 禁用指定程序运行
- Junit4.x扩展:运行指定方法
- linux指定程序运行优先级
- 指定jre运行jar程序
- Windows阻止指定程序运行
- java运行指定程序exe
- 如何指定GPU运行程序
- 扩展js,实现c#中的string.format方便拼接字符串
- 扩展Emacs,方便执行正在编辑的Perl程序
- C#中的快捷键,可以更方便的编写代码
- C#中的快捷键,可以更方便的编写代码
- C#中的快捷键,可以更方便的编写代码
- C# 程序运行无法加载 C++ DLL“xxx.dll”: 找不到指定的模块
- C#程序运行效果
- Ubuntu常用配置
- js的escape函数
- 初学UML之-------用例图
- 一年成为Emacs高手(像神一样使用编辑器)
- IE6 调用gzip压缩后JavaScript不执行的解决方法
- C# 运行指定程序,可以方便扩展
- c语言面试题
- Python:非常好的面向对象编程语言
- 【android】EditText属性大全
- struts2中<s:select >标签的使用
- 使用代码获得win7某个文件的权限
- HDU 1003 Max Sum
- Windows系统磁盘分区和卷的概念
- 将查询组件与提供者关联,则客户端数据集支持查询行为