Win32Exception:目录名称无效 [英] Win32Exception: The directory name is invalid

查看:2206
本文介绍了Win32Exception:目录名称无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行过程作为具有管理员权限的启用运行Vista和UAC 2个不同的计算机,但在其中的一个我得到一个Win32Exception,说:目录名称是无效的

谁能告诉我什么是错我的代码?

  VAR MYFILE = D:\\SomeFolder\\MyExecutable.exe 
VAR workingFolder =D:\\SomeFolder
变种PINFO =新System.Diagnostics.ProcessStartInfo();
pInfo.FileName = MYFILE;
pInfo.WorkingDirectory = workingFolder;
pInfo.Arguments = myArgs;
pInfo.LoadUserProfile = TRUE;
pInfo.UseShellExecute = FALSE;
pInfo.UserName = {} UserAccount;
pInfo.Password = {} SecureStringPassword;
pInfo.Domain =;

System.Diagnostics.Process.Start(PINFO);



更新



这是执行上面的代码的应用程序有requireAdministrator执行级别。
我甚至将工作文件夹设置为Path.GetDirectoryName(MYFILE)新建System.IO.FileInfo(MYFILE).DirectoryName


解决方案

这是因为该文件的路径长度超过255个字符。


I'm trying to run a process as a different user that has Administrator privilege in 2 different computers running Vista and their UAC enabled but in one of them I get a Win32Exception that says "The directory name is invalid"

Can anyone tell me what is wrong with my code?

var myFile = "D:\\SomeFolder\\MyExecutable.exe";
var workingFolder = "D:\\SomeFolder";
var pInfo = new System.Diagnostics.ProcessStartInfo();
pInfo.FileName = myFile;
pInfo.WorkingDirectory = workingFolder;
pInfo.Arguments = myArgs;
pInfo.LoadUserProfile = true;
pInfo.UseShellExecute = false;
pInfo.UserName = {UserAccount};
pInfo.Password = {SecureStringPassword};
pInfo.Domain = ".";

System.Diagnostics.Process.Start(pInfo);

UPDATE

The application that executes the above code has requireAdministrator execution level. I even set the working folder to "Path.GetDirectoryName(myFile)" and "New System.IO.FileInfo(myFile).DirectoryName"

解决方案

It is because the path length of the file exceeds 255 characters.

这篇关于Win32Exception:目录名称无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