积极答复者
WH_JOURNALRECORD 钩子 无法安装。。。。。

问题
答案
-
这个权限提升是需要代码的,具体提升方法可以参考关机的权限提升方法:
#include <windows.h> #pragma comment(lib, "user32.lib") #pragma comment(lib, "advapi32.lib") BOOL MySystemShutdown() { HANDLE hToken; TOKEN_PRIVILEGES tkp; // Get a token for this process. if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) return( FALSE ); // Get the LUID for the shutdown privilege. LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); tkp.PrivilegeCount = 1; // one privilege to set tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; // Get the shutdown privilege for this process. AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0); if (GetLastError() != ERROR_SUCCESS) return FALSE; // Shut down the system and force all applications to close. if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, SHTDN_REASON_MAJOR_OPERATINGSYSTEM | SHTDN_REASON_MINOR_UPGRADE | SHTDN_REASON_FLAG_PLANNED)) return FALSE; //shutdown was successful return TRUE; }
- 已标记为答案 Kira Qian 2010年6月15日 5:38
全部回复
-
没有提升权限的话不行。需要以管理员身份运行。你也可以在应用程序的清单文件中加入<requestedExecutionLevel level="requireAdministrator" uiAccess="true"/>
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP -
这个权限提升是需要代码的,具体提升方法可以参考关机的权限提升方法:
#include <windows.h> #pragma comment(lib, "user32.lib") #pragma comment(lib, "advapi32.lib") BOOL MySystemShutdown() { HANDLE hToken; TOKEN_PRIVILEGES tkp; // Get a token for this process. if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) return( FALSE ); // Get the LUID for the shutdown privilege. LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); tkp.PrivilegeCount = 1; // one privilege to set tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; // Get the shutdown privilege for this process. AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0); if (GetLastError() != ERROR_SUCCESS) return FALSE; // Shut down the system and force all applications to close. if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, SHTDN_REASON_MAJOR_OPERATINGSYSTEM | SHTDN_REASON_MINOR_UPGRADE | SHTDN_REASON_FLAG_PLANNED)) return FALSE; //shutdown was successful return TRUE; }
- 已标记为答案 Kira Qian 2010年6月15日 5:38
-
你好,
这个问题我可以重现。我是在Win7 x64系统下重现的,其他XP/2003没有问题。在Win7下即使run as administrator了还是有这个问题,LastError 5是表示访问拒绝。Win7下面有些问题是比较难处理的。我推荐你下载一个sample,这个sample在win7 x64下运行也是没问题的。
http://1code.codeplex.com/
里面有一个CPPHook的sample。你可以先参考一下,希望对你有帮助。
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!