我们正在使用C#.Net Compact Edition 3.5和Windows Mobile 6.1,并且不太熟悉C ++或Windows API调用。我们需要以编程方式将电池闲置/可疑时间从其设置的任何时间(通常默认为3/5分钟)更改为15分钟。我在网上找到了一些例子,但到目前为止,它们都没有工作,或者我不知道如何/无法找到如何实现它们,因为它们是用C ++编写的,或者没有用于在C#中运行的解释或上下文。
int test = SystemParametersInfo(SPI_SETBATTERYIDLETIMEOUT, 15, null, 0); //15 seconds, to test it actually working
//test return 0
如何从C#中的.Net CE 3.5更改Windows Mobile 6.1中的电池超时?
由于
编辑:请求此应用程序的客户端专门请求了此行为。他们希望在应用程序执行期间有更长的超时,并且在未运行时需要系统默认超时。
答案 0 :(得分:2)
我同意Hans的观点,这可能是通过改变他们的设备而不询问来惹恼最终用户的最好方法。这就是说,我已经为一个客户做了类似的事情,希望所有设备都附带有简洁的设置。而不是使用更改的列表来使安装程序更快。
我相信您所关注的设置保存在
的注册表设置中\HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Power\Timeouts
然后您可以通过框架
更改此内容RegistryKey singleKey =
registryKey.OpenSubKey(
"\HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Power\Timeouts", true);
singleKey.SetValue("BattSystemIdle", 600);
singleKey.Close();
我不是100%确定您使用的是哪个注册表项,但您可以使用优秀的Breaksoft Mobile注册表编辑器找到您需要的确切密钥。通过改变你的设备并在键盘改变时保持关注,你应该快速找到你想要的设置。
编辑:死链接 - Breaksoft移动注册表编辑器
使用下面评论中提供的替代方案
答案 1 :(得分:1)
我无法在VS 2008中的Windows Mobile 6项目中获得流畅的精确方法。首先,注册表路径中的\被识别为控制代码前缀,其次是 RegistryKey singleKey line在构建期间导致错误。下面的代码确实有效:
var localMachine = Registry.LocalMachine;
var subKey = localMachine.OpenSubKey(@"\System\CurrentControlSet\Control\Power\Timeouts", true);
subKey.SetValue("BattSuspendTimeout", 600);
仍然需要重启才能生效。
答案 2 :(得分:0)
对于SystemParametersInfo函数,您需要使用C#中的dllimport命令对其进行P / Invoke。 pinvoke.net有一个在Windows中执行此操作的示例。要将其移植到Windows Mobile,只需将引用从user32.dll
更改为coredll.dll
即可。
http://www.pinvoke.net/default.aspx/user32.systemparametersinfo
[DllImport("coredll.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SystemParametersInfo(uint uiAction, uint uiParam, IntPtr pvParam, SPIF fWinIni);
还要考虑"What if two programs did this"?
-PaulH