How to Fix: Run Batch Script as Administrator (Without Password)
Infopackets Reader Barry S. writes:
" Dear Dennis,
I read with interest your article on how to shut down Mozilla Thunderbird gracefully using a series of 'taskkill' commands. The issue I have is that Thunderbird eats an enormous amount of memory if I leave it running over a period of 24 hours or more. When I try and send an email, the words in the email window (as I'm typing them) come out in spurts. This drives me crazy as I am a fairly quick typist. I tried setting up a batch script to run (using Task Scheduler) to gracefully close Thunderbird and restart it every 24 hours, but for some reason it isn't working properly. When Thunderbird restarts from the script, it runs in the background but doesn't load the main Thunderbird window. Strangely enough this works fine if I run the script using an administrative command prompt window. I believe the problem has to do with administrative access, even though I have set the Task Scheduler to run the program as Administrator. Can you help me run a batch script as administrator? "
My response:
I asked Barry if he would like me to connect to his machine using my remote desktop support service, and he agreed.
How to Fix: Run Batch Script as Administrator (Without Password)
I have plenty of experience with batch scripts (.BAT, or .CMD), etc - however I have not come across the same type of problem where the script works using an administrative command line and then doesn't work when running it using Task Scheduler, even with Administrator access check marked.
After a bit of research I came across two solutions when it comes to running a program with administrative privileges using a batch script.
Solution #1: Run the Program in C:\Windows\System32
As many users have pointed out in online forums: if you place an executable inside of the C:\Windows\System32 directory, it should run with administrative privileges because that is where most of the .EXE files for the Windows operating system are stored.
Please note, however, this is a "hack," and assumes that the .EXE can run on its own outside of its normal installation directory, which might work for a very small percentage of programs. I do not recommend this method as this will have limited success and is also a security risk. Therefore, I recommend using Solution #2 below.
Solution #2: Set up the Task in Task Scheduler, then Call the Task Using a Batch File
To launch a program using administrative privileges (using a batch script), you must first set up the program inside of Task Scheduler - using administrative privileges. Once that is done you can call the program inside the batch script, which references the Task Scheduler entry.
As an example, these are the steps you would take if you are attempting to launch Thunderbird from a batch script (using a Task Scheduler entry):
- Launch Task Scheduler: click Start then type in "task scheduler" (no quotes); wait for Task Scheduler to appear and click it.
- At the top left of the Task Scheduler window, left click the "Task Scheduler Library" icon to highlight it,
then right click over top of the highlighted area and select "Create Task" (do NOT select "Create Basic Task").
- The "Create Task" window will appear. Under the "General" tab, type in the
name of the task - example: "Run Thunderbird", then click the option near the bottom that says "Run with Highest Privileges". At this point Windows
should prompt you to enter your user name and password - this is a security protocol used to launch administrative tasks.
Note: the user you are running the task under should have administrative
rights, or the task won't run with administrative privileges.
- Normally when an entry is added to Task Scheduler, a "Trigger" is needed as part of automating the process of launching a task. That said, we are going to be calling this event from a batch script, so we will
skip the "Trigger" tab in this case.
- Next, click the "Actions" tab of the task, then click the "New..." button near the bottom. A new window will appear;
under the "Settings" heading, click the "Browse" button
and select the executable for the program you wish to launch with administrative privileges from your batch script. In this case, we are using the Thunderbird.exe (executable) located in C:\Program Files\Mozilla Thunderbird\Thunderbird.exe. Once you have selected the .EXE file,
click the "Open" button to add it, then click "OK".
- Finally, click the "Settings" tab, then un-check mark the option that says "Stop the task if it runs longer than:" (3 days). Click OK to add the task to Task Scheduler.
- Test to make sure that the task runs. Right click the Task Scheduler event you just created, and select "Run" from the dialogue menu. The task should run without any issues.
Continue on with the section below.
Call the Task Using Your Batch Script
If the task (event) is launching properly from the Task Scheduler main window, it's now time to call the Task Scheduler event using your batch script.
To do so, use the following syntax inside your batch file:
SCHTASKS /Run /TN "run thunderbird"
... Where "run thunderbird" is the name of the task as outlined in Step #3 in the previous section.
Continue on with the section below.
Launch Your Batch Script using Task Scheduler
You can now repeat all the steps above - this time, create a new even by adding your batch script to Task Scheduler.
This time you will want to use a "Trigger" to run the task every 24 hours (for example). Once the event has been added into Task Scheduler, you can test to see if it is working by right clicking over top of the event, then select "Run". Thunderbird (or whichever task you wanted to run with administrative privileges) should launch properly!
I hope that helps.
Additional 1-on-1 Support: From Dennis
If all of this is over your head, or if you need help automating a script / program and it needs to run with administrative privileges, I can help using my remote desktop support service. Simply contact me, briefly describing the issue and I will get back to you as soon as possible.
Got a Computer Question or Problem? Ask Dennis!
I need more computer questions. If you have a computer question -- or even a computer problem that needs fixing -- please email me with your question so that I can write more articles like this one. I can't promise I'll respond to all the messages I receive (depending on the volume), but I'll do my best.
About the author: Dennis Faas is the owner and operator of Infopackets.com. With over 30 years of computing experience, Dennis' areas of expertise are a broad range and include PC hardware, Microsoft Windows, Linux, network administration, and virtualization. Dennis holds a Bachelors degree in Computer Science (1999) and has authored 6 books on the topics of MS Windows and PC Security. If you like the advice you received on this page, please up-vote / Like this page and share it with friends. For technical support inquiries, Dennis can be reached via Live chat online this site using the Zopim Chat service (currently located at the bottom left of the screen); optionally, you can contact Dennis through the website contact form.
Most popular articles
- Which Processor is Better: Intel or AMD? - Explained
- How to Prevent Ransomware in 2018 - 10 Steps
- 5 Best Anti Ransomware Software Free
- How to Fix: Computer / Network Infected with Ransomware (10 Steps)
- How to Fix: Your Computer is Infected, Call This Number (Scam)
- Scammed by Informatico Experts? Here's What to Do
- Scammed by Smart PC Experts? Here's What to Do
- Scammed by Right PC Experts? Here's What to Do
- Scammed by PC / Web Network Experts? Here's What to Do
- How to Fix: Windows Update Won't Update
- Explained: Do I need a VPN? Are VPNs Safe for Online Banking?
- Explained: VPN vs Proxy; What's the Difference?
- Explained: Difference Between VPN Server and VPN (Service)
- Forgot Password? How to: Reset Any Password: Windows Vista, 7, 8, 10
- How to: Use a Firewall to Block Full Screen Ads on Android
- Explained: Absolute Best way to Limit Data on Android
- Explained: Difference Between Dark Web, Deep Net, Darknet and More
- Explained: If I Reset Windows 10 will it Remove Malware?
My name is Dennis Faas and I am a senior systems administrator and IT technical analyst specializing in cyber crimes (sextortion / blackmail / tech support scams) with over 30 years experience; I also run this website! If you need technical assistance , I can help. Click here to email me now; optionally, you can review my resume here. You can also read how I can fix your computer over the Internet (also includes user reviews).
We are BBB Accredited
We are BBB accredited (A+ rating), celebrating 21 years of excellence! Click to view our rating on the BBB.
Comments
Running schtasks requires elevated privileges
This is very interesting technique. However, in my case in order to run schtasks the command prompt window should be ran as admin. Otherwise I get "ERROR: Access is denied." Which defeats the purpose... Any suggestions?
Thanks!
Run with admin privileges
Step #3 states to run the script with admin privileges. If this is not set then the whole thing won't run with administrator rights and the script will fail.
If you tested the batch file using the command line then you will have to run the command line with admin privileges as well, though that has nothing to do with Step #3. Running anything in an administrative command line would be for demonstrative purposes only (for yourself to see any error messages associated with the batch file) - but as stated, Step #3 would set the batch with admin rights under Task Scheduler.