积极答复者
win10里 Powercfg /srumutil 收集功耗数据,无法通过Process类调用

问题
-
在做一个项目时后台使用最 Powercfg /srumutil收集功耗数据
在cmd里用管理员权限可以正常调用但是在代码里用Process类开一个进程,
通过 redirect output则每次都返回下面的错误
Unable to perform operation. An unexpected error (0x1f) has occurred: A device attached to the system is not functioning.
另外调用别的cmd也是可以正常work的(比如 Powercfg /A)
完全没有想法是什么问题导致,应该怎样在自己的代码里调用?
PS:代码是在Admin权限下运行的
答案
-
程序编译版本问题
- 已建议为答案 kelivnchgli 2016年10月19日 8:35
- 已标记为答案 ThankfulHeartModerator 2016年10月20日 6:54
- 已编辑 kelivnchgli 2016年10月24日 0:55
全部回复
-
代码
Process proc = new Process(); proc.StartInfo = new ProcessStartInfo(); proc.StartInfo.FileName = "powercfg.exe"; proc.StartInfo.Arguments = @"/srumutil"; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.UseShellExecute = false; proc.Start(); string streamstr = proc.StandardOutput.ReadToEnd();
-
- 已建议为答案 Hart WangModerator 2016年10月17日 6:58
-
开发环境:win10 + vs2015
开发语言:C#
工程类型:windows 服务
运行环境:win10
问题描述:在C#代码中,运行powercfg /srumutil /output “C:\HwDataService\temp\srum.xml” /xml,运行时提示如下错误。
Error: SruUpdateStatus failed
Completed with status 5 (0x00000005)
Unable to perform operation. An unexpected error (0x1f) has occurred: A device attached to the system is not functioning.
猜测可能是由于没有提升到管理员权限导致的,尝试提示权限,但是没有成功(不确定是提升权限操作失败还是其他原因)。
- 已合并 ThankfulHeartModerator 2016年10月20日 6:57 同样的问题
-
Hi lean_law,
我能重新你的问题,我在台式机上面,也不能执行成功,效果是和你一样的。
@ThankfullHeart. 你能提供一下你的测试代码吗?
让我测试一下。我这边是和楼主一样的.
Hart
EDIT: 笔记本是可以执行成功的
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.
- 已编辑 Hart WangModerator 2016年10月17日 6:58
-
Hi,
如果你是用台式机测试?我能重现你的问题,因为台式机是没有办法运行这个设备的,直接用的是220v的电,
我也是测试好久,才发现这个问题。
笔记本是可以的,你是在笔记本上面测试的吗?
如果方便,你可以提供一下代码吗?
Best Regards,
Hart
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.
-
找到MSDN中的联接,不过参考意义不大
https://technet.microsoft.com/en-us/library/cc978749.aspx
我认为主要的还是磁盘访问权限的问题,试下其它的磁盘,或是先创建文件夹之后赋给权限,再试下命令能否运行
专注于.NET ERP/CRM开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms
-
-
你们用的是什么系统
win10的么
我Windows10上笔记本也试过,都可以的。
不过Windows7的SP1在我电脑上显示:参数无效:
ASP.NET Forum
StackOverFlow
FreeRice Donate
Issues to report- 已编辑 ThankfulHeartModerator 2016年10月18日 3:30
-
你是说你那边笔记本上可以正常work么
我这里也是在笔记本上coding的
我的笔记本Windows7(SP1),不可以,显示参数无效。
但是别人Windows10(专业版)那个貌似可以耶。具体看我上面回复的截图。
ASP.NET Forum
StackOverFlow
FreeRice Donate
Issues to report
-
笔记本设置成“高性能”,显示器,电源设置不关闭。
同时管理员模式运行VS。
在Win10的时候,使用MSDN账号登陆云账户。
ASP.NET Forum
StackOverFlow
FreeRice Donate
Issues to report
-
程序编译版本问题
- 已建议为答案 kelivnchgli 2016年10月19日 8:35
- 已标记为答案 ThankfulHeartModerator 2016年10月20日 6:54
- 已编辑 kelivnchgli 2016年10月24日 0:55
-
What is the bitness of your version of Windows 32 / 64?
If you are on a 64 bit system, you need to make your application 64 bit also.
If you are building it as AnyCPU, make sure the "Perfer 32 bit" checkbox is unchecked in the build properties.
I had the exact same problem until I built my application as a 64 bit (x64) one.
Hope this helps!
Russell
I skate to where the puck is going to be, not where it is. -Wayne Gretzky