Server 2016 scheduled task won't run

Scheduled task won't run unless logged in on Windows Server 2016. I've researched this for several hours and I'm getting nowhere. This is calling a VBS script which runs just fine if you either run it manually, or set the scheduled task to run only when the user is logged in.

The user is a domain admin. I also tried activating the default administrator account and it also fails in the same way when using this account, too.

I've tried calling the script via a batch file.
I've ensured that the START IN folder is specified and that it has a trailing backslash.

I've also tried calling this as C:\windows\syswow64\cscript - with a variable of the path to the vbscript, and using the syswow folder as the START IN folder.

I'm at a loss to know what to try next. There's possibly a typo somewhere along the line, but the scheduled task does run if it's set to run only when I'm logged in - I would hope that this proves the parameters to be correct.

For information, the script calls a program called Snapshot.exe and this creates a volume shadow copy vss type backup to a folder. This will eventually be a network resource but I've reconfigured it to be a local drive location temporarily so that there's no confusion over network credentials.

Any ideas please?
LVL 1
edz_pgtAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

McKnifeCommented:
We schedule snapshots by drive snapshot ourselves (is it drive snapshot for you) and it works. Share your task, batch and error, please.
0
edz_pgtAuthor Commented:
Hi McKnife,

Yes, it's Drive Snaphot. We've got loads of these out there and several on servers. The possible difference here is it being Server 2016 as this is the first one we've done, as far as I'm aware.

We've got a massive script that we usually use, but I've stripped most of it out in an effort to narrow down what might be causing this issue. So, the script that I'm running as a test right now is this:

'**Start Encode**
Dim strCurrDay
strCurrDay = Day(Now)
Dim strCurrMonth
strCurrMonth = Month(Now)
Dim strCurrYear
strCurrYear = Year(Now)
Dim strHshFilename
Dim strRptFilename
Dim strSNAFilename
Dim strMessage
Dim strBckupType
Dim strOutcome
Dim strSpaceEmail
Dim strShortPathLog
Dim strShortPathBackup
Dim objFolder
Dim objRprtFile
Dim objFiles
Dim objFile
Dim strHyphenPos
Dim strDelFullFile
Dim strDelDiffFile
Dim dtOldestDate
Dim strOldestFile
Dim intCountHshFiles
Dim BackupFolderExists
set objFso = CreateObject("Scripting.FileSystemObject")
set WshShell = Wscript.CreateObject("WScript.Shell")
strShortPathLog = objFso.GetFolder("E:\Backup").ShortPath


strShortPathBackup = objFso.GetFolder("E:\Backup\Test").ShortPath
strHshFilename = strShortPathBackup & "\C-" & strCurrYear & "-" & strCurrMonth & ".hsh"
strRptFilename = strShortPathLog & "\C-" & strCurrYear & "-" & strCurrMonth & "-" & strCurrDay & "-Backup-Report.log"
strSNAFilename = strShortPathBackup & "\C-" & strCurrYear & "-" & strCurrMonth & "-" & strCurrDay & ".SNA"
Return = WshShell.Run(strShortPathLog & "\snapshot.exe -PW=m32268m6xGC239a -T -W -L4400 C: " & strSNAFilename & " --LogFile:" & strRptFilename, , True)

Open in new window


Scheduledtask1.JPG
Any help is appreciated!
0
McKnifeCommented:
Share the task, batch (whole batch) and error, please. You gave me parts of the task, parts of the batch and no error.

You could see that it just works (not DS's fault, not server 2016's fault), by using this task:
snapshot c: e:\test.sna

Open in new window

without using vbscript or any arguments/ start in drives.
Execute that as system and that's all.
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

edz_pgtAuthor Commented:
Actually, I did do this previously but in a batch file, not a vbs file. It worked no problem at all.
So, that would sugged it's something to do with the code in the vb script - but it works no problem when it's run manually.
0
McKnifeCommented:
Well, we still need the error as seen on the history tab of task scheduler, and we need the task details (executor, elevated or not...).
0
edz_pgtAuthor Commented:
OK - I've minimised the script down to this which I've tested works fine when run manually.

set objFso = CreateObject("Scripting.FileSystemObject")
set WshShell = Wscript.CreateObject("WScript.Shell")
Return = WshShell.Run("E:\Backup\snapshot.exe C: E:\backup\test\cdrive.sna")

Open in new window


The scheduled task never actually finishes, so I need to terminate it each time. The last log before termination is this:
Task Scheduler launched "{27371fdd-a3f9-4f1b-ac43-77b7f6d2967c}"  instance of task "\Snapshot2"  for user "myadminaccount" .

The task is set to run whether the user is logged in or not.
The user account is set to myadminaccount.
Run with highest priviliges is checked.
Configured for Vista/Server 2008.
0
McKnifeCommented:
Try the system account instead. If that fails, we will easily be able to diagnose that. (Please note, the system account can be used to write to network shares as well).
0
edz_pgtAuthor Commented:
Looks like its not running as system, either.
That was something I tried earlier in the process and I did have some luck with it but that was just a simple batch file command line and the network shares failed. Doesnt appear to run the vbs script though - even with a local destination.
0
McKnifeCommented:
Ok, download psexec.exe and run
psexec -s -I cmd

