自定义可执行文件扩展名(非exe)
关键是在启动过程之前将Process.StartInfo.UseShellExecute属性设置为false。接着使用start即可启动非exe文件作为可执行文件运行。
1 2 3 4 |
System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = @"c:\test\test.extname"; p.StartInfo.UseShellExecute = false; p.Start(); |
或者
1 2 3 4 5 6 |
var processStartInfo = new ProcessStartInfo { FileName = @"c:\test\test.extname", UseShellExecute = false }; Process.Start(processStartInfo); |
或者
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
var proc = new Process { StartInfo = new ProcessStartInfo { FileName = "test.extname", Arguments = "参数", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true } }; proc.Start(); while (!proc.StandardOutput.EndOfStream) { //输出执行结果 string line = proc.StandardOutput.ReadLine(); } |
如果您对C#游戏开发感兴趣,可以扫下面二维码加入我们的QQ群来一起学习交流
原创文章,转载请注明本文链接地址(违者必究):自定义可执行文件扩展名(非exe)