2010-09-29 19 views
2

當我如何開始從.NET應用程序`-energy`的Powercfg.exe?

using (var process = new Process 
{ 
    StartInfo = new ProcessStartInfo 
    { 
     FileName = "powercfg.exe", 
     Arguments = "-energy", 
     RedirectStandardOutput = true, 
     UseShellExecute = false, 
    } 
}) 
{ 
    process.Start(); 
    process.WaitForExit(); 
} 

它輸出:

庫診斷功耗效率(energy.dll)不 可能會被收取費用。

翻譯成英格爾斯:

能耗效率診斷庫(energy.dll)無法加載。

運行管理也是如此。

+0

唯一的問題當從.NET執行應用程序時,當我在命令行調用它,它運行正常 – 2010-09-29 16:12:56

+0

爲什麼d你有UseShellExecute =假? – dthorpe 2010-09-29 16:30:25

+0

@dthorpe RedirectStandardOutput =''TRUE'需要UseShellExecute = – 2010-09-29 16:44:10

回答

1

恐怕我不能重複你的結果;我得到的結果文件的預期。但是,如果有幫助,也許我的測試參數可以幫助你縮小了可能是在您的環境的罪魁禍首:

  • 運行Visual Studio 2010的管理員
  • 針對性的.NET 4客戶端配置文件
  • 編譯在x86任何CPU和二進制文件
  • 計算機運行的是Windows 7 64位
+0

罪魁禍首它沒有工作是參數「 - 能量」,它採用了「energy.dll」。我並沒有包括在你測試了它的團隊這樣的說法,但現在我編輯的問題。我的環境是一樣的你。 – 2010-09-29 17:09:18

+0

我沒有擺在那裏說法,這就是爲什麼我修改我的答案。它適用於書面。 – 2010-09-29 17:10:37

+0

它開始工作,但我不知道是什麼問題或使解決它 – 2010-09-29 17:21:08

0

設置WorkingDirectory的路徑energy.dllpowercfg.exe所在。

+0

FALSE'我嘗試 – 2010-09-29 12:07:37

+0

複製DLL到Windows \ System32下醜陋但大多是修復... – 2010-09-29 12:10:01

+0

@Mario的DLL已經存在 – 2010-09-29 12:14:31

相關問題