我正在嘗試將IL代碼編譯到程序集。 ilasm.exe
應該被我的C#應用程序調用。我通過ProcessStartInfo
實例調用ilasm.exe
。體育課的生成正常,我的大會正在開展工作。爲什麼我的IL生成的Assembly,由C#調用的ilasm.exe需要UAC?
我的問題是,由我的應用程序創建的文件,以後需要管理員權限才能執行。
如果我通過命令行手動調用ilasm.exe
,則不需要管理員權限。
使用ilasm.exe命令: ilasm.exe /qui /output="c:\test\newFile.exe" <path to il file>
我的應用程序調用ilasm.exe:
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\ilasm.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = ilFilePath + " /qui /output=" + outputPath + "testFile.exe";
try
{
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
}
catch
{
// Log error.
}
難道我做錯了什麼?從C#調用另一個進程時是否需要指定其他內容?
我正在運行我的應用程序和沒有管理員權限的命令行。
作爲非管理員收到的錯誤是什麼?什麼是patchFile?你不會像你說的那樣從命令行調用它。 – 2012-04-04 00:24:28
對不起,我忘了提及一些事情。在這種情況下,patchFile是包含il代碼的文件的路徑。我沒有收到任何錯誤。錯誤在於ilasm.exe通過c#代碼調用,之後需要管理員權限才能執行,而ilasm.exe通過cmd調用並不需要它們。 – 2012-04-04 00:36:13
如果我理解你,你說的都是生成有效的EXE,但是從'Process.Start'生成的EXE會讓你的計算機去* BOOP *並彈出UAC提示符。如果是這樣的話,聽起來就像代碼中嵌入了'highestAvailable'' requestedExecutionLevel'解釋[here](http://msdn.microsoft.com/en-us/library/bb756929.aspx)。如果是這樣,我不知道爲什麼它會不同。 – 2012-04-04 00:40:49