Solved Adding & Running .BAT File - As Administrator - from Start Menu


IanMosley

Windows Insider
Power User
VIP
Local time
5:35 PM
Posts
1,226
Location
UK
OS
Windows 11 Pro 25H2 (Build 26200.8728)
I wish to run the enclosed .bat file - as administrator - from Start Menu.

Is this possible? And if so, how do I do it?

File contents

@ECHO ON
rundll32.exe pnpclean.dll,RunDLL_PnpClean /drivers/maxclean
dism /Online /Cleanup-Image /CheckHealth
dism /Online /Cleanup-Image /ScanHealth
sfc /scannow
dism /Online /Cleanup-Image /RestoreHealth
PAUSE

EXIT
 
Last edited:

My Computer My Computer

At a glance

Windows 11 Pro 25H2 (Build 26200.8728)Intel Core Ultra 9 285 5.6 GHz32.00 GBIntel Integrated Graphics (128 MB)
OS
Windows 11 Pro 25H2 (Build 26200.8728)
Computer type
PC/Desktop
Manufacturer/Model
Dell Pro Max Tower T2 FCT2250
CPU
Intel Core Ultra 9 285 5.6 GHz
Motherboard
64-bit operating system, x64-based processor
Memory
32.00 GB
Graphics Card(s)
Intel Integrated Graphics (128 MB)
Sound Card
Realtek Audio
Monitor(s) Displays
Dell P2714H Monitor
Screen Resolution
1920 x 1080
Hard Drives
1 x 512GB M.2 XG10d SED KIOXIA PCIe solid state drive (Internal)
1 x 2TB Seagate ST2000DM008-2UB102 HDD (Internal)
1 x 1TB Seagate STGX4000400 External HDD
1 x 4TB Seagate STGX4000400 External HDD
1 x 6TB WD Elements AE 2689 External HDD
PSU
500 Watts
Cooling
Air
Keyboard
Microsoft Wired Keyboard 600
Mouse
Microsoft USB Basic Optical Mouse v2.0
Browser
Firefox
Antivirus
Windows Defender + Malwarebytes Premium
Other Info
BaseBoard Manufacturer Dell Inc.
BaseBoard Product 022RY57
BaseBoard Version A01
You can use the following to elevate a command prompt to run those commands... it WILL invoke a UAC auth screen which can be annoying, but I don't know a way to bypass that off the top of my head.

Batch:
@ECHO OFF

:init
setlocal DisableDelayedExpansion
set cmdInvoke=1
set winSysFolder=System32
set "batchPath=%~dpnx0"
rem this works also from cmd shell, other than %~0
for %%k in (%0) do set batchName=%%~nk
set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs"
setlocal EnableDelayedExpansion

:checkPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )

:getPrivileges
if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)

ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
ECHO args = "ELEV " >> "%vbsGetPrivileges%"
ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
ECHO args = args ^& strArg ^& " "  >> "%vbsGetPrivileges%"
ECHO Next >> "%vbsGetPrivileges%"

if '%cmdInvoke%'=='1' goto InvokeCmd

ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
goto ExecElevation

