REG file doesn't work


exodia508766

New member
Local time
1:39 AM
Posts
24
OS
Windows 11
Im trying to add a custom command to Context Menu, but the command works in normal powershell window. Any help is appreciated.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\DesktopBackground\Shell\TurnOff]
"MUIVerb"="Close All Apps"
"icon"="imageres.dll,-5102"
"Position"="Bottom"

[HKEY_CLASSES_ROOT\DesktopBackground\Shell\TurnOff\command]
@="PowerShell -command "Get-Process | Where-Object {$_.MainWindowTitle -ne ''} | stop-process -Force"
 
Windows Build/Version
22621

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    DELL Inspiron 16 5630
    CPU
    i5 1335U
    Memory
    8
You probably just need to add escape chars to the command, and you were missing a quote.

Code:
@="PowerShell -command \"Get-Process | Where-Object {$_.MainWindowTitle -ne ''} | stop-process -Force\""
 

My Computer

System One

  • OS
    PE
Try this link:
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    PC/Desktop
    CPU
    Ryzen 9 3900X
    Motherboard
    ASUS ROG Strix X570-E Gaming
    Memory
    G-Skill RipjawsV F4-3600C18 (16GB x 2)
    Graphics Card(s)
    Gigabyte RX 5700 XT Gaming OC
    Sound Card
    Realtek ALC1220P
    Monitor(s) Displays
    ASUS VE278 (x 2)
    Screen Resolution
    1920x1080
    Hard Drives
    Samsung 850 Pro 256GB
    Samsung 970 Pro NVMe 512GB (x 2)
    ST10000VN0004 10TB (x 2)
    ST10000VN0008 10TB (x 2)
    ST4000VN000 4TB (x 2)
    PSU
    Corsair HX1000
    Case
    Corsair Carbide 400R
    Cooling
    AMD Wraith Prism (Stock)
    Keyboard
    Logitech G213
    Mouse
    Logitech G502
    Internet Speed
    100Mbps down / 40Mbps up
    Browser
    Firefox - Chrome - Edge
    Antivirus
    Windows Defender - Clamwin
Here is the full fixed file to copy/paste:

Code:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\DesktopBackground\Shell\TurnOff]
"MUIVerb"="Close All Apps"
"icon"="imageres.dll,-5102"
"Position"="Bottom"

[HKEY_CLASSES_ROOT\DesktopBackground\Shell\TurnOff\command]
@="PowerShell -command \"Get-Process | Where-Object {$_.MainWindowTitle -ne ''} | stop-process -Force\""

If you noticed me leaving the site for a second, thats because I tried it :LOL: This will close all open windows when selected from the right click context menu.
 

My Computer

System One

  • OS
    PE
So like when I tried those new .REG files, it closes most apps but not File Explorer, Task Scheduler, Event Viewer etc. But when I use the command in actual PowerShell, it closes those too. What am i missing ?
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    DELL Inspiron 16 5630
    CPU
    i5 1335U
    Memory
    8
{$_.MainWindowTitle -ne ''}
Still learning PowerShell and have a question, in that portion above is the space after ne required and is the following two single quotes or a double quote?
 

My Computers

System One System Two

  • OS
    Win11 Pro RTM
    Computer type
    Laptop
    Manufacturer/Model
    Dell Vostro 3400
    CPU
    Intel Core i5 11th Gen. 2.40GHz
    Memory
    12GB
    Hard Drives
    256GB SSD NVMe
  • Operating System
    Windows 11 Pro RTM x64
    Computer type
    PC/Desktop
    Manufacturer/Model
    Dell Vostro 5890
    CPU
    Intel Core i5 10th Gen. 2.90GHz
    Memory
    16GB
    Graphics card(s)
    Onboard, no VGA, using a DisplayPort-to-VGA adapter
    Monitor(s) Displays
    24" Dell
    Hard Drives
    512GB SSD NVMe, 2TB WDC HDD
    Browser
    Firefox, Edge
    Antivirus
    Windows Defender/Microsoft Security
2 single quotes
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    DELL Inspiron 16 5630
    CPU
    i5 1335U
    Memory
    8
So like when I tried those new .REG files, it closes most apps but not File Explorer, Task Scheduler, Event Viewer etc. But when I use the command in actual PowerShell, it closes those too. What am i missing ?
For me Task Scheduler and Event Viewer close. File explorer however does not. I believe UWP based apps are overlooked. Best not to close explorer.exe unless you relaunch it afterwards, otherwise you would lose taskbar.

Also UAC may be preventing the others from closing.
 

My Computer

System One

  • OS
    PE
I tried it on Windows 10 as well, just to make sure and nope, it still did not work.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    DELL Inspiron 16 5630
    CPU
    i5 1335U
    Memory
    8
Still learning PowerShell and have a question, in that portion above is the space after ne required and is the following two single quotes or a double quote?
Basically it says cycle through all the processes and if the window title -not equal '' (or nothing) then close it. So close any open window. Data inside single quotes are taken literally and inside double quotes are interpreted. either could have been used in this instance, but it is cleaner to use singles or escape chars would have to be used.
 

My Computer

System One

  • OS
    PE
Thanks
 

My Computers

System One System Two

  • OS
    Win11 Pro RTM
    Computer type
    Laptop
    Manufacturer/Model
    Dell Vostro 3400
    CPU
    Intel Core i5 11th Gen. 2.40GHz
    Memory
    12GB
    Hard Drives
    256GB SSD NVMe
  • Operating System
    Windows 11 Pro RTM x64
    Computer type
    PC/Desktop
    Manufacturer/Model
    Dell Vostro 5890
    CPU
    Intel Core i5 10th Gen. 2.90GHz
    Memory
    16GB
    Graphics card(s)
    Onboard, no VGA, using a DisplayPort-to-VGA adapter
    Monitor(s) Displays
    24" Dell
    Hard Drives
    512GB SSD NVMe, 2TB WDC HDD
    Browser
    Firefox, Edge
    Antivirus
    Windows Defender/Microsoft Security
You might like the version I just posted here.
 

My Computer

System One

  • OS
    Windows 7
Did you find out what was the problem ?
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    DELL Inspiron 16 5630
    CPU
    i5 1335U
    Memory
    8
Your error was all quotes inside the @="..." must be escaped with leading \'s.
Code:
@="powershell \"command1; command2\""
 

My Computer

System One

  • OS
    Windows 7
Is it possible to put your powershell command with escapes in .REG file without vbscript and scheduled task ? Can you show me how ?
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    DELL Inspiron 16 5630
    CPU
    i5 1335U
    Memory
    8
If you skip the scheduled task feature, you will lose the ability to close elevated (Administrator) apps.

Here's the standalone .reg file:
Code:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\DesktopBackground\Shell\TurnOff]
"MUIVerb"="Close All Apps"
"icon"="imageres.dll,-5102"
"Position"="Bottom"

[HKEY_CLASSES_ROOT\DesktopBackground\Shell\TurnOff\command]
@="cmd /c start \"\" /min powershell -Window Hidden \"(New-Object -ComObject Shell.Application).Windows() | foreach {$_.Quit()}; Get-Process | where {$_.SI -eq (Get-Process -PID $PID).SI -and $_.MainWindowHandle -ne 0 -and $_.Name -ne 'explorer'} | Stop-Process -Force\""
 

My Computer

System One

  • OS
    Windows 7

Latest Support Threads

Back
Top Bottom