使用Process.Start启动带参数进程时出现“文件未找到”异常的问题
问题解决:Process.Start启动带参数进程时提示“文件未找到”
你的代码错误在于使用了错误的Process.Start重载方法:
Process.Start(@"inject.exe example.dll example_process")
这个重载会把整个字符串当作可执行文件的完整路径,系统会尝试寻找名为inject.exe example.dll example_process的文件,自然找不到,所以抛出“file not found”异常。
正确的实现方式
方式1:使用ProcessStartInfo(推荐,更易扩展配置)
通过ProcessStartInfo分离程序路径和参数,是更规范的写法:
var startInfo = new ProcessStartInfo { FileName = "inject.exe", // 若不在当前目录,需写绝对路径,比如@"C:\YourPath\inject.exe" Arguments = "example.dll example_process" }; Process.Start(startInfo);
方式2:使用双参数重载的Process.Start
直接传入程序路径和参数两个独立字符串:
Process.Start(@"inject.exe", @"example.dll example_process");
额外注意事项
- 如果
inject.exe不在当前应用的工作目录下,必须指定绝对路径,否则系统会在默认路径中查找,依然可能报错。 - 确认
example.dll的路径是否正确,若不在inject.exe的工作目录,可能需要给DLL指定绝对路径。
内容的提问来源于stack exchange,提问作者niqu1337
相关产品推荐
相关产品推荐

