WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Sending Keystrokes

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

SendKeys from a Service


Question:

SendKeysTo() works fine in 'interactive mode', but it fails when the compiled exe is called by the windows service.
app = "~Notepad"
Run("notepad.exe", "");
if WinShow(app)then Display(3, "Info", "Found Notepad...")
SendKeysTo(app, "!{f4}") ;close it

Answer:

This comes down to an issue of "desktops", "windowstations" and the permissions applied to them.

There is a desktop named "default" and it is on this desktop that all interactive applications run. There are other desktops, too, such as the one used by WinLogon and the one used when a screensaver is running. The keyboard & mouse can only be associated with one desktop at any given time. This means that while the "default" desktop is not the current desktop, no keyboard or mouse activities can occur on the "default" desktop, and that includes simulated keyboard & mouse input that is performed via WinBatch.

Now, to add to the issue, services that run under specific user accounts each have their own separate desktops. This means that those services cannot interact with the "default" desktop and thus cannot perform keyboard & mouse manipulation of applications that are on the "default" desktop. Only a service that runs under the Local System account can be associated with the "default" desktop for purposes of interacting with apps on the "default" desktop, but even in that situation they are still limited by the occurrences of the "default" desktop not being the current desktop [e.g. locked workstation, screensaver is active].


Article ID:   W16716
File Created: 2005:02:18:12:21:58
Last Updated: 2005:02:18:12:21:58