How can I end a process with admin privileges using a batch file

16,997

Solution 1

There are two methods of running a command with administrator privileges.

Solution 1:

Right-Click the batch-file and click run as admin.

Solution 2:

Use the runas command to run a command or batch file with administrative permissions. This way the process is still automate but you will still need to type in the password for administrator.

Example:

C:\> runas /user:administrator "taskkill /f /im explorer.exe"
Enter the password for administrator:

Type runas /? for more info.

Solution 2

if you are already the administrator, you can create a shortcut to your batch file and when you right click the shortcut -> properties -> advanced -> check the checkbox "run as administrator" and voila! everytime you run the batch script via this shortcut file, it will run as administrator and will kill without any discrimination, happily ever after

Share:
16,997
Robert Buckley
Author by

Robert Buckley

Updated on June 09, 2022

Comments

  • Robert Buckley
    Robert Buckley almost 2 years

    I have written a batch file which starts OpenVPN. If the client is found, I check the connectivity by running PING. If the server is not found, then this means that although OpenVPN is running, the connection has not been established. At this point I want to restart OpenVPN. Because I am not using the admin account for this script, I always get the error "permission denied" when using TASKKILL /F. Is there anyway around this?

  • rojo
    rojo about 9 years
    There's a third. If you're logged on as an admin user but UAC is forcing your script to run without admin privileges, you can have your script prompt for elevation if needed. And there are surely others involving psexec and other third party tools.
  • Kalamalka Kid
    Kalamalka Kid almost 3 years
    This does not exist in Windows 10
  • gawkface
    gawkface almost 3 years
    @KalamalkaKid its there in Win 10 (I have Home edition) when you right click the shortcut and not the original file. In shortcut's properties, go to Shortcut -> Advanced and there's the checkbox