4
0
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.
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 – 2012-11-08T18:07:26.870Don'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 – 2012-11-08T18:11:43.630I 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 – 2012-11-08T18:59:45.343I 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 – 2012-11-08T19:14:13.207
hack-ish... but this might work for you: http://www.shulerent.com/2012/03/07/getting-a-poorly-designed-clickonce-application-to-run-as-administrator/
– TheCompWiz – 2012-11-08T19:57:34.573Ok, I tried using the /IT switch when creating the task from the command line again and it worked this time :) Not sure why it didn't before. As an added bonus, if you also use the /V1 switch it automatically sets the Task to "Run with highest privileges" and sets the Start In directory to the directory that the executing program is in. Here is an example of the command I used to create the task from the command prompt:
schtasks /Create /RU "[Domain]\[MyUsername]" /SC ONLOGON /TN "Launch AHK Command Picker" /TR "D:\AHKStuff\AHKCommandPicker.ahk" /IT /V1 – deadlydog – 2012-11-08T20:06:44.600
Glad to hear you got it working! – TheCompWiz – 2012-11-08T20:18:24.047