Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I love AutoHotkey (AHK) and use it to launch all of my apps using AHK Command Picker. In order to get around restrictions put in place by the Windows 8 UAC I require my AHK scripts to run as administrator. Now, whether running the script as admin or not, if I manually start my AHK script it is able to launch my ClickOnce apps. This is an example of how I am launching the ClickOnce app from AHK:

Run, C:\SomeFolder\MyClickOnceApp.appref-ms

The problem I'm having occurs when I use the Task Scheduler to automatically start my AHK script when I log into Windows. When I do this, if I try and launch a ClickOnce app with my script then nothing happens. I can close the script and manually run the Scheduled Task to restart it, but it still won't work. If I then close the script and launch it manually (by double clicking my .ahk file), then everything works fine and I can launch my ClickOnce apps. If I then close the script again, and manually run the Scheduled Task to restart it again, then everything still works fine and I can launch my ClickOnce apps.

So the problem doesn't seem to be caused by the Task Scheduler launching the script, but that for some reason the script needs to be manually ran at least once first before it will be able to open ClickOnce apps.

I'm not sure what the difference is between me manually double clicking the .ahk file or by having a Scheduled Task launch it for me (the scheduled task is set to run as my user (which is an admin), and has "Run with highest privileges" checked). But for some reason me manually double clicking the file seems to change some setting so that the AHK script runs differently until the next time the PC is restarted. The one difference that I can think of is that in the Scheduled Task I have the "Start in (optional)" field set to the folder containing the AHK script (e.g. C:\SomeFolder), whereas when I manually run the .ahk file by double clicking it I don't know if this is set.

Any suggestions are greatly appreciated. Thanks.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

The problem is that the task-scheduler does not run in the same user-session as the currently logged in user. (Yes, it may be running as the same user... but the same user can have multiple sessions in Windows, not all of which are started within a GUI) What happens is that when the task-scheduler starts applications but there is no place for it to display the GUI. It is not running in the same session as the logged-on user.

share|improve this answer
    
Hmmm, I assumed that because I have my Scheduled Task to launch "at log on", that it would run in my same session. Your explanation does make sense though, and would also explain why TrayIt! is not able to hook into any windows that I launch with my AHK script. So do you have any ideas on what I can do to get the Scheduled Task to start in MY session? Thanks! –  deadlydog Nov 8 '12 at 18:07
    
Don't use scheduled tasks. Put a shortcut in the users' startup folder, or specify an entry in the HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run key in the registry. –  TheCompWiz Nov 8 '12 at 18:11
    
I originally tried using the startup folder, but neither of these options work for me because I need my AHK script to Run As Admin. If I tell the shortcut in the startup folder to Run As Admin, it simply doesn't get launched (Windows 8 UAC blocks it). This is why I need to use the Task Scheduler, because it has the "Run with highest privileges" option. I found this post which says to create the scheduled task from the command line using the /IT parameter, but this doesn't seem to work either –  deadlydog Nov 8 '12 at 18:59
    
I also just tried removing the "Run As Administrator" option from the startup folder link and instead put it directly on the Autohotkey.exe executable, but had the same result where the script doesn't get launched at startup. Right now it looks like my best option is to figure out how to get the Task Scheduler to run the Task in my current user session. –  deadlydog Nov 8 '12 at 19:14
    
hack-ish... but this might work for you: shulerent.com/2012/03/07/… –  TheCompWiz Nov 8 '12 at 19:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.