首页 > 其他分享 >Process.Start 报错

Process.Start 报错

时间:2023-08-14 12:57:22浏览次数:36  
标签:Process System Environment Start 报错 true

Process.Start 报错 System.Diagnostics.Process.StartWithShellExecuteEx

Process.Start 为什么会引发“系统找不到指定的文件”异常

Process.Start 报错 找不到路径 ,System.ComponentModel.Win32Exception:“系统找不到指定的文件。

问题1

在WinForm中可能是权限问题,设置文件夹和文件权限即可,也可能是NET版本太低了,只要把项目版本从net2.0  换成4.0以及以上,同时 解决方案平台设置位 AnyCPU 即可

//报错找不到路径 ,System.ComponentModel.Win32Exception:“系统找不到指定的文件。” ----只要把net2.0 换成4.0以及以上,同时 解决方案平台设置位 AnyCPU 即可
//Process.Start(@"F:\osk.exe");
var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "osk.exe");
Process.Start(path);
   var p = new Process();
            p.StartInfo = new ProcessStartInfo(path)
            {
                WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.System),
                UseShellExecute = true,
                Verb = "runas" //管理员权限
            };
            p.Start();

 

问题2

在NET6 中可能是NET Framework 版本的最后执行的是StartWithShellExecuteEx而不是StartWithCreateProcess方法

造成这样的原因,是因为UseShellExecute在 .NET 6 上默认为 false:

public bool UseShellExecute { get; set; }

而在 .NET Framework 上默认为 true:

//
// 摘要:
// Gets or sets a value indicating whether to use the operating system shell to
// start the process.
//
// 返回结果:
// true if the shell should be used when starting the process; false if the process
// should be created directly from the executable file. The default is true.
[DefaultValue(true)]
[MonitoringDescription("ProcessUseShellExecute")]
[NotifyParentProperty(true)]
public bool UseShellExecute { get; set; }

问题3、

如果想使用参数的话,需要在 Arguments上设置参数

 var p = new Process();
            p.StartInfo = new ProcessStartInfo(path)
            {
                WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.System),
                UseShellExecute = true,
                Verb = "runas",
                Arguments="参数"
            };
            p.Start();

 

 

标签:Process,System,Environment,Start,报错,true
From: https://www.cnblogs.com/1175429393wljblog/p/17628327.html

相关文章

  • 安装MinGW时报错“The file has been downloaded incorrectly!”解决方案
    前言作为一个准备学习C语言的准大一的通信工程崽子,Linux还不会用,在Windows上使用gcc得安装MinGW。我知道各位大佬们看到第一句话之后想说些什么。虽然说有很多优秀的编程软件自带了MinGW,但是想想,如果使用Windows的cmd直接敲个“gcc-v”来跑代码,逼格不直接蹭蹭上涨,能够充分满足......
  • volatility3处理虚拟机内存快照报错
    准备工作python3.7以上https://github.com/volatilityfoundation/volatility3#安装pipinstallvolatility3#使用vol.exe-vvv-ftest-Snapshot1.vmemhashdump-vvv显示详细的报错信息-f指定内存镜像hashdump获取账号密码hash生成Linux下的standalone文件在Li......
  • Windows 10更新后,打开windows sandbox沙盒报错,找不到虚拟机监控程序的解决办法
    要点:1.卸载沙盒2.命令提示符输入bcdedit/sethypervisorlaunchtypeAuto3.重启后重新安装沙盒 windows10打开windowssandbox突然出现报错:找不到虚拟机监控程序。请启用虚拟机监控程序支持。Error0xc0351000.该系统上没有虚拟机监控程序。解决办法: 1、卸载windows沙......
  • git 上传报错及解决方案
    failedtopushsomerefsto报错内容,不能推送文件到github上error:failedtopushsomerefstogithub地址原因是github项目与本地文件夹一些关键文件的确实,比如.git,readme.md文件等等解决:本地文件夹打开控制命令台1、添加本地文件夹,github项目更新到本地gitadd.git......
  • 【Solid works报错(无法连接到服务器)】
    报错有时,安装好SolidWorks后,打开时会弹出如下的错误弹窗原因最主要的原因之一为:安装的杀毒软件将SolidWorks服务设为禁止启动,每次开机后都需要进行手动的启动,这里以火绒为例。点击进入火绒之后,点击启动项管理,找到服务项中的SolidWorksFlexnetServer和SolidWorksLicens......
  • 自定义springboot-starter包
    https://www.cnblogs.com/yuansc/p/9088212.html 前言我们都知道可以使用SpringBoot快速的开发基于Spring框架的项目。由于围绕SpringBoot存在很多开箱即用的Starter依赖,使得我们在开发业务代码时能够非常方便的、不需要过多关注框架的配置,而只需要关注业务即可。例如我想......
  • PXE操作过程 kickstart 无人值守安装
    PXE操作过程分配给同一局域网内新加机器的地址(配置文件)dhcp分配地址指明tftp服务器的地址tftp服务端开启udp配置默认关闭安装syslinux取得pxelinux.0文件安装vsftpd服务挂载软件安装源(mount/dev/sr0/var/ftp/centos7)将四大文件拷入(/var/lib/tftpboot......
  • org.springframework.context.ApplicationContextException: Failed to start bean 'd
    ##    一、报错信息org.springframework.context.ApplicationContextException:Failedtostartbean'documentationPluginsBootstrapper';nestedexceptionisjava.lang.NullPointerException具体报错信息如下:##  二、报错原因     SpringBoot2......
  • mysql在开启group_replication后,状态显示为RECOVERING,告警日志报错MY-013117、MY-0115
    问题描述:mysql在开启group_replication后,状态显示为RECOVERING,告警日志报错MY-013117、MY-011582、MY-011583,如下所示:数据库:MySQL8.0.27系统:rhel7.364位1、问题重现Slave02[(none)]>select*fromperformance_schema.replication_group_members;+-----------------------......
  • mysql在开启group_replication后,报错ERROR 3092,This member has more executed transa
    问题描述:mysql在开启group_replication后,报错ERROR3092,Thismemberhasmoreexecutedtransactionsthanthosepresentinthegroup,如下所示:数据库:MySQL8.0.27系统:rhel7.31、异常重现Slave01[(none)]>startgroup_replication;ERROR3092(HY000):Theserverisnotc......