各位大侠紧急求助????!!!在NT service程序中调用mouse_event模拟鼠标按键不起作用?

yyc_csdn 2003-01-28 11:27:17
各位大侠紧急求助!!!
win2000下怎么模拟发送Ctrl+Alt+del?
为什么在NT service程序中调用mouse_event模拟鼠标按键不起作用?
为什么我在后台程序中调用GetCursor函数总是返回IDC_WAIT光标啊?
...全文
85 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
88dd 2003-02-27
  • 打赏
  • 举报
回复
我写了一个函数


BOOL ChangeServiceDesktop(void)
{
HDESK hdeskCurrent;
HDESK hdesk;
HWINSTA hwinstaCurrent;
HWINSTA hwinsta; //
// Save the current Window station
//
hwinstaCurrent = GetProcessWindowStation();
if (hwinstaCurrent == NULL)
return FALSE; //
// Save the current desktop
//
hdeskCurrent = GetThreadDesktop(GetCurrentThreadId());
if (hdeskCurrent == NULL)
return FALSE; //
// Obtain a handle to WinSta0 - service must be running
// in the LocalSystem account
//
hwinsta = OpenWindowStation(_T("winsta0"), FALSE,
WINSTA_ACCESSCLIPBOARD |
WINSTA_ACCESSGLOBALATOMS |
WINSTA_CREATEDESKTOP |
WINSTA_ENUMDESKTOPS |
WINSTA_ENUMERATE |
WINSTA_EXITWINDOWS |
WINSTA_READATTRIBUTES |
WINSTA_READSCREEN |
WINSTA_WRITEATTRIBUTES);
if (hwinsta == NULL)
return FALSE; //
// Set the windowstation to be winsta0
//
if (!SetProcessWindowStation(hwinsta))
return FALSE; //
// Get the default desktop on winsta0
//
hdesk = OpenDesktop(_T("default"), 0, FALSE,
DESKTOP_CREATEMENU |
DESKTOP_CREATEWINDOW |
DESKTOP_ENUMERATE |
DESKTOP_HOOKCONTROL |
DESKTOP_JOURNALPLAYBACK |
DESKTOP_JOURNALRECORD |
DESKTOP_READOBJECTS |
DESKTOP_SWITCHDESKTOP |
DESKTOP_WRITEOBJECTS);
if (hdesk == NULL)
return FALSE;
// Set the desktop to be "default"
//
if (!SetThreadDesktop(hdesk))
return FALSE;
// Do a message box
//
/*
MessageBox(NULL, _T("MB_OK"), _T("test_interact"), MB_OK); //
// Reset the Window station and desktop
//
if (!SetProcessWindowStation(hwinstaCurrent))
return FALSE;
if (!SetThreadDesktop(hdeskCurrent))
return FALSE; //
// Close the windowstation and desktop handles
//
if (!CloseWindowStation(hwinsta))
return FALSE;
if (!CloseDesktop(hdesk))
return FALSE;
*/
return TRUE;
}

在你的servicemain函数中调用这个函数试试
void WINAPI ServiceMain(DWORD dwArgc, PTSTR* pszArgv)
{
...
ChangeServiceDesktop();
...
}
Rigel 2003-01-28
  • 打赏
  • 举报
回复
Win2000下模拟输入(鼠标、键盘)用SendInput函数

UINT SendInput(
UINT nInputs, // count of input events
LPINPUT pInputs, // array of input events
int cbSize // size of structure
);
yjf7888 2003-01-28
  • 打赏
  • 举报
回复
不懂,不过要模拟Ctrl+Alt+del的话,查查Winlogon和gina吧。
yyc_csdn 2003-01-28
  • 打赏
  • 举报
回复
mouse_event在2000下也起作用,只不过在后台服务中(即NT service)不起作用罢了,不知是为什么?windows服务和不同Application好像不太一样,例如SetCursorPos在Apllication中有效,在service中就无效,必须使用OpenWindowStation和SetProcessWindowStation API才行,所以我想在service中使用mouse_event是不是要设置什么才行?请赐教!!

2,640

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 硬件/系统
社区管理员
  • 硬件/系统社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