Enable_Disable Control Panel and Settings using AutoHotkey

Get help with using AutoHotkey and its commands and hotkeys
RaudelJr
Posts: 5
Joined: 28 Jan 2017, 04:00

Enable_Disable Control Panel and Settings using AutoHotkey

28 Jan 2017, 04:16

Enable_Disable Control Panel and Settings using AutoHotkey

I'm Trying to create HotKeys that would Enable and Disable the Windows Control Panel and Settings.

I currently have the following:

!f2:: ; This will Disable the Windows Control Panel and Settings.
Run "C:\Enable_Disable Control Panel and Settings\Disable Control Panel and Settings.reg"
Return

!f1:: ; This will Enable the Windows Control Panel and Settings.
Run "C:\Enable_Disable Control Panel and Settings\Enable Control Panel and Settings (default).reg"
Return

which is working fine since it runs the registry files which write to the Registry the keys as shown below respectively.

[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"NoControlPanel"=dword:00000000

[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"NoControlPanel"=dword:00000001

But I would like to have a script that will automatically write to the registry without using the Run command.

I tried the following:

!f4:: ; This will Disable the Windows Control Panel and Settings.
RegWrite, REG_DWORD, HKEY_CURRENT_USER, SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer, NoControlPanel, 1
Return

!f3:: ; This will Enable the Windows Control Panel and Settings.
RegWrite, REG_DWORD, HKEY_CURRENT_USER, SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer, NoControlPanel, 0
Return


But it didn't work. I'm not sure what I'm doing wrong. Is it permissions, or something else?
foxhunter
Posts: 70
Joined: 04 Aug 2016, 04:27

Re: Enable_Disable Control Panel and Settings using AutoHotkey

28 Jan 2017, 05:25

Run your script as admin, this works for me
RaudelJr
Posts: 5
Joined: 28 Jan 2017, 04:00

Re: Enable_Disable Control Panel and Settings using AutoHotkey

28 Jan 2017, 11:04

I run the script at startup. Since I place it in the common startup folder.

Is there a way to set it to be as administrator, or to script proper permissions?
RaudelJr
Posts: 5
Joined: 28 Jan 2017, 04:00

Re: Enable_Disable Control Panel and Settings using AutoHotkey

28 Jan 2017, 15:31

I've been reading and trying to understand the different commands, but I'm not very versed.

I would like the script to gain administrative permissions and be able to write to registry regardless of the user.
RaudelJr
Posts: 5
Joined: 28 Jan 2017, 04:00

Re: Enable_Disable Control Panel and Settings using AutoHotkey

01 Feb 2017, 03:31

I wanted to mention that I figured it out.

The script is fine the way it is.

And to skip all the UAC prompts, and to be able to run at startup, you simply need to set up a task in the Task Scheduler to run on user logon and to run with highest privileges.

Also I compiled the script into an EXE and selected it as the program to be ran at logon.

That's it.

Raudel
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
GitHub: 4GForce

Re: Enable_Disable Control Panel and Settings using AutoHotkey

01 Feb 2017, 03:57

I don't feel like swapping users and actually testing this, but I know it used to work ... could be a starting point for you to test :

Code: Select all

RunAsAdmin() 
{
    ShellExecute := A_IsUnicode ? "shell32\ShellExecute":"shell32\ShellExecuteA" 
    if not A_IsAdmin 
    { 
        If A_IsCompiled 
           DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_ScriptFullPath, str, A_WorkingDir, int, 1) 
        Else 
           DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_AhkPath, str, """" . A_ScriptFullPath . """", str, A_WorkingDir, int, 1) 
    }
}	
RaudelJr
Posts: 5
Joined: 28 Jan 2017, 04:00

Re: Enable_Disable Control Panel and Settings using AutoHotkey

01 Feb 2017, 21:50

Tried the following, It didn't work to run my script as Administrator. I'm a real newby. Sorry. I must really be doing something wrong.


RunAsAdmin()
{
ShellExecute := A_IsUnicode ? "shell32\ShellExecute":"shell32\ShellExecuteA"
if not A_IsAdmin
{
If A_IsCompiled
DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_ScriptFullPath, str, A_WorkingDir, int, 1)
Else
DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_AhkPath, str, """" . A_ScriptFullPath . """", str, A_WorkingDir, int, 1)
}
}

!f2:: ; This will Disable the Windows Control Panel and Settings.
RegWrite, REG_DWORD, HKEY_CURRENT_USER, SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer, NoControlPanel, 1
Return

!f1:: ; This will Enable the Windows Control Panel and Settings.
RegWrite, REG_DWORD, HKEY_CURRENT_USER, SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer, NoControlPanel, 0
Return

#NoTrayIcon

#SingleInstance force










I also tried


RunAsAdmin() {
Loop, %0% ; For each parameter:
{
param := %A_Index% ; Fetch the contents of the variable whose name is contained in A_Index.
params .= A_Space . param
}
ShellExecute := A_IsUnicode ? "shell32\ShellExecute":"shell32\ShellExecuteA"

if not A_IsAdmin
{
If A_IsCompiled
DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_ScriptFullPath, str, params , str, A_WorkingDir, int, 1)
Else
DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_AhkPath, str, """" . A_ScriptFullPath . """" . A_Space . params, str, A_WorkingDir, int, 1)
ExitApp
}
}

!f2:: ; This will Disable the Windows Control Panel and Settings.
RegWrite, REG_DWORD, HKEY_CURRENT_USER, SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer, NoControlPanel, 1
Return

!f1:: ; This will Enable the Windows Control Panel and Settings.
RegWrite, REG_DWORD, HKEY_CURRENT_USER, SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer, NoControlPanel, 0
Return

#NoTrayIcon

#SingleInstance force

Return to “Ask For Help”

Who is online

Users browsing this forum: Chunjee, mikeyww, phrank, punchin, RubbeH and 37 guests