Mikko Noromaa
2003-10-08 22:50:34 UTC
Hi,
I am trying to create a Windows XP service that launches an application in a
private (hidden) desktop, and sends some keystrokes to it.
So far I have gotten this to work with the following code:
HWINSTA hWinsta=OpenWindowStation(_T("WinSta0"), FALSE, MAXIMUM_ALLOWED);
SetProcessWindowStation (hWinsta);
HDESK hDesk=OpenDesktop(_T("Default"), 0, FALSE, MAXIMUM_ALLOWED);
SetThreadDesktop (hDesk);
si.cb=sizeof(si);
si.lpDesktop=_T("WinSta0\\Default");
retval=CreateProcess(NULL, _T("D:\\Windows\\Notepad.exe"), NULL, NULL,
FALSE, 0, NULL, NULL, &si, &pi);
Sleep (2000);
// ...
// Use SendInput() to send keystrokes that write some text, then do
File/Save As, c:\a.txt and enter.
// ...
Sleep (2000);
TerminateProcess (pi.hProcess, 0);
The above version works fine from the service. Notepad starts on my active
desktop, SendInput() sends the keystrokes to it successfully, and Notepad
saves the new file to c:\a.txt.
Next I tried creating my own window station and desktop:
HWINSTA hWinsta=CreateWindowStation(_T("NsWinSta"), 0, GENERIC_ALL, NULL);
// ...
HDESK hDesk=CreateDesktop(_T("NsDesktop"), NULL, NULL, 0, GENERIC_ALL,
NULL);
// ...
si.lpDesktop=_T("NsWinSta\\NsDesktop");
// ...
All other code is the same as in the first example. When I run this code
from the service, I can see a new Notepad process being created in Task
Manager. The Notepad window does not appear on my desktop, as expected.
However, the SendInput() calls fail with error code 5 (access denied).
Is it possible to use SendInput() to send input to other desktops than the
active one? Do I need to enable some additional rights beyond GENERIC_ALL
for this to work?
--
Mikko Noromaa (***@excelsql.com)
- SQL in Excel, check out ExcelSQL! - see http://www.excelsql.com -
I am trying to create a Windows XP service that launches an application in a
private (hidden) desktop, and sends some keystrokes to it.
So far I have gotten this to work with the following code:
HWINSTA hWinsta=OpenWindowStation(_T("WinSta0"), FALSE, MAXIMUM_ALLOWED);
SetProcessWindowStation (hWinsta);
HDESK hDesk=OpenDesktop(_T("Default"), 0, FALSE, MAXIMUM_ALLOWED);
SetThreadDesktop (hDesk);
si.cb=sizeof(si);
si.lpDesktop=_T("WinSta0\\Default");
retval=CreateProcess(NULL, _T("D:\\Windows\\Notepad.exe"), NULL, NULL,
FALSE, 0, NULL, NULL, &si, &pi);
Sleep (2000);
// ...
// Use SendInput() to send keystrokes that write some text, then do
File/Save As, c:\a.txt and enter.
// ...
Sleep (2000);
TerminateProcess (pi.hProcess, 0);
The above version works fine from the service. Notepad starts on my active
desktop, SendInput() sends the keystrokes to it successfully, and Notepad
saves the new file to c:\a.txt.
Next I tried creating my own window station and desktop:
HWINSTA hWinsta=CreateWindowStation(_T("NsWinSta"), 0, GENERIC_ALL, NULL);
// ...
HDESK hDesk=CreateDesktop(_T("NsDesktop"), NULL, NULL, 0, GENERIC_ALL,
NULL);
// ...
si.lpDesktop=_T("NsWinSta\\NsDesktop");
// ...
All other code is the same as in the first example. When I run this code
from the service, I can see a new Notepad process being created in Task
Manager. The Notepad window does not appear on my desktop, as expected.
However, the SendInput() calls fail with error code 5 (access denied).
Is it possible to use SendInput() to send input to other desktops than the
active one? Do I need to enable some additional rights beyond GENERIC_ALL
for this to work?
--
Mikko Noromaa (***@excelsql.com)
- SQL in Excel, check out ExcelSQL! - see http://www.excelsql.com -