October 30, 2012

Controlling Apps that Run as Admin

Filed under: Automation,Vista,Windows 7,Windows 8 — Marcus Tettmar @ 10:16 am

By now you are probably aware of UAC (User Account Control) that came along when Vista was released. And you probably know that to do anything like copy files to Windows\System32 or Program Files or do other administrative stuff you need to be running as Admin, or you’ll get the UAC prompt come up asking you for permission to continue. And when you continue the thing you launched is then running as admin.

For sensible reasons, Windows is designed so that an ordinary level process – i.e. an application that is running under a standard user account without administrative privileges (let’s call it an un-elevated application) is not allowed to manipulate, interact with or exchange information with an elevated process (one running with administrator privileges or “As Admin”).

Macro Scheduler runs “as invoker”. In other words it runs at the level of the user who starts it. In most cases, and by default, that means it is running without administrator privileges. Unless you have disabled UAC, or chosen to run Macro Scheduler as admin, or have set the Macro Scheduler shortcut properties to launch Macro Scheduler as admin, then Macro Scheduler will run as a standard user without administrative privileges.

Since a standard process is not allowed to manipulate an admin process, Macro Scheduler is not able, by default, to send keystrokes into windows belonging to processes running as admin.

Try it. Run Notepad as admin and then try the following simple macro in Macro Scheduler:

Setfocus>Untitled – Notepad
Send>Hello World

You’ll see nothing happen. The text “Hello world” will not arrive in Notepad.

Now close Notepad and run Notepad as normal and of course the script works.

So what do you do if you NEED to send keystrokes into an admin level window? Well, unless it is possible to run that process as an ordinary user you will need to also run Macro Scheduler as admin.

To run Macro Scheduler “elevated” as admin, right click on the Macro Scheduler shortcut and select “Run as Administrator”. If you have UAC enabled (the default) you’ll see the UAC confirmation box pop up to make sure you’re happy to continue. Ok that and now Macro Scheduler is running as admin.

Now try running Notepad as admin again and you’ll find our little macro works.

Some legacy applications written before Vista came along were developed assuming the user had administrative privileges, which was common in the days of XP. This was poor practice but widely done. A common transgression was that they would write their settings and files to the Program Folder. In order to run these applications under Vista or later they would therefore have to be run as Admin, unless there was any way to force them to write data to another more sensible location. Sadly there are still applications that do this, especially older ones that are no longer maintained. Since the only way to use such legacy apps on Vista/Win7/Win8 is to disable UAC or set them to run as admin and put up with the UAC prompt, if you need to automate them you’re going to have to also run Macro Scheduler (or your compiled macro) as admin.

Short version: If you wish to automate an elevated application (one that runs as admin), Macro Scheduler or your compiled macro, also needs to be running elevated.

August 24, 2011

New Building Windows 8 Blog

Filed under: Windows 8 — Marcus Tettmar @ 11:38 am

Microsoft have recently launched a new blog called “Building Windows 8” written by engineers on the Microsoft Windows 8 team and providing a means of dialog between themselves and the rest of us. It already features some interesting insights into how the new version of Windows will differ from existing versions. Well worth keeping an eye on.

Building Windows 8

Here’s their first Windows 8 preview video from June.