0
我正在嘗試創建一個控制檯應用程序來替換批處理文件。該批處理文件提示用戶並運行以下代碼...如何使用不同的用戶運行IE並指定url?
RUNAS/user:USA \%usr%「C:\ Program Files \ Internet Explorer \ iexplore.exe%ServerPath%/%AppName%」
如何將其轉換爲C#代碼?我基本上使用下面的代碼。我聲明瞭一個用戶名和一個路徑,但它總是通過我的Windows登錄啓動IE。我錯誤地使用動詞嗎?我是否需要輸入密碼?如果是,如何?
string sPath = ServerPath
ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\Program Files\Internet Explorer\iexplore.exe");
startInfo.Verb = @"runas /user:USA\" + sUser;
startInfo.Arguments = sPath;
startInfo.UseShellExecute = false;
Process.Start(startInfo);
IE啓動然後我得到一個SecurityRisk頁說:「你的安全設置級別使計算機處於危險之中」。但是,當運行批處理文件時,我不這樣做。 – James 2010-12-21 01:48:17
我假設Windows Vista/7?我建議嘗試以管理員身份運行「批處理模擬器」,並查看是否有幫助。 – 2010-12-21 01:51:40
Win XP,但添加此修復它:myProcess.LoadUserProfile = true; – James 2010-12-21 02:21:19