how to schedule in Windows 2008 task scheduler.

Nov 30, 2010 at 6:25 PM

I have other PS1 scripts running fine in task scheduler but this one goes to "Running" for a second and then stops.  If I run the script in a .bat file manually.. it runs fine.  This one has me stumped. 

Coordinator
Nov 30, 2010 at 6:44 PM

I have faced the problem too.

My script implements a very rough locking mechanism to prevent simultaneous execution of two (or more) instances as the zipping part is very resource intensive. You can find the mechanism at lines from 1249 to 1258. Simply speaking it throws a semaphore file in the %Temp% path and removes it when done.

So here comes the tricky part. When you run a script using task scheduler the %temp% is appended a number (1, 2, 3, whatever) as each environment has to be separated from others. So it might have happened that a previous scheduled task has aborted prior normal completion and, therefore, has left the lock file in place.

Check any subfolder in your %temp% path to see if there is any .lock file and remove it.

Nov 30, 2010 at 6:46 PM
Edited Nov 30, 2010 at 7:42 PM

It will run if I select "Run only when user is logged on"

I'll try what you said to see what happens :-)

- Brandon
www.certpros.net




From: [email removed]
To: [email removed]
Date: Tue, 30 Nov 2010 10:44:50 -0800
Subject: Re: how to schedule in Windows 2008 task scheduler. [7zbackup:236560]

From: Anlan

I have faced the problem too.
My script implements a very rough locking mechanism to prevent simultaneous execution of two (or more) instances as the zipping part is very resource intensive. You can find the mechanism at lines from 1249 to 1258. Simply speaking it throws a semaphore file in the %Temp% path and removes it when done.
So here comes the tricky part. When you run a script using task scheduler the %temp% is appended a number (1, 2, 3, whatever) as each environment has to be separated from others. So it might have happened that a previous scheduled task has aborted prior normal completion and, therefore, has left the lock file in place.
Check any subfolder in your %temp% path to see if there is any .lock file and remove it.
Read the full discussion online.
To add a post to this discussion, reply to this email (7zbackup@discussions.codeplex.com@discussions.codeplex.com)
To start a new discussion for this project, email 7zbackup@discussions.codeplex.com@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com
Coordinator
Nov 30, 2010 at 6:48 PM

Ok ... keep me informed about your results.

And ... BTW .... thank you for your post.

Nov 30, 2010 at 7:00 PM
It seems that it will only run in a logged in environment. Will not run if logged out. Even if I select to run whether logged in or not.

I saw the 7zBackup.lock file but that didn't seem to be the issue.


From: [email removed]
To: [email removed]
Date: Tue, 30 Nov 2010 10:48:40 -0800
Subject: Re: how to schedule in Windows 2008 task scheduler. [7zbackup:236560]

From: Anlan
Ok ... keep me informed about your results.
And ... BTW .... thank you for your post.
Read the full discussion online.
To add a post to this discussion, reply to this email (7zbackup@discussions.codeplex.com@discussions.codeplex.com)
To start a new discussion for this project, email 7zbackup@discussions.codeplex.com@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com
Coordinator
Mar 8, 2011 at 5:38 PM

Hi certpros,

i follow up on this thread to inform you I have faced the same problem on a recently installed Windows 2008 R2: despite the lock file has no influence on the execution of the script, it seems like it only runs in interactive mode and, as a scheduled job, regularly fails or does nothing.

After a serious digging the web for similar issues I found the following as reasons for this Powershell script to fail:

  1. Windows 2008 Task Scheduler : it behaves differently from previous versions. The "Run only when user is logged on" tick did lit the bulb. Not logged in user means no user profile is loaded which brings to the fact that Junction.exe does not find whether or not user has accepted eula on first run therefore halting the execution of the script (it would require to answer the prompt). To avoid the problem I have slightly changed the code of the script to include "/accepteula" switch by default. Will publish modified version shortly.
  2. Windows 2008 security policy : the user credentials used to run the scheduled script must be granted "Create symbolic links" in local security policy otherwise Junction.exe will not run.
  3. Windows 2008 Task Scheduler Syntax : the "Action" tab has to be precisely filled. Program to start must be "Powershell.exe" while "Arguments" must be like this :

    -Command & ("{C:\Scripts\7zBackup.ps1 --type full --selection c:\Scripts\pc-andrea.txt --destpath D:\pppp --rotate 10 --prefix MYPC --workdrive D}")
    Note the usage of brackets and curly brackets. Also be sure you fill the "Start from" field with the path where your ps1 script is.

  4. Ensure task's elevated privileges are activated.

With all this honoured I had no problems running the script.

Jun 9, 2011 at 10:24 AM

Hi,

Could you please provide a code snippet for "/accepteula" switch? I also need to setup scheduling in Windows Server 2008.

Many thanks in advance!

Coordinator
Jun 9, 2011 at 11:07 AM
Edited Jun 9, 2011 at 11:07 AM

Hi ermakovich,

you can easily integrate "/accepteula" switch this way. Look in Make-Junction function at about line 836 and change this way

 

# Junction it
Junction "/accepteula " $jPath $jTarget | Out-Null

This will be by default in new releases.

Jun 9, 2011 at 12:28 PM
Edited Jun 9, 2011 at 12:31 PM

Works for me. Thanks a lot!

Btw, it seems that the following syntax is also legal:

Junction $jPath $jTarget /accepteula | Out-Null

Sep 11, 2012 at 1:23 PM

I had to add some extra " " after -command. Like this:

-Command "& ("{D:\Other\7zBackup\7zBackup.ps1 --selection D:\Other\7zBackup\MyBackup.txt --clearbits true}")"