Hotkey script to change between 2 .reg files.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Hunter2865
Posts: 1
Joined: 18 Mar 2018, 00:25

Hotkey script to change between 2 .reg files.

18 Mar 2018, 00:40

Hello. I currently am trying to create a script in order to use a hotkey to change between 2 .reg files. I have successfully done this with:

Code: Select all

^+1:: ; Ctrl+Shift+1
Run C:\Users\Hunter\Documents\LineInCeiling.reg
return

^+2:: ; Ctrl+Shift+2
Run C:\Users\Hunter\Documents\LineInDefault.reg
return
However, there is a series of 3 popups that come up everytime I execute a hotkey. I have tried using /s but always get some sort of error.
I just need help so that when I press the hotkey, it does what I need it to do with no further action required. Thanks in advance for any help!
Let me know if I left out any information that is required.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Hotkey script to change between 2 .reg files.

18 Mar 2018, 02:02

Those reg files are used to (re)write some settings at the registry. It should be possible to use AHK's RegWrite-command instead. Have a try if the popups are still showing.
RickC
Posts: 299
Joined: 27 Oct 2013, 08:32

Re: Hotkey script to change between 2 .reg files.

19 Mar 2018, 11:56

The popups are 1) a User Access Control (UAC) prompt asking "Do you want to allow this app to make changes to your device"; 2) a Registry Editor prompt asking "Are you sure you want to continue?" and; 3) a Registry Editor message informing you whether the 'merge' succeeded. This is because just 'running' a REG file invokes the Registry Editor by default.

As BoBo suggests, using AHK's RegWrite is usually the best way to go.

Note:

1. You need to be aware of the effect of using a 32-bit version of AHK with a 64-bit OS and vice versa. See SetRegView for more info.

2. You will have to elevate the command (i.e. invoke a UAC) if the .REG file to be imported writes to the 'machine' hive (HKLM) rather than the 'user' hive (HKCU).

3. You may need to restart Explorer, sign out/sign in or restart for some registry changes to take effect, especially if they are machine-wide.

For example, the following DOESN'T need to run elevated because it's writing to HKCU, DOES need SetRegView 'cos I'm using the 32-bit version of AHK in a 64-bit environment and the registry change DOESN'T take effect until Explorer is restarted:

Code: Select all

; Taskbar - Show/hide People icon (1=Enable/Show / 0=Disable/Hide)
SetRegView, 64
RegWrite, REG_DWORD, HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People, PeopleBand, 0
SetRegView, Default

; Restart Explorer
psScript =
(
 Stop-Process -ProcessName explorer -Force
)
Run PowerShell.exe -Command %psScript%,, hide
If, however, the .REG files are lengthy/complicated then an alternative is to use AHK to run the commandline reg.exe and pass the .REG file as an import parameter. This will avoid the confirmation prompts, including overwriting existing values if you use the /f (force) switch. You can read more about the use of reg.exe here: https://ss64.com/nt/reg.html.

You can run reg.exe from AHK using comspec (and its /hide switch) to hide what's happening but you may still need to use elevation.

Hope this helps...

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], TAC109 and 260 guests