[英]Process.Start exception: “The directory name is invalid”
我在我的Windows 2008測試環境中工作時,我的Windows 7 Professional 64位開發機器上的Process.Start
方法實現失敗。
const string CommandDirectory = @"C:\Program Files (x86)\Command";
var process = new Process
{
StartInfo =
{
FileName = string.Format("{1}{0}MyExecutable.exe", Path.DirectorySeparatorChar, CommandDirectory),
RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false,
UserName = userName,
Password = securePassword,
Domain = "MYDOMAIN",
},
};
process.Start();
在process.Start();
,我在我的開發機器上遇到以下異常:
System.ComponentModel.Win32Exception occurred
HResult=-2147467259
Message=The directory name is invalid
Source=System
ErrorCode=-2147467259
NativeErrorCode=267
StackTrace:
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
InnerException:
我嘗試了一些事情:
我確保我分配給進程的用戶帳戶對可執行文件所在的路徑以及%systemroot%位置具有完全權限。 我還確保用戶在本地安全策略中具有“在身份驗證后模擬客戶端”權限。
我已經嘗試將ProcessStartInfo.WorkingDirectory
顯式設置為CommandDirectory
。 當我這樣做時,可執行文件啟動但立即崩潰,沒有解釋。
我已經在我的開發機器上通過刪除UserName
, Password
和Domain
屬性使其使用我的個人憑據來實現此功能。 但這對於部署來說並不實用。 這使我覺得問題與憑據和權限有關。
誰能告訴我我做錯了什么?
@Julien Lebosquain的評論引導我回答。 我需要在本地登錄一次,因為我想冒充用戶。 這創建了默認用戶文件夾。
據推測,我調用的可執行文件需要寫入AppData或用戶目錄的另一個子文件夾。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.