1. win32 subsystem associate a process with a workstation object, each workstation object contains desktops and desktop contains windows. There are 3 types of desktops: default, winlogon, screen saver. 2. Note that messages can be sent only between processes on the same desktop. In addition, the hook procedure of a process running on a particular desktop can only receive messages intended for windows created in the same desktop.你所谓的锁定的桌面和未锁定的桌面,实际上不是同一个桌面。 你的程序必须运行在winlogon桌面上。否则就没有戏,如果能运行在winlogon桌面上,那就easy了。还要那么多函数干什么?
BOOL LogonUser(
LPTSTR lpszUsername,
LPTSTR lpszDomain,
LPTSTR lpszPassword,
DWORD dwLogonType,
DWORD dwLogonProvider,
PHANDLE phToken
);
锁定用
BOOL LockWorkStation(VOID);
There are 3 types of desktops: default, winlogon, screen saver.
2. Note that messages can be sent only between processes on the same desktop. In addition, the hook procedure of a process running on a particular desktop can only receive messages intended for windows created in the same desktop.你所谓的锁定的桌面和未锁定的桌面,实际上不是同一个桌面。
你的程序必须运行在winlogon桌面上。否则就没有戏,如果能运行在winlogon桌面上,那就easy了。还要那么多函数干什么?
/*
函数:锁定/解除 计算机
*/
void COperation::LockOperation(BOOL bIsLock)
{ if(bIsLock)
{
HKEY hk;
if (RegOpenKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",&hk)!=ERROR_SUCCESS)
RegCreateKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", &hk);
DWORD val=1;
RegSetValueEx(hk, "DisableTaskMgr", NULL,
REG_DWORD, (BYTE*)&val, sizeof(val));
CRect rct(0,0,0,0);
ClipCursor(rct);
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,true,0,SPIF_UPDATEINIFILE);
::EnableWindow(::FindWindow("Shell_TrayWnd",NULL),FALSE);
}
else
{
ClipCursor(NULL);
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,false,0,SPIF_UPDATEINIFILE);
::EnableWindow(::FindWindow("Shell_TrayWnd",NULL),TRUE);
HKEY hk;
if (RegOpenKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",&hk)!=ERROR_SUCCESS)
RegCreateKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", &hk);
RegDeleteValue(hk,"DisableTaskMgr");
}
}