如题:
WDM设备驱动程序中能修改系统的电源状态吗?如何修改?
WDM设备驱动程序中能修改系统的电源状态吗?如何修改?
解决方案 »
- VC 如何在资源管理器中设计窗口时设计它运行时的大小
- dll调试----在delphi中调用VC++编写的dll,如何调试能进入到dll中函数
- IWebBrowser2如何指定浏览器
- 奇怪现象 vc显示pdf文件
- 【版务】网友 guileen(松风抚琴) 严重灌水的问题
- 如何在程序初始化过程中加入一些图片或其它一些资源???????
- 为什么我的DBGrid中只能写一行?再线等待!!
- 怎样在程序中把从串口读取的数据转换为键盘消息发送给Word等文字编辑器?
- 请各位老师为我解答一下_hread函数中参数的意思。
- 怎样得到字符串长度?对不起分不多了。
- 简单问题,DDX, DDE, OLE都应用在哪里?性能怎么样?放分如流水
- 关于CDatabase类用什么函数读取数据库中的内容
ZwSetSystemPowerState sets the power state of the system.NTSYSAPI
NTSTATUS
NTAPI
ZwSetSystemPowerState(
IN POWER_ACTION SystemAction,
IN SYSTEM_POWER_STATE MinSystemState,
IN ULONG Flags
);
Parameters
SystemAction
Specifies the power action to perform.The permitted values are drawn from the enumeration POWER_ACTION:typedef enum _POWER_ACTION {
PowerActionNone,
PowerActionReserved,
PowerActionSleep,
PowerActionHibernate,
PowerActionShutdown,
PowerActionShutdownReset,
PowerActionShutdownOff
} POWER_ACTION, *PPOWER_ACTION; MinSystemState
Specifies the minimum power state to enter as a result of performing the action. The permitted values are drawn from the enumeration SYSTEM_POWER_STATE:typedef enum _SYSTEM_POWER_STATE {
PowerSystemUnspecified = 0,
PowerSystemWorking,
PowerSystemSleeping1,
PowerSystemSleeping2,
PowerSystemSleeping3,
PowerSystemHibernate,
PowerSystemShutdown
} SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE; Flags
Qualifies the SystemAction. Defined values include:POWER_ACTION_QUERY_ALLOWED
POWER_ACTION_UI_ALLOWED
POWER_ACTION_OVERRIDE_APPS
POWER_ACTION_LOCK_CONSOLE
POWER_ACTION_DISABLE_WAKES
POWER_ACTION_CRITICALReturn Value
Returns STATUS_SUCCESS or an error status, such as STATUS_PRIVILEGE_NOT_HELD, STATUS_ALREADY_COMMITTED, or STATUS_CANCELLED.
最后一个参数也可以换成
POWER_ACTION_QUERY_ALLOWED,这样会向应用程序进行询问,如果有应用程序不允许进入睡眠状态,调用将失败。休眠的话ZwSetPowerAction (PowerActionHibernate, PowerSystemHibernate, 0);
最后一个参数也可以换成
POWER_ACTION_QUERY_ALLOWED,这样会向应用程序进行询问,如果有应用程序不允许进入休眠状态,调用将失败。不使用ZwSetPowerAction的话,也可以用另外一个Native API
ZwInitiatePowerAction,这个API仅比上一个多一个参数,在最后。前三个参数完全一样。最后一个参数传0就可以了。win32 API中有一个SetSystemPowerState,它调用的是ZwInitiatePowerAction。你需要包含的ddk头文件是
ntpoapi.h可能需要将函数名的前缀Zw换成Nt
ZwSetPowerAction换成NtSetPowerAction
ZwInitiatePowerAction换成NtInitiatePowerAction
ZwSetPowerAction (PowerActionSleep, PowerSystemSleeping1, 0);休眠
ZwSetPowerAction (PowerActionHibernate, PowerSystemHibernate, 0);
可是提示这个没被定义,于是我在NTDDK查找包含NtSetPowerAction和ZwSetPowerAction都没找到啊。
NTSYSCALLAPI // only called by WinLogon
NTSTATUS
NTAPI
NtSetSystemPowerState(
IN POWER_ACTION SystemAction,
IN SYSTEM_POWER_STATE MinSystemState,
IN ULONG Flags // POWER_ACTION_xxx flags
);
NtSetSystemPowerState (PowerActionSleep, PowerSystemSleeping1, 0);
后,BUILD出现
unresolved external symbol _imp_NtSetSystemPowerState@12
#pragma comment(lib,"ntdll.lib")
还是不行
#pragma comment(lib,"ntdll.lib")
这个在BUILD的时候会不会进行检测,我把
#pragma comment(lib,"ntdll.lib")故意改成#pragma comment(lib,"ntdllAAAA.lib"),实际上没有ntdllAAAA.lib,可是BUILD的时候还是只出现“unresolved external symbol _imp_NtSetSystemPowerState@12”这个错误??不明白这是怎么回事。
当***.lib不存在时是不提示错误的你最好把ntdll.lib拷贝到当前目录来,这样能保证找到ntdll.lib
在BUILD的时候,还是出现
unresolved external symbol _imp_NtSetSystemPowerState@12
以前我好象也碰到过
我记得是我需要加上ntoskrnl.lib我用#pragma comment (lib, "...")也不成不过不起作用,你看看能不能在source文件里面加呢
TARGETLIBS=$(BASEDIR)\lib\*\free\ntdll.lib后,BUILD通过,我先测试一下,看看行不行。
POWER_STATE PowerState = Irpstack->Parameters.Power.State;
if (PowerState.SystemState==PowerSystemHibernate)
{
NtSetSystemPowerState (PowerActionSleep, PowerSystemSleeping1, 0);
}
可是当我执行休眠时,NtSetSystemPowerState不起作用,机器继续进入休眠啊
请问DebugPrint怎么用啊?以前没用过。
DebugPrint要什么支持,要怎么用?以前没用过啊。
Major Code
IRP_MJ_POWERWhen Sent
The Power Manager or a device power policy owner sends this IRP to determine whether it can change the system or device power state, typically to go to sleep. A driver must call PoRequestPowerIrp to allocate and send this IRP. The Power Manager sends this IRP at IRQL = PASSIVE_LEVEL to device stacks that set the DO_POWER_PAGABLE flag in the PDO. The Power Manager can send the IRP at IRQL = DISPATCH_LEVEL if the DO_POWER_INRUSH flag is set. Such drivers cannot directly or indirectly access any paged code or data.Input
Parameters.Power.Type specifies the type of power state being set, either SystemPowerState or DevicePowerState. Parameters.Power.State specifies the power state itself, as follows: * If Parameters.Power.Type is SystemPowerState, the value is an enumerator of the SYSTEM_POWER_STATE type.
* If Parameters.Power.Type is DevicePowerState, the value is an enumerator of the DEVICE_POWER_STATE type.
Parameters.Power.ShutdownType specifies additional information about the requested transition. Possible values are enumerators of the POWER_ACTION type.Output
None.I/O Status Block
A driver sets Irp->IoStatus.Status to STATUS_SUCCESS to indicate that the device can enter the requested state. A driver sets any appropriate failure status to indicate that it cannot enter the requested state.
--------------------------------------------------------------------------
前面有了啊I/O Status Block
A driver sets Irp->IoStatus.Status to STATUS_SUCCESS to indicate that the device can enter the requested state. A driver sets any appropriate failure status to indicate that it cannot enter the requested state.
另外,如果对休眠不进行任何处理,当选择休眠时,系统会提示不能进入休眠,我想让系统不提示禁止休眠,而把休眠的动作转成待机处理,这样行不行?----------------------------------------------------------
这好象不行 :(没查到
1.调用PoStartNextPowerIrp,表明其已准备处理下一个电源IRP。
2.设置Irp->IoStatus.Status为失效状态,并且调用IoCompleteRequest,指定IO_NO_INCREMENT。不把IRP传递到更下面的设备栈中。
3.调用IoReleaseRemoveLock,释放以前获取的锁。
4.从其DispatchPower例程中返回一个失效状态。 这里面的第3、4点不知道该怎么做?Irp->IoStatus.Status为失效状态,失效状态的值为多少,我随便设了一个11,不知道行不行?