Open in new window

The command windows which then appears runs as system account and you can test your script visibly as system.
0
edz_pgtAuthor Commented:
Thanks McKnife.
I've downloaded that, opened an elevated command prompt, run the command you suggested, and it works just fine.

So, it seems it's not the script. It must be something to do with the scheduled task - but I just can't see it.
I'm sure this is going to be one of those 'Doh!' moments but, I'm hoping it comes sometime soon!
0
McKnifeCommented:
That was just the analysis. I'll use your task now, hang on.
0
edz_pgtAuthor Commented:
Thanks - much appreciated!
0
McKnifeCommented:
Works at once.
I'll provide the task as xml file so that you can import it:
testbackup.xml
0
edz_pgtAuthor Commented:
Many thanks - I've compared the two tasks side by side by exporting mine to XML. I've noticed a handful of differences so I'll test those out.

Can you just confirm - are you using Server 2016 please?
0
McKnifeCommented:
Yes, I can confirm that, server 2016, 1607.
0
edz_pgtAuthor Commented:
Well, I don't get it.
This task is virtually identical and still doesn't run.
(I've replaced the domain as it was to desciptive of the client that this server belongs to.)
Snapshot3.xml
0
edz_pgtAuthor Commented:
I've just noticed I'm geting some events in the event log.
I have a string of ID:513

I'll have a google.....
0
McKnifeCommented:
Ok, one more thing: I always use the 64 bit version of drive snapshot, just in case you don't.
0
edz_pgtAuthor Commented:
That's interesting - I was warned off the 64 bit version!
I might give that a try. Thanks.
0
McKnifeCommented:
Warned? Now that's interesting for me. Why were you warned? We are using the x64 version since it came out (5-10 years?) and never a problem. It offers higher performance than the x86 one, lately I compared it on the same system I got 7 GB/minute with the x86 one and 11 GB/minute using x64.
0
edz_pgtAuthor Commented:
When I was first introduced to Snapshot about 5 years ago, I assumed that I needed to 64bit and I struggled to get it to work. I just remember someone (but I can't remember who!) telling me not to use that one and to use the 32bit instead. I have absolutely no idea why!

Anyway, it didn't make any difference - it still doesn't work. It looks like I've managed to fix the error in the event log, but it's not fixed my issue.


I don't suppose it make a difference, but it's worth mentioning that this is a virtual machine. You're not aware of any reason why this would have an impact?
0
edz_pgtAuthor Commented:
For completeness, I wonder if you'd mind downloading the very latest 32-bit snapshot.exe and seeing if your scheduled task still runs with that please?
0
McKnifeCommented:
Works with 32 bit. Works with your snapshot3.xml task and inside a virtual machine. So clearly, you are doing something that you are not sharing or your system has a defect.
0
edz_pgtAuthor Commented:
Yup - I appreciate everything you've done to try and help.
I've created new scheduled tasks and I've also imported yours. Nothing appears to work.

So frustrating!
0
McKnifeCommented:
Ok, problem reproduced and solved, I hope:

After recreating the task again and running it, I have the same problem now. What did I do differently? last time, using psexec -s -i cmd, I executed the script visibly, for a test. During that test run, you get this warning:
Capture.PNGIf you remove that checkmark and press ok in the test run, backup starts and afterwards, the task runs. So it was the warning that the cscrpt engine throws... I bet it's the same for you.

Use batch instead, maybe.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
McKnifeCommented:
Ah, it's simply this:
Capture.PNGUNblock it and there you go.
0
edz_pgtAuthor Commented:
Interesting.
However, neither the 32 bit or the 64bit exe files have that check mark.

So, you may well be right about the splash screen type box though. You think we can supress that prompt?
0
edz_pgtAuthor Commented:
OMG! - You are an absolute star!
I was actually in the process of rebuilding a vm as a last ditch attempt to resolve this!
0
McKnifeCommented:
If it's unblocked, it's unblocked... then it's something else for you.
Did you verify if the drive snapshot process (snapshot.exe) even appears in task manager?
If it does, it could very well be that the vss mechanism does not get a lock on the drive because of a database being mounted, for example.
0
McKnifeCommented:
Aha... :-)
So what solved it?
0
edz_pgtAuthor Commented:
So, I've used psexec and run it as:
cscript vbscript.vbs
Then, un-checked that box on the UAC prompt and continued.
Crashed the Snapshot task
Started it again and it didn't offer to UAC prompt.
Crashed Snapshot again.
Started the scheduled task (as system) and it ran.

Just need to bring my original script back in again and see if I can get it working to that shared folder.

I'll come back and confirm in a bit.
0
edz_pgtAuthor Commented:
OK - so, I can run the script from psexec and it works just fine and saves to a UNC path on the network. However, running it from the scheduled task, it says it can't find the destination.

Any ideas?
0
edz_pgtAuthor Commented:
Actually - I've just discovered it now works on the admin account so the System account isn't actually necessary.
Woohoo!!
0
edz_pgtAuthor Commented:
Thanks so much, McKnife - your help was invaluable and all at a weekend, too!
0
McKnifeCommented:
You are welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2016

From novice to tech pro — start learning today.