AutoHotKey stop working after I started PowerShell as administrator - powershell

I use the AutoHotKey script to map some the keys under Windows 10 OS . It works very well except that I started Powershell as administrator. All the key mappings does not work after that as if autohotkey has been shut down. However things are all fine when I run PowerShell without administrator. Anyone knows how to fix that?

As Bluecakes said, just running the AutoHotKey as administrator will fix my problem.
You can either set the AutoHotKey to run always as administrator by right-click on AutoHotKey.exe and select property, in the compatiblity Tab , check the run this programme as administrator, or you can add a 'run as administrator' entry in the right-click menu of ahk scripts by editting the registry. Following this link:

Related

How to switch default run terminal for VSCode with Powershell

When I select RUN for my PowerShell script it executes in my "Integrated PowerShell Console" which is running PowerShell 7.x.
Some of my scripts use commands that are not available in PS7 (yet?) but works in PS5.
I have a second Terminal running in VSCode running PS5 and I can paste the script there and it works.
How can I switch the functionality of RUN (F5) to execute the script in my second terminal window?
Thank you Shivam Jha for the link.
I tried to map F5 to "workbench.action.terminal.runActiveFile: Run the active file in the terminal instance." and that works except it can only run code from files, not code just entered in the editor and not yet saved.
The solution then is to have F5 mapped to workbench.action.debug.run and CTRL+F5 mapped to workbench.action.terminal.runActiveFile.
This way I can have several PowerShell terminals active and use CTRL+F5 to run the active file in any of them.
This is just a guess, untested, but to me, it seems promising.
Open two instances of vscode, open the same folder in both, and open the two different terminals, one in each instance. If it still takes the default terminal even if you open another one in advance, try running in interactive window. Also check whether running just a selection (then just select the whole file) might influence the chosen output terminal.

How to build AHK scripts automatically on startup?