:InvokeCmd
ECHO args = "/c """ + "!batchPath!" + """ " + args >> "%vbsGetPrivileges%"
ECHO UAC.ShellExecute "%SystemRoot%\%winSysFolder%\cmd.exe", args, "", "runas", 1 >> "%vbsGetPrivileges%"

:ExecElevation
"%SystemRoot%\%winSysFolder%\WScript.exe" "%vbsGetPrivileges%" %*
exit /B

:gotPrivileges
setlocal & cd /d %~dp0
if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul  &  shift /1)

::::::::::::::::::::::::::::
::START
::::::::::::::::::::::::::::
rundll32.exe pnpclean.dll,RunDLL_PnpClean /drivers/maxclean
dism /Online /Cleanup-Image /CheckHealth
dism /Online /Cleanup-Image /ScanHealth
sfc /scannow
dism /Online /Cleanup-Image /RestoreHealth
PAUSE
EXIT /B
 

Attachments

My Computers My Computers

  • At a glance

    Windows 11 Pro βIntel® Core™ i7-1165G732 GB DDR4-3200 SDRAMIntel® Iris® Xᵉ Graphics
    OS
    Windows 11 Pro β
    Computer type
    Laptop
    Manufacturer/Model
    HP Pavilion Laptop 15-eg0070wm
    CPU
    Intel® Core™ i7-1165G7
    Memory
    32 GB DDR4-3200 SDRAM
    Graphics Card(s)
    Intel® Iris® Xᵉ Graphics
    Screen Resolution
    1920x1080
    Hard Drives
    2TB PCIe® NVMe™ M.2 SSD
  • At a glance

    macOS Ventura3.4 GHz Quad-Core Intel Core i540 GB 2400 MHz DDR4Radeon Pro 570 4 GB
    Operating System
    macOS Ventura
    Computer type
    PC/Desktop
    Manufacturer/Model
    Apple iMac 27" 5K (2017)
    CPU
    3.4 GHz Quad-Core Intel Core i5
    Memory
    40 GB 2400 MHz DDR4
    Graphics card(s)
    Radeon Pro 570 4 GB
    Monitor(s) Displays
    27" 5K, 34" UW
    Screen Resolution
    Mon 1: 5120 × 2880 Mon 2: 2560 x 1080
    Hard Drives
    32GB NVME, 1TB SSD
Maybe a bit simpler for you.....
Put your batch file in a folder on the C: drive.
Then make a shortcut to that batch file and give it "Run as Administrator" privileges.
And then put the shortcut in the Startup folder, not the batch file itself.

In order to run a batch file with Admin privileges, I've had to run it from a Shortcut, where I select "Run as Administrator".
It's a very old trick, but seems to still work.
Good Luck,
TM :cool:
PS: If UAC bugs you, shut it off! I do!
 
You can use the following to elevate a command prompt to run those commands... it WILL invoke a UAC auth screen which can be annoying, but I don't know a way to bypass that off the top of my head.
This is way beyond my technical skill.

However, do I just create a .bat with these contents? I've tried this but I cannot pin it to the Start Menu.
 

My Computer My Computer

At a glance

Windows 11 Pro 25H2 (Build 26200.8728)Intel Core Ultra 9 285 5.6 GHz32.00 GBIntel Integrated Graphics (128 MB)
OS
Windows 11 Pro 25H2 (Build 26200.8728)
Computer type
PC/Desktop
Manufacturer/Model
Dell Pro Max Tower T2 FCT2250
CPU
Intel Core Ultra 9 285 5.6 GHz
Motherboard
64-bit operating system, x64-based processor
Memory
32.00 GB
Graphics Card(s)
Intel Integrated Graphics (128 MB)
Sound Card
Realtek Audio
Monitor(s) Displays
Dell P2714H Monitor
Screen Resolution
1920 x 1080
Hard Drives
1 x 512GB M.2 XG10d SED KIOXIA PCIe solid state drive (Internal)
1 x 2TB Seagate ST2000DM008-2UB102 HDD (Internal)
1 x 1TB Seagate STGX4000400 External HDD
1 x 4TB Seagate STGX4000400 External HDD
1 x 6TB WD Elements AE 2689 External HDD
PSU
500 Watts
Cooling
Air
Keyboard
Microsoft Wired Keyboard 600
Mouse
Microsoft USB Basic Optical Mouse v2.0
Browser
Firefox
Antivirus
Windows Defender + Malwarebytes Premium
Other Info
BaseBoard Manufacturer Dell Inc.
BaseBoard Product 022RY57
BaseBoard Version A01
I attached an identical batch file to the post, so just download that and stick it in Startup
 

My Computers My Computers

  • At a glance

    Windows 11 Pro βIntel® Core™ i7-1165G732 GB DDR4-3200 SDRAMIntel® Iris® Xᵉ Graphics
    OS
    Windows 11 Pro β
    Computer type
    Laptop
    Manufacturer/Model
    HP Pavilion Laptop 15-eg0070wm
    CPU
    Intel® Core™ i7-1165G7
    Memory
    32 GB DDR4-3200 SDRAM
    Graphics Card(s)
    Intel® Iris® Xᵉ Graphics
    Screen Resolution
    1920x1080
    Hard Drives
    2TB PCIe® NVMe™ M.2 SSD
  • At a glance

    macOS Ventura3.4 GHz Quad-Core Intel Core i540 GB 2400 MHz DDR4Radeon Pro 570 4 GB
    Operating System
    macOS Ventura
    Computer type
    PC/Desktop
    Manufacturer/Model
    Apple iMac 27" 5K (2017)
    CPU
    3.4 GHz Quad-Core Intel Core i5
    Memory
    40 GB 2400 MHz DDR4
    Graphics card(s)
    Radeon Pro 570 4 GB
    Monitor(s) Displays
    27" 5K, 34" UW
    Screen Resolution
    Mon 1: 5120 × 2880 Mon 2: 2560 x 1080
    Hard Drives
    32GB NVME, 1TB SSD
My mistake, I thought you wanted it in Startup, not Start Menu... You should be able to drag/drop the file on the start menu to solve that, if not, there's a tutorial on here for adding batch files/folders/etc to the Start Menu but I don't have a link right now.
 

My Computers My Computers

  • At a glance

    Windows 11 Pro βIntel® Core™ i7-1165G732 GB DDR4-3200 SDRAMIntel® Iris® Xᵉ Graphics
    OS
    Windows 11 Pro β
    Computer type
    Laptop
    Manufacturer/Model
    HP Pavilion Laptop 15-eg0070wm
    CPU
    Intel® Core™ i7-1165G7
    Memory
    32 GB DDR4-3200 SDRAM
    Graphics Card(s)
    Intel® Iris® Xᵉ Graphics
    Screen Resolution
    1920x1080
    Hard Drives
    2TB PCIe® NVMe™ M.2 SSD
  • At a glance

    macOS Ventura3.4 GHz Quad-Core Intel Core i540 GB 2400 MHz DDR4Radeon Pro 570 4 GB
    Operating System
    macOS Ventura
    Computer type
    PC/Desktop
    Manufacturer/Model
    Apple iMac 27" 5K (2017)
    CPU
    3.4 GHz Quad-Core Intel Core i5
    Memory
    40 GB 2400 MHz DDR4
    Graphics card(s)
    Radeon Pro 570 4 GB
    Monitor(s) Displays
    27" 5K, 34" UW
    Screen Resolution
    Mon 1: 5120 × 2880 Mon 2: 2560 x 1080
    Hard Drives
    32GB NVME, 1TB SSD
Create a shortcut of your batch file anywhere
Move it here C:\ProgramData\Microsoft\Windows\Start Menu\Programs
You now have it in your All Apps menu
You can then Pin it to Start Menu/Task bar & Run as Admin
 

My Computers My Computers

  • At a glance

    All Branches but ReleaseAMD Ryzen 7 7735HS 3200-4500 Mhz 8 cores x 232 GB DDR5Radeon Graphic / NVIDIA GeForce RTX 4060 8 GB...
    OS
    All Branches but Release
    Computer type
    Laptop
    Manufacturer/Model
    Acer Nitro ANV15-51
    CPU
    AMD Ryzen 7 7735HS 3200-4500 Mhz 8 cores x 2
    Motherboard
    Sportage_RBH
    Memory
    32 GB DDR5
    Graphics Card(s)
    Radeon Graphic / NVIDIA GeForce RTX 4060 8 GB GDDR6
    Sound Card
    AMD/Realtek(R) Audio
    Monitor(s) Displays
    Integrated Monitor (15.3"vis)
    Screen Resolution
    FHD 1920X1080 16:9 144Hz
    Hard Drives
    KINGSTON OM8SEP4512Q-AA 1TB
    Western Digital 256GB
    PSU
    19V DC 6.32 A 120 W
    Cooling
    Dual Fans
    Mouse
    MS Bluetooth
    Internet Speed
    Fiber 1GB Cox -us & 1GB Orange-fr
    Browser
    Edge Canary- Firefox Nightly-Chrome Dev-Chrome Dev
    Antivirus
    Windows Defender
  • At a glance

    Windows 11 BetaAMD A9-94208 GB of DDR4AMD Radeon R5
    Operating System
    Windows 11 Beta
    Computer type
    Laptop
    Manufacturer/Model
    Asus X751BP
    CPU
    AMD A9-9420
    Memory
    8 GB of DDR4
    Graphics card(s)
    AMD Radeon R5
    Screen Resolution
    1600x900
    Hard Drives
    Seagate 1 TB
If you use the batch I provided, after you add it to the Start Menu, you do NOT have to run as Admin as it will do it for you.
 

My Computers My Computers

  • At a glance

    Windows 11 Pro βIntel® Core™ i7-1165G732 GB DDR4-3200 SDRAMIntel® Iris® Xᵉ Graphics
    OS
    Windows 11 Pro β
    Computer type
    Laptop
    Manufacturer/Model
    HP Pavilion Laptop 15-eg0070wm
    CPU
    Intel® Core™ i7-1165G7
    Memory
    32 GB DDR4-3200 SDRAM
    Graphics Card(s)
    Intel® Iris® Xᵉ Graphics
    Screen Resolution
    1920x1080
    Hard Drives
    2TB PCIe® NVMe™ M.2 SSD
  • At a glance

    macOS Ventura3.4 GHz Quad-Core Intel Core i540 GB 2400 MHz DDR4Radeon Pro 570 4 GB
    Operating System
    macOS Ventura
    Computer type
    PC/Desktop
    Manufacturer/Model
    Apple iMac 27" 5K (2017)
    CPU
    3.4 GHz Quad-Core Intel Core i5
    Memory
    40 GB 2400 MHz DDR4
    Graphics card(s)
    Radeon Pro 570 4 GB
    Monitor(s) Displays
    27" 5K, 34" UW
    Screen Resolution
    Mon 1: 5120 × 2880 Mon 2: 2560 x 1080
    Hard Drives
    32GB NVME, 1TB SSD
Create a shortcut of your batch file anywhere
Move it here C:\ProgramData\Microsoft\Windows\Start Menu\Programs
You now have it in your All Apps menu
You can then Pin it to Start Menu/Task bar & Run as Admin
I've successfully created a tile - System Diagnostics - on my Start Menu using this method.
However, when I click on it -
1. No option to Run as Administrator; and,
2. All I get is a 'pop-up window' as indicated below -

1.png
 

My Computer My Computer

At a glance

Windows 11 Pro 25H2 (Build 26200.8728)Intel Core Ultra 9 285 5.6 GHz32.00 GBIntel Integrated Graphics (128 MB)
OS
Windows 11 Pro 25H2 (Build 26200.8728)
Computer type
PC/Desktop
Manufacturer/Model
Dell Pro Max Tower T2 FCT2250
CPU
Intel Core Ultra 9 285 5.6 GHz
Motherboard
64-bit operating system, x64-based processor
Memory
32.00 GB
Graphics Card(s)
Intel Integrated Graphics (128 MB)
Sound Card
Realtek Audio
Monitor(s) Displays
Dell P2714H Monitor
Screen Resolution
1920 x 1080
Hard Drives
1 x 512GB M.2 XG10d SED KIOXIA PCIe solid state drive (Internal)
1 x 2TB Seagate ST2000DM008-2UB102 HDD (Internal)
1 x 1TB Seagate STGX4000400 External HDD
1 x 4TB Seagate STGX4000400 External HDD
1 x 6TB WD Elements AE 2689 External HDD
PSU
500 Watts
Cooling
Air
Keyboard
Microsoft Wired Keyboard 600
Mouse
Microsoft USB Basic Optical Mouse v2.0
Browser
Firefox
Antivirus
Windows Defender + Malwarebytes Premium
Other Info
BaseBoard Manufacturer Dell Inc.
BaseBoard Product 022RY57
BaseBoard Version A01
Ok, I solved it...

Remove the batch file from C:\ProgramData\Microsoft\Windows\Start Menu\Programs and place it somewhere else on your system.
Right-click the batch file and go to "Send To" -> "Desktop (create shortcut)"
Take this new shortcut and put that in C:\ProgramData\Microsoft\Windows\Start Menu\Programs and Pin it to Start
You do NOT have to run it as Admin as it will do it itself and it should run fine from the new shortcut
 

My Computers My Computers

  • At a glance

    Windows 11 Pro βIntel® Core™ i7-1165G732 GB DDR4-3200 SDRAMIntel® Iris® Xᵉ Graphics
    OS
    Windows 11 Pro β
    Computer type
    Laptop
    Manufacturer/Model
    HP Pavilion Laptop 15-eg0070wm
    CPU
    Intel® Core™ i7-1165G7
    Memory
    32 GB DDR4-3200 SDRAM
    Graphics Card(s)
    Intel® Iris® Xᵉ Graphics
    Screen Resolution
    1920x1080
    Hard Drives
    2TB PCIe® NVMe™ M.2 SSD
  • At a glance

    macOS Ventura3.4 GHz Quad-Core Intel Core i540 GB 2400 MHz DDR4Radeon Pro 570 4 GB
    Operating System
    macOS Ventura
    Computer type
    PC/Desktop
    Manufacturer/Model
    Apple iMac 27" 5K (2017)
    CPU
    3.4 GHz Quad-Core Intel Core i5
    Memory
    40 GB 2400 MHz DDR4
    Graphics card(s)
    Radeon Pro 570 4 GB
    Monitor(s) Displays
    27" 5K, 34" UW
    Screen Resolution
    Mon 1: 5120 × 2880 Mon 2: 2560 x 1080
    Hard Drives
    32GB NVME, 1TB SSD
The problems I've been having to get this to work have been down to the text editor I use.

All up and working now. Thank you. :-)
 

My Computer My Computer

At a glance

Windows 11 Pro 25H2 (Build 26200.8728)Intel Core Ultra 9 285 5.6 GHz32.00 GBIntel Integrated Graphics (128 MB)
OS
Windows 11 Pro 25H2 (Build 26200.8728)
Computer type
PC/Desktop
Manufacturer/Model
Dell Pro Max Tower T2 FCT2250
CPU
Intel Core Ultra 9 285 5.6 GHz
Motherboard
64-bit operating system, x64-based processor
Memory
32.00 GB
Graphics Card(s)
Intel Integrated Graphics (128 MB)
Sound Card
Realtek Audio
Monitor(s) Displays
Dell P2714H Monitor
Screen Resolution
1920 x 1080
Hard Drives
1 x 512GB M.2 XG10d SED KIOXIA PCIe solid state drive (Internal)
1 x 2TB Seagate ST2000DM008-2UB102 HDD (Internal)
1 x 1TB Seagate STGX4000400 External HDD
1 x 4TB Seagate STGX4000400 External HDD
1 x 6TB WD Elements AE 2689 External HDD
PSU
500 Watts
Cooling
Air
Keyboard
Microsoft Wired Keyboard 600
Mouse
Microsoft USB Basic Optical Mouse v2.0
Browser
Firefox
Antivirus
Windows Defender + Malwarebytes Premium
Other Info
BaseBoard Manufacturer Dell Inc.
BaseBoard Product 022RY57
BaseBoard Version A01

Latest Support Threads

Back
Top Bottom