【发布时间】:2010-04-12 12:25:07
【问题描述】:
我正在尝试使用脚本来控制我的电源选项,因为 XP 没有为您提供更改 CPU 频率选项的直观方法。到目前为止,这是我的脚本:
meh = `cmd.exe /C POWERCFG.EXE /QUERY Portable/Laptop`
puts ""
puts meh
case input
when 1 then system('cmd.exe /C POWERCFG.EXE /CHANGE Portable/Laptop /processor-throttle-ac NONE')
when 2 then system('cmd.exe /C POWERCFG.EXE /CHANGE Portable/Laptop /processor-throttle-ac ADAPTIVE')
when 3 then `cmd.exe /C POWERCFG.EXE /CHANGE Portable/Laptop /processor-throttle-ac CONSTANT`
end
问题在于这些更改根本没有发生。如果我直接在 cmd.exe 提示符中运行相同的命令,它们就可以工作。这很奇怪,但是在最初的 powercfg 查询之后没有任何效果。我觉得我错过了一些非常明显的东西。
我怎样才能让上面的脚本正确运行?
更新: C:\shoe>ruby freq.rb
Field Description Value
----------------- -----
Name Portable/Laptop
Numerical ID 1
Turn off monitor (AC) After 15 mins
Turn off monitor (DC) After 5 mins
Turn off hard disks (AC) After 30 mins
Turn off hard disks (DC) After 5 mins
System standby (AC) After 20 mins
System standby (DC) After 5 mins
System hibernates (AC) Not Supported
System hibernates (DC) Not Supported
Processor Throttle (AC) ADAPTIVE
Processor Throttle (DC) ADAPTIVE
Enter a number to switch portable/laptop profile to that mode.
1 - None (HIGHEST FREQUENCY MODE)
2 - Adaptive (SPEEDSTEP)
3 - Constant (LOWEST FREQUENCY MODE)
#SCRIPT IS CANCELED HERE. I've already tested the methods to change powercfg options, and they work, but they only apply to Ruby's instance of powercfg.
C:\shoe>powercfg /QUERY 1 /NUMERICAL
Field Description Value
----------------- -----
Name Portable/Laptop
Numerical ID 1
Turn off monitor (AC) After 15 mins
Turn off monitor (DC) After 5 mins
Turn off hard disks (AC) After 30 mins
Turn off hard disks (DC) After 5 mins
System standby (AC) After 20 mins
System standby (DC) After 5 mins
System hibernates (AC) Not Supported
System hibernates (DC) Not Supported
Processor Throttle (AC) CONSTANT
Processor Throttle (DC) ADAPTIVE
【问题讨论】:
-
是否需要每次都执行
cmd.exe(从而创建一个新的shell)?
标签: windows ruby command-line