Each time I restart my computer, I have to rebuild all my AHK Scripts so the keyboard shortcuts will work.
For instance, I have a script that assigns Ctrl+j to set up an instance of the MEAN stack and open my web site. After restarting my computer, pressing ^j does nothing until I go into Sublime and ^b (Build). I could build from AHK, but I do a lot of work in Sublime, so it's easier to build there.
How can my AHK Scripts automatically build on startup?
What I've tried so far:
Looking to build a post startup, startup script: This Is concerned with using an AHK script to start many programs on starup. I use Windows' Task Manager > Startup to do this, thus has nothing to do with making. I want to not have to rebuild all my scripts after every restart.
Windows 10 - run script on windows startup problem: This assumes the start script is already written and implemented. However, it doesn't appear to give the script.
AutoHotKey FAQ: I eventually found a solution here, but it took a long time to dig through the questions so I figured I'd post a question anyway to help others who run into this.
Simply add a shortcut (don't need to be the actual file) of your script in the Windows 'Startup' folder.
Three ways to get there:
1- In Windows Explorer, go to %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup (for current user startup list) or %ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Startup (for every user startup list)
or
2- Open Windows' Run application (Windows + r) write shell:startup (current user) or shell:common startup (every user) in the edit field and click on the 'ok' button.
or
3- Start > Programs > Startup (old Windows versions)
In AutoHotKey you can access this folder with the Built-in Variables %A_Startup% (current user) or %A_StartupCommon% (every user)
To create the (current user) shortcut automatically from your script, use the following line:
FileCreateShortcut, %A_ScriptFullPath%, %A_Startup%\shortcutname.lnk
To do the same for all users, use this line instead:
FileCreateShortcut, %A_ScriptFullPath%, %A_StartupCommon%\shortcutname.lnk
(in the case of having a file with the same name in the folder, the file would be overwritten)
ps: Win10 blocks scripts in startup with AHK running as admin... read the comments of this post for extra info.
Run at startup in Windows 10:
Compile the script to *.exe
Put the shortcut of that exe in startup folder "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup"
That's all. Do NOT set it to run as admin. Programs in Win10 don't run at startup which are marked as run as admin.
Run Script as admin at Startup in Windows 10:
Go to ahk script and mark it run as admin.
Create the VBScript using a text editor
'put it in startup folder to run the mentioned ahk script at startup
Set WshShell = CreateObject("WScript.Shell" )
WshShell.Run """C:\Users\jerry\Downloads\scripts\some_script.ahk""", 0 'Must quote command if it has spaces; must escape quotes
Set WshShell = Nothing
Replace C:\Users\jerry\Downloads\scripts\some_script.ahk with the path to your script with extension and save it as .vbs.
Place this .vbs script at startup folder %appdata%\Microsoft\Windows\Start Menu\Programs\Startup
PS: My fav AHK scripts: https://gourav.io/blog/autohotkey-scripts-windows
Open note pad or any other text editor
write Start "" "C:\ahk\yourdirectory\yourahk.ahk"
press save as
navigate to %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup
name the filename anything.bat
As a Windows 7 user, I have limited experience with Windows 10. I have heard that W10 can be finicky with regard to running programs underground administratie or limited user. In W7, you just add the .AHK file link to the startup dir.
A simple solution without writing any code, using the Windows Task Scheduler, set the script to start when the user logs on. If it is set to system startup it will error because it is too early.
To allow the script to automate administrative programs without running as admin, here're the required steps:
When installing AHK, check the "Add 'Run with UI Access' to context menus" option.
After installation, find AutoHotkeyU64_UIA.exe on your disk.
Open the .ahk script's properties, change the "Open with" option to the AutoHotkeyU64_UIA.exe you just found.
Create a shortcut to this script.
Open %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup in the file explorer.
Move that shortcut to this folder.
And you're done.
How does it work?
The "Add 'Run with UI Access' to context menus" option provides a workaround for common UAC-related issues by allowing the script to automate administrative programs without running as admin.
Reference: Run with UI Access.
Open windows run (win+r) and type “shelll:startup”
Copy paste the ahk file into there
Close the folder
And that‘s all!

'Run As' box popping up when program runs on Windows XP

I have a program that was written in house years ago by someone who has now left. The program should run (minimized in the task bar) when I login which it does but before it can run I see the 'Run As' window below. The program isn't signed which may be the problem. I'm logged on as an administrator. Can anyone tell me why I see the 'Run As' box? It runs fine on Windows 7 but I need to add it to a Windows XP PC.
The program is set to run from the registry via HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run.
Many thanks
James
If you don't have any other need for the RunAs feature then you could first try stopping the service. open the run command and type services.msc then scroll down to "Secondary Logon" and disable this service.

Why does "F5 - Start Debugging" ignore breakpoints in PowerGUI?

I'm not sure if I'm being a bit thick, but I have a simple script with three lines:
$iis = 90000
$name = "somesite"
Write-Host("Values are: $iis and $name")
If I set a breakpoint on any of these lines and hit the play button (F5 - start debugging) the script runs but the breakpoints are ignored.
If I start the script with F11 (step into) I can step through just fine, however hitting F5 to run to the next breakpoint again causes PowerGUI to ignore the breakpoints
The script I'm working on is substantial and I don't really want to have to F11 through every line of code.
Why would this be?
I'm running PowerGUI 2.2.0.1358 on Windows 7 64-bit Ultimate Edition.
I tried both the x64 and x32 versions of the PowerGUI script editor without success.
I'm also running the PowerGUI Script Editor as Administrator (launched using right-click on PowerGUI Script Editor shortcut and Run As Administrator)
My PowerShell execution policy is set to Unrestricted.
It looks like there's a problem with PowerShell and square brackets in folder and filenames.
Both PowerGUI and PowerShell ISE won't hit breakpoint if the script being debugged resides in a folder with [ or ] in the name.
I had this problem when the script that I was running was on a remote file share.
E.g. \\serverA\FileShare\script.ps1.
When I saved the script as c:\script\script.ps1 it was ok.
Powershell apparently also has an issue with spaces in the folder names. It did not like 'My Documents' but did for 'Documents'. Once I switched my path in PowerShell within ISE the debugger worked again.

Why won't PowerShell ISE let me set breakpoints when running as Administrator?

Having failed to get PowerGUI to work properly I've fallen back on PowerShell ISE. However if I run this as Administrator it won't let me set any breakpoints.
If I launch as normal (my login is a member of Administrators) all is well but because I need to script some tasks that require full administrator rights this is no good.
I have saved the script as a proper file (i.e. it's not "untitled1.ps1") but no joy.
I'm running Windows 7 x64 Ultimate.
Strangely this doesn't seem to be a problem on my Windows 2008 R2 dev box (I'm logging in as user that is a member of Administrators then running PS ISE "As Administrator" and breakpoints are set and hit.
Any ideas why this would be?
I also faced the same issue, saving the file to a physical location enabled all debugging capabilities.
It looks like there's a problem with PowerShell and square brackets in folder and filenames.
Both PowerGUI and PowerShell ISE won't hit breakpoint if the script being debugged resides in a folder with [ or ] in the name.
I notice you're running x64. Is there any chance that you're running x64 ISE but have only set the execution policy away from restricted on x86 (or vice-versa).
I am using Visual Studio Code and in my case, I was missing the powershell extension.
Was facing the same issue because I had used other editor to make changes to the ps1 file. After opening the file with PowerShell ISE and clicking "Save" solved the issue for me.