Scheduled Task Running Batch File at Login Not Working

0

Okay, here is the scenario. We are making some network changes where I work and would otherwise have to touch each PC to do this. I created a batch file with the code below. Obviously with our dns settings and admin password inserted.

@echo off

>nul wmic nicconfig where (IPEnabled=TRUE) call SetDNSServerSearchOrder     ("DNS1", "DNS2")


>nul net user Administrator NEWADMINPASSWORD


2>nul net localgroup administrators /delete "Domain Users" 

The batch file runs just fine from both the local C: directory and the network location it is stored on, but when running as a task it fails. It was my understanding that when running a script at login it runs under the system account and thus shouldn't get denied access.

Any help would be greatly appreciated. Thanks.

LaneDutch

Posted 2017-11-17T17:03:29.350

Reputation: 1

So you are saying you didn't set it to run under the system account but are expecting it to run under the system account just because the trigger you have set? – Squashman – 2017-11-17T17:17:13.913

1Are you sure you're supposed to be outputting to a file called null – None – 2017-11-17T17:28:54.873

Yes. How should I specify it to run under the system account otherwise. Id like to say I'm not a expert at any of this. I can stumble through a lot, but there isn't a whole lot of waltzing going on here. Also, no I don't need it to output a null file. I was trying to suppress it writing a confirmation message in the cmd window. – None – 2017-11-17T18:09:29.823

On the General Tab of the task, Click the radio button to run whether user is logged on or not. Click Changer User or Group. Type in system. click Check Names. Click Ok. Click ok. – Squashman – 2017-11-17T18:20:29.190

1In Windows the null device is expressed as NUL. Just one L. – Squashman – 2017-11-17T18:21:41.833

Alright, I haven't had a chance to try the above suggestion, but when running the script locally on a windows 7 machine it executes fine. However, when I run it on my new Laptop which is running Windows 10 it gives me access denied. All permissions concerning the Local Admin group are the same on both platforms and I cant figure out why this is. This is just a side note however. – None – 2017-11-17T19:56:39.167

@LaneDutch, then this really isn't a coding problem, which is what StackOverFlow is dedicated to. In General your original question isn't a coding problem. You may want to post your question on a different Stack Exchange site. – Squashman – 2017-11-17T20:03:20.257

Oh that was just a question until I get a second to edit the task. No worries. The above suggestion worked. Ill mark it as the answer. – None – 2017-11-17T20:07:07.793

Post your comment as a answer and Ill mark it for you. Thanks for the help. I apologize if it skirted the lines of what this forum is for, but I wasn't sure if there was a coding solution or not. – None – 2017-11-17T20:13:53.220

An AD start-up script rather than login script will run as system. – HelpingHand – 2017-11-17T23:46:28.603

Answers

1

Run Batch with the highest privileges under system account using Task Scheduler.

  1. Open Task Scheduler
  2. goto your task properties which runs the batch file
  3. Select General Tab
  4. Make sure your task settings are these...

    Uncheck Run only when user is logged on

    Check Run whether user is logged on or not

    Check Run with the highest privileges

This will ensure that the task will run as an account that has explicit "Full access" permissions to the system with highest privileges.

Click Here - ServerFault Solution

Gourav

Posted 2017-11-17T17:03:29.350

Reputation: 11

0

Ended up running it in the logon script. Still had a problem related to the fact that the script we were calling was stored on a network drive being mapped by the same logon script. Because of how fast it all ran, the X drive wasn’t being mapped before the script was being called. We used the UNC path instead and the script ran flawlessly.

Thanks.

LaneDutch

Posted 2017-11-17T17:03:29.350

Reputation: 1