0

我们在 Windows Mobile 6.1 中使用 C# .Net Compact Edition 3.5,对 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 中的电池超时?

谢谢

编辑:请求此应用程序的客户端已专门请求此行为。他们希望在应用程序执行期间有更长的超时时间,并且在未运行时需要系统默认超时时间。

4

3 回答 3

1

我同意 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 移动注册表编辑器来找到您需要的确切键。通过更改您的设备并在按键更改时密切注意它们,您应该可以快速找到您想要的设置。

编辑:死链接 - Breaksoft 移动注册表编辑器

使用下面评论中提供的替代方案

MSDN - 电源管理超时

于 2011-06-30T16:20:59.323 回答
1

我无法在 VS 2008 中的 Windows Mobile 6 项目中获得流利的确切方法。首先,注册表路径中的 \ 被识别为控制代码前缀,其次RegistryKey singleKey行在构建过程中导致错误。下面的代码确实有效:

var localMachine = Registry.LocalMachine;
var subKey = localMachine.OpenSubKey(@"\System\CurrentControlSet\Control\Power\Timeouts", true);
subKey.SetValue("BattSuspendTimeout", 600);

不过还是需要重启才能生效。

于 2014-12-22T12:06:24.867 回答
0

对于SystemParametersInfo函数,您需要使用 C# 中的 dllimport 命令对其进行 P/Invoke。pinvoke.net 有一个在 Windows 中执行此操作的示例。要将其移植到 Windows Mobile,只需将引用从 更改user32.dllcoredll.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);

还要考虑“如果两个程序都这样做了怎么办”

-保罗H

于 2011-07-01T16:29:40.423 回答