-1

I want my .bat file to always run as administrator without me having to manually allow it to make changes to my device each time. It's part of a larger automated process and simply clears and resets the clipboard. Since it's automated I can't be there each time to hit yes.

wmic service where "name like '%%cbdhsvc_%%'" call stopservice
%windir%\System32\cmd.exe /c "echo off | clip"
wmic service where "name like '%%cbdhsvc_%%'" call startservice

Alternatively is there a way I could set it to run say every 5 seconds in the background with only a single confirmation until I tell it to stop or for a set period? Thanks

RealHowTo
  • 34,977
  • 11
  • 70
  • 85
Cheesy
  • 23
  • 5
  • 3
    Not possible, Windows specifically disallows running as admin without explicit confirmation from a user. It's part of their protection against malware. – Mark Ransom Jul 19 '22 at 22:23
  • 2
    If you want it to run on a schedule, (every _n_), then create a task in Windows Task Scheduler to run the script with sufficient privileges to not require confirmation. – Compo Jul 20 '22 at 01:29

1 Answers1

1

For only having to allow administrator once, you could use the timeout command.

:top
"code"
timeout /t 5 /NOBREAK > nul
goto :top

do timeout/? in cmd to see the usage.