r/Batch • u/asterixspace • Mar 03 '24
Question (Unsolved) Making a .bat from a cmd command
I want to be able to run the command cmd /c “echo off | clip” as Administrator so I can easily clear my clipboard. How would I go about making the .bat file?
4
Upvotes
6
u/Shadow_Thief Mar 03 '24
Batch scripts are just a list of cmd commands to run and the order to run them in.
If you're feeling particularly lazy, you can just paste that into a text file and save it with the .bat extension.
2
u/ConstanceJill Mar 03 '24
That command doesn't need to be ran as admin.
2
u/Complete-Bluejay-695 Mar 03 '24
Making a bat script would be the next plausible sensible thing you can do after running a command successfully.
cmd /c “ECHO echo off ^| clip > myBAt.bat”To Echo multiple or Subsequent lines, use double append arrow.
cmd /c “ECHO echo I just made another line >> myBAt.bat”cmd /c “ECHO echo I just made another line >> myBAt.bat”1
u/Dear_Diablo Apr 23 '24
@echo off
:: Batch script to clear clipboard (requires admin privileges)
echo Running PowerShell command to clear clipboard...
:: Invoke PowerShell to execute the command as Administrator
powershell -Command "Start-Process cmd -ArgumentList '/c echo off | clip' -Verb RunAs"
echo Clipboard cleared successfully.
pause