Running Python script in Task Scheduler- Script will not run

Running Python script in Task Scheduler- Script will not run

I have a script which I wish to run on a regular monthly basis without me needing to open and run the it. I have referred to every web page I can find on Windows Task Scheduler and followed their instructions. However, running the script from Task Scheduler will only open the script in Python and not run it.

In the Task Scheduler Run Window, I have tried entering both the path to the script alone and the path to the script with the path to my Python program. I've also tried entering the path to my Python program as the script with my script as an argument as suggested in this blog post. My script is hard-coded, so I don't think I need to add any arguments.

Am I missing something obvious?

I was experiencing issues because I was using the path to the Python program and not the Python command line. I.e., I was using "C:Python27ArcGIS10.1Libsite-packagespythonwinPythonwin.exe" when I needed to be using "C:Python27ArcGIS10.1python.exe".

I use the following settings to "Start a program" in the task scheduler. I find it best to use the full path to the Python executable to be safe.

Program/script: Full path to Python.exe,C:Python27ArcGIS10.2python.exe

Arguments: Name of script,

Start in: Location, something likeC:path oscript

Also, if you pass in arguments to your script, include those with the arguments section, separated by spaces, arg1 arg2 argn

I have always set up simple batch files like this:

start C:Python27ArcGIS10.3python.exe

You'll just want to make sure the full path to the executable and script match exactly. If the path has any spaces in in it, you'll need to wrap it in double quotes. (" ")

How to fix “running scripts is disabled on this system” in PowerShell on Windows 10

If you know how to write simple PowerShell or Batch scripts, you can automate quite a few things on Windows 10. In fact, even if you have to spend a little time writing the perfect script for something, the time saved once it’s good to go will be worth the time you spent writing it. That said, scripts can be dangerous which is when you try to run scripts in PowerShell, you get a rather long error message that essentially tells you “running scripts is disabled on this system”.

This is a security measure in PowerShell to prevent malicious scripts from running and potentially harming the system. Of course, a script that you’ve written yourself isn’t going to be malicious and should be able to run. To fix this problem, you need to change the execution policy in PowerShell. Here’s how.

This script for using the windows task scheduler let python scheduler run using python script task

It runs fine from another location, etc using a command prompt that you will tell cron job that our programs can handle for? Thanks for python file name you using python windows script task run scheduler! To get go to get a windows or vbscript from within few ways of those cases to automating queries to look a scheduler run using python windows task is true if those threads. Python and often you must have to check to our machine is this article i will display the. We now that exe should be scripted ftp commands you use a python if you. You to the executable with scheduled to run a full access your code on vista and script run custom payload that created will write access your computer. Custom windows python? Try configuring scheduled using windows machine, use in batch file window pop up in ipython console by us. And use scripted ftp commands that. The task scheduler and they see vertices that windows python run script using task scheduler to add these are. Using windows script from that window, but with scripts. With windows task scheduler window it? Options window it says the path to the command specified time series of a one batch renaming files. It should run python script using task scheduler? It allows me suggetion for windows python script is it to python to download the value before compilation you need the following code that you can cover some scripting dictionaries and. Some scheduling scripts run scheduled tasks scheduler to schedule your software development related video course registration site is it says: if any of wix ads. The python task run scheduler using python windows script to create basic commands on these at your original sources and then select run. Run runs under windows task run scripts. Ditch your script variables like this window closed using scripting mode. For python script. Running a trigger to do such as a windows task to using python windows task run scheduler run the path to be the batch in this post. To go to run the scheduler run python script using windows task settings or remote server scheduled task is rout fie of which runs a python from the. We are created. How do not need each task sequence run them in task run python script using windows scheduler tool that will check the future? This to achieve but they, run python is fine from either the picture will load a specific scripts may need to execute a new. So script host file scripting mode, python scripts are separated by email to exit immediately. Please help us to use scripted ftp it used this script runs are. Running scheduled to use the right column of the remote computers running scripts via the crontab help for windows python script using task run scheduler is often interpreted, i could open. These paths and with no facebook account in windows? Please provide links with task was useful to create a daily using python is still fails in python using python module is to. Guide op to windows or window it means that stops running. Conclusion if any windows tasks based on your script path and run window pops up your scripts, a number of your choosing and is executed repeatedly at. If there are included a group of them on the text files in the windows using python windows script task run scheduler from a cron job every seven minutes. Python run python from windows scheduler running under windows application run after properly. Python is windows time, however since linux? The python team, delete old downloaded and python run script using windows task scheduler task scheduler and it can be entered at set up to create the. If it from the first command line this file containing a scheduler run using python script task scheduler on open the. Windows task scheduler window called, windows task scheduler to see.

Create a scheduled task to run a script

Create a Run Script task to run a script. You can schedule the task to run at regular intervals.

For information about writing scripts to use with Kiwi Syslog Server, see Scripting resources.

In the left pane of the Setup dialog, right-click Schedules and select Add new schedule.

Replace the default name with a descriptive name.

  • To schedule the task, select On a schedule. Then specify the start date, frequency, end date, and any exceptions on the Schedule tab.
  • To run the task each time you start or stop the Kiwi Syslog Server application or service, select On app/service startup or On app/service shutdown.

On the Program Options tab, complete the following fields:

Enter the path and file name of an existing script file or of the file to be created.

Select the scripting language.

Windows Script provides two script engine languages, Visual Basic Scripting Edition and Microsoft JScript.

VBScript: a variation of Visual Basic or VBA (Visual Basic for Applications) used in MS Word and Excel. See the Microsoft website for more information on VBScript.

JScript: a variation of JavaScript or ECMAScript used in web sites, specifically Microsoft's Internet Explorer for web-client scripting. JScript is usually faster than VBScript at performing string manipulations. See the Microsoft website for more information on JScript.

Both languages offer similar functionality and speed, so the choice on which to use is up to personal preference. However, SolarWinds recommends the use of JScript if your script is performing mainly string manipulation. JScript appears to perform faster during string manipulation in most cases.

It is also possible to use additional scripting languages, such as Perl or Python. To use one of the following languages, you must install the Active Scripting engine for that language:

  • PerlScript
  • Python

Python extensions for Microsoft Windows includes access to the Win32 API. For more information see the Python for Windows Extension website (© 2018 Python Software Foundation, available at, obtained on December 20, 2018).

Disclaimer: Please note, any content posted herein is provided as a suggestion or recommendation to you for your internal use. This is not part of the SolarWinds software or documentation that you purchased from SolarWinds, and the information set forth herein may come from third parties. Your organization should internally review and assess to what extent, if any, such custom scripts or recommendations will be incorporated into your environment. You elect to use third party content at your own risk, and you will be solely responsible for the incorporation of the same, if any.

Select the groups of fields that Kiwi Syslog Server can access:

  • When you grant read access to a group of fields, their values are copied into the script variables and are readable from within the script.
  • When you grant write access to a group of fields, their values are copied from the script variables and will replace the equivalent program fields.

Each time a script runs, the available message fields are copied to the script variables and back again upon completion of the script. The copying takes time and uses CPU cycles. To improve script performance, SolarWinds recommends granting read and write access only to the variables used in the script.

For more information about the fields in each group, see Script variables.

To email or save the report generated each time the clean-up task runs, select one or more options on the Run Program Notification tab.

The script

VBScript is modeled on Visual Basic and used mostly by administrators, but it's simple enough that most of us can learn the basics. We'll use Notepad as our script editor. Open Notepad and enter the script shown in Listing B.

This simple script creates an Excel instance, identifies the workbook with the PivotTable we want to print, and opens that file. With the Visible property set to False, you won't see it. Next, the script runs the macro in Listing A that refreshes the PivotTable objects and then prints PivotTable1. After printing, the script closes the workbook without prompting to save, closes the instance of Excel, and sets the Excel object to Nothing.

Save the file as PrintPivotTable1.vbs—you must add the .vbs extension yourself when typing the name. Close the file, noting its location.

ProblemWindows Task Scheduler will not run a.

How to schedule a Python script to run at prescribed times. The method to schedule a Python script depends on your operating system. The general steps for Windows operating systems are given below. For more information about scheduled tasks, see the Windows help. For Unix and Linux systems, see the man entry for cron or crontab. To run Python programs in Task Manager on Windows: In "Programs/Script" input path to python.exe In "Add Arguments"input script file name In "Additional Information" input path to location where file is saved. Once you have created your primary and standby ArcGIS Enterprise deployments, you can automate replication from the primary to the standby using the webgisdr utility, separate properties files for full and incremental backups, and a scheduled task using Windows Task Scheduler. 4 ways to open Task Scheduler on Windows 10: Way 1: Open it in the Start Menu. Click the lower-left Start button, enter schedule in the empty box and select Schedule tasks from the results. Way 2: Turn on Task Scheduler via Search. Tap the Search button on the taskbar, type schedule in the blank box and choose Schedule tasks. Way 3: Open it in the Control Panel.

  1. The meat of this topic shows you how to launch Window’s Task Scheduler on various operating systems Windows 7, XP, and so on. The screenshot below shows the Task Scheduler on Windows 7. There’s a lot stuff you can do with the task scheduler and you’ll just have to.
  2. 21.08.2018 · I have problem with Task Scheduler in Windows Server 2012. I would like to run script in Task Scheduler in which I use arcpy.Unfortunately when I use arcpy in my script Task Scheduler does not work correctly. I have following test script which print current Python version.
  1. The following steps illustrates how to schedule a python script in windows server task scheduler.this can also be applied to any other scripts if applicable: 1. create a new task 2.
  2. Tag: arcgis python windows task scheduler Scheduling Python arcpy script in windows task scheduler. July 17, 2014 arcsdegeo Leave a comment. The following steps illustrates how to schedule a python script in windows server task scheduler.this can also be applied to any other scripts if applicable: 1. create a new task. 2. under “General” tab setup the general task scheduler description.
  3. Scheduling a Python script to run at prescribed times. How to schedule a geoprocessing script to run at prescribed times. Scheduled Tasks. Steps: The method to schedule a script depends on your system. For Windows XP. Click the Windows Start menu, point to Control Panel, then double-click Scheduled Tasks. If the control panel is in category view, click Performance and Maintenance and.

TutorialUsing geoprocessing tasks in Desktop.

How To: Run a model as a Windows scheduled task Summary. Instructions provided describe how to call a custom model from Python and run it as a Windows scheduled task. Another method for automating the geoprocessing tasks contained in a custom model is to export the model to a script. However, it is suggested that there is some knowledge of the. The Comments text box allows you to display text in the Windows Schedule Tasks XP or Task Scheduler Vista and Windows 7 window the text doesn't appear in the output. You can specify when and how often you want the geocoding job to execute in the remaining screens of the Address Coder Scheduler wizard. Task Scheduler. Once you have successfully built up your Python script to call your model, the next step would be to automate this script in Windows Task Scheduler. When creating a task there are a couple of key parameters to look out for: Ensure the task is "Run whether the user is logged on or not" and "Run with the highest privileges". The workforce assignment script can be used to create new Workforce for ArcGIS assignments from report features that exists in other feature layers on a regularly scheduled interval. This script can be scheduled to run as frequently as you want using Windows Task Scheduler, but only one instance of the task can be running at a single time.

1 Answer 1

Commentary on this question: Looking over this post I observe that your job was originally running as 'sa'. It appears that the service account for your SQL Server was not given rights to the necessary file shares.

This is apparently what led to the job looking as if it were "Running" forever. Of course, nothing was actually happening.

It is a best practice to withhold giving the SQL Server service account rights to any non-essential folders. This helps keep the SQL Server environment from being exploited for unsafe activities. (Much the same reason that the xp_cmdshell stored procedure is disabled by default.)

When you switched from sa to an account that had the needed rights to the file system everything worked. Which was, of course, the right thing to do.

Scheduled SQL Agent jobs do sometimes hang (but look like they are still 'running') for a long time. Likely this is usually due to external issues, such as not getting access to file system.

As long as the SQL Agent believes the job is "running", it will not try to start the job again.

5 Answers 5

My workon.bat script wouldn't set Env properties properly but this final command worked in Task Scheduler:

cmd /C c:/Users/name/Env/workon_name/Scripts/activate.bat & python

You create a Windows batch file e.g. MyProgram.bat with the following content:

Make sure you replace YourEnv with a conda environment that you set up before.

You can start the batch file from your Task Scheduler, no additional arguments needed.

Alternatively, to avoid the pop-up window I let the Task Scheduler call a three-line MyProgram.vbs file instead which calls the above batch file like this:

It is a bit awkward to always have three files (what would you expect with Windows. ) but I use the same names for the files, so it's OK. I'd be happy to hear a better solution.

What if you create a batch file, e.g. test.bat , that first activates your virtual environment, then runs your python script? Something like:

Then have that script run from Windows Task Scheduler.

In your script, I would also suggest making the envscriptsactivate part not depend on where the script is run. i.e. make it an absolute path.

you can create it in the command line using schtasks and specifying the path to the python executable inside your virtual environment directory

alternatively, you can use the task scheduler GUI with Action: start a program Set the Program/script: to the python executable in the virtual environment path, and add the python script in the Add arguments (optional): field

For example, I'm using conda, with an environment call MSSQL-ETL-ENV. The path to python would be

When you are directly calling the python.exe file in the virtual environment, you are indeed indirectly activating the virtualenvironment .

When you type .envScriptsactivate , you are just changing the path variable, such that the path to your Lib directory which contains the libraries installed in your virtualenvironment to occur first. As a result when python searches for those libraries it finds these libraries in the virtualenv first and uses them.

Running Python script in Task Scheduler- Script will not run - Geographic Information Systems

I have setup a task using Task Scheduler that I would like to use to launch a batch file at a certain time each day. The batch file works correctly when launched manually and the task also works correctly when the option 'Run only when user is logged on'. However, as soon as I mark 'Run whether user is logged on or not' using the Administrator login, the task returns a Last Run Result of (0x1). This happens when trying to launch the file on demand or when it is scheduled at it's daily time to run.

From some research I have done, I don't believe I should see the actions of the batch file and the program that it launches when this option is marked, but I know it is not running correctly in the background due to the fact the log files are not generated from the task it is to complete. I have marked 'Run with highest privileges' and also entered information in the Start in field under Edit Action with no quotes. The history logs show that the task successfully finished, despite the lack of the Last Run Result code and no log files being generated. I have also verified the user being added to the Log on as a batch job option and that there are full permissions to the files (all on the local machine).

Does anyone have any insight to what I could be missing? If helpful, i could post the history logs as well.

All replies

Thanks for the reply - yes, we have set this user up with this user right, but unfortunately to no avail. I'm starting to think that it may be related to the program that is trying to launch and the process it is trying to run instead of the Task Scheduler after testing some more, so I'm planning to do some more research on that.

Thanks for your response however!

I had a similar issue today when I enabled "Run whether user is logged in or not" on a task that runs overnight. The task was configured to run a batch file with a simple copy command in it. After I enabled "Run with highest privileges", the task ran successfully.

Also remember that the user account you are using for the task has the privileges necessary for the programs in the batch file to complete successfully i.e. if a command to copy something to a server is ran with a user account that exists on the local machine, but not on the server you are copying to, the task will fail silently and may or may not report a result. The same will happen if the username on the local machine and the server is the same, but the password is not.

Is Microsoft ever going to a) publish a fix for this or b) give a comprehensive solution for it? They seem to ignore it. I have done everything in every forum thread I've found to fix this and nothing works. It's a simple batch job that works with my personal account but no other. It accesses local files and a WinSCP upload. The user is in local administrators. It has batch logon privileges.

I've tried running the WinSCP directly with the same results. 0x1.

Could MS at least explain what return code 1 is? Is that the really useful "unexpected error?" If it's a permissions issue, shouldn't it state that instead of claiming to have finished? Now I have to update this job every time I change my password and I have no idea what will happen if I should leave the firm.

This is very poor design and even worse documentation. Support by forum should be illegal.

Check your relative paths in the batchfile. If you are using drive letters that points to a network drive. (drive that the is assigned to the user when logged on) then you wont be able to run the task with "Run whether user is logged in or not".

To use "Run whether user is logged in or not" you need to use UNC paths or point to the physical disk (if local drive).

Depending on the program executed in the batch file, it is however not always possible to use UNC paths.

Agrree that MS has total F. up the task scheduler. The log feature is just not usable with error codes like 0x1 or 0xFF. There are better 3. part alternatives.

I have found that entering the directory path to the "Start in (optional):" block for where the script originates works for me. If you put in the quotations around the directory, even though there is a space, within the Start in box I find it doesn't work, so you see I didn't put them in. Check out the screenie ..

I have found that entering the directory path to the "Start in (optional):" block for where the script originates works for me. If you put in the quotations around the directory, even though there is a space, within the Start in box I find it doesn't work, so you see I didn't put them in. Check out the screenie ..

But did not worked for me.

Another thing often forgotten, is to grant explicit directory rights for the execution account. Typically this becomes a problem, if the batch job needs to create a log file or in any other way modify contents of the target folder.

Thanks for tip, I got it to work finally!

My variation - just put the file name under 'Program/Script', no quotes and the directory under 'Start in' as described, again no quotes.

I have found that entering the directory path to the "Start in (optional):" block for where the script originates works for me. If you put in the quotations around the directory, even though there is a space, within the Start in box I find it doesn't work, so you see I didn't put them in. Check out the screenie ..

Thanks worked for me!

One Batch file with a copy command. This file didn’t work with scheduler but it works manually.

One Batch file with a ftp command. This file works fine with the scheduler and manually.

In the scheduler of the copy bath file: filed in the directory in the start in field.

I had this same exact issue.

I later found out that the script I was using to create the scheduled task didn't copy the file that the scheduled task referenced. I felt rather silly.

I had this issue too but the above techniques didn't work for me. I then worked out that the file name of the script was too long, so once I shortened it - it worked :)

In my case, I configured a web server to email me an alert via Task Scheduler when a tester attempted to log in. I was seeing (0x1) appear in the Task Scheduler results pane.

On investigation, Exchange 2010 was treating email from this server as spam.

In the Exchange 2010 Management Console -> Organisation Configuration -> Hub Transport -> Anti-spam -> Content Filtering -> Custom Words -> Allow messages containing these words or phrases:

. I added the title of the email being blocked as a phrase.

Retest from source server. . all then worked for me.

I have the same issue where I have a Task which runs the Powershell script to Compress a whole bunch of bak & trn files from a local drive to create a RAR file using the locally installed WinRAR application. This process with RAR commandline also ensures deletion of all the files added to the archive.

Another task scheduled at a later stage picks the created .RAR file and transfers(MOVE - CUT PASTE) across to another server with UNC path reference.

When I run the script manually as Admin with Powershell, it works fine in both cases, but when attached to the Task Scheduler task, it comes up with the 0x1 error.

  • Run whether user is logged on or not
  • Run with highest privileges
  • Actions -> Edit -> Program/Script : I invoke Powershell and pass the ps1 file as the argument
  • Start in : C:WindowsSystem32WindowsPowerShellv1.0
  • task which is for the copying of the file on to the remote folder is run as this user which has Local Admin rights on both the machine it is running on and the remote server as well.

Any help would be deeply appreciated.

. even added .<scriptfilename>.ps1 in the additional arguments, and tried to run and the result is still the same 0x1 error!

Just FYI, cant explain it. Don't know why, but I re-wrote my scripts that were failing, from scratch. The problem went away.

Initially the batch files would run manually no problem but would consistently fail through the task scheduler. Out of frustration, I deleted them and re-wrote. suddenly no problem! Go Figure.

I deleted the old ones so I can not go back and compare. Obviously something was wrong but I could never find it.

I m facing the same problem in Windows 8.1 task schedular i have tried all the proposed solution mention above but nothing is working for my case.

In my case i m invoking the task from System account where the folder where the batch script resides has full control of System account.

The same scenarion i have checked in Windows 7 but it was working fine in that.

Please advice how to proceed for Windows 8.1.

In the task scheduler, edit the properties of the action and check you have the correct "start in" folder as that is likely to be an issue, even if the folder is specified in the Program/script field

On the General tab, Check the last drop down and make sure it is pointing to correct OS. In my case , it was default set to Windows Vista ,Windows 2008 and my server was windows 2008R2. Once i changed it to Windows 2008R2 , it just worked fine with whether or not user logged in option. Hope that helps!

There are three important options to make sure your task will run: 1 - Create your task using the "Create Task" option instead of the "Create Basic Task" (this gives you more options for the server type, usually the default server will work - Windows Server 2003, Windows XP, or Windows 2000). 2 - Use only UNC paths in your batch files and in the "Actions" Tab. You can map drives on your computer, but you must use the UNC paths throughout your task. 3 - On the "General" Tab, select the "Change User or Group" and add the correct credentials even if you are already signed into the account with the correct credentials. These options should work if you select to run the task when the user is logged on or not. Place a pause at the end of your batch file so you can see any errors and test run the job.

NOTE: if you are trying to connect to an AS400 network folder, open an AS400 session. You do not have to sign in, just start the session.

I tried everything that everyone suggested, but the only thing that I got to work was to put a command in the batch file to output a directory listing.

This makes absolutely no sense at all however, it was the only way that I could get the batch file to run without any problems.

BTW, my batch file was running an FTP script to download files from IBM AS/400.

This was the one that worked for me (thanks You Rocke!)

My bat file would run fine when executed manually, just the task wouldn't run it!

Creating a 'New Task' rather than a 'Basic Task' gives you a Windows 7 option in the server type (which is what I needed in my case)

I also put the path (without quotes) into the 'Start In' box and ticked the 'Run with Highest Privileges' box.

I must say it was rather nice to figure out that (0x1) could mean that the batch file couldn't be found. The batch file I was trying to run had an amperstand (&) in the file name which evidently caused Task Scheduler problems when trying to run it. Meanwhile, I was able to run the batch file outside of TS without any problems.

Tip: If TS isn't running the batch file as schedule, try running it via the 'Run' command within TS, either via the right click menu or the option on the right hand side panel.

Try Changing Server in Configure Box on General Tab of Task. I changed it from Windows vista to windows xp which worked for me :)

I had this issue. How I resolved it was to explicitly state all paths used in the .bat file.

e.g. the code in runTest.bat

I know this issue could be very old but I have had this problem for years using WinSCP and everything I tried I still got the error until I realized just now that this was because there was an error in the script file that is used to run WinSCP. so the task was not being shut down properly so windows would not consider it a success.

At the end of the script I had the following:

The correct syntax should be

See and example of the script below.

Most of the 0x1 error cases that I found are from the path errors. So always use a full path in your .bat file
(ex. cscript "test.vbs" to cscript "c: est est.vbs")

One more important note is you'll need to add your path of the .bat file in "Start in (optional):" - if you don't, it won't just run when you logged off. See this tutorial video:

I've had the 0x1 error appearing when attempting to run a PowerShell script via Task Scheduler.

Originally, I had set-up the actions via this link:

I noticed another PowerShell script which another Admin had set-up successfully. Once I set mine up the same way, it worked:

Action: Start a Program

Program/Script: PowerShell.exe

Argument: -File "<<local path to PowerShell script including script name>>"

Start In: <<blank>>

For me it was a bad character from copy/paste. The path originally came from another machine running a similar scheduled task. Kept getting 0x1 on the new machine.

I pasted the problematic task string into powershell, and there was a funky extended ascii/utf character in there instead of a an actual space. So I just re-typed the space character in the dialog box and it worked fine. So if all else fails, re-type the path/start directories in your "Edit Action" dialog box because they may "look" ok to you but are actually bad chars.

Try running the script manually - I've just had the same problem and it ended up being due to a missing > that I overlooked after editing the script for added functionality

It was only when I ran the script manually in a powershell session that the error was revealed

Or log the script activity to a log file

Action: Start a Program

Program/Script: PowerShell.exe

Argument: -File "<<local path to PowerShell script including script name>>"

Start In: <<blank>>

I have a problem that has not been reported by anyone so far.

I have setup task scheduler jobs on a server where my login belong to administrators group on the server. All the jobs created run .bat scripts. These jobs are setup to run every minute. the .bat scripts run fine when I double click them.

I get 0x1 error when I set it up to run under my login but runs fine when I set it up to run under Administrators group, as long as only I am logged in or no one from Administrators group are logged in. The Administrators group includes many other users. The trouble starts if anyone from Administrators group logs in because all task scheduler jobs starts running under their logins and fail because of the privileges.

I have tested every possible solution suggested above and nothing has worked. Would appreciate if any one knows a solution to this.

This seems to have worked for me. The message did not refresh in the Task Scheduler even after I changed the settings and reran the job manually a few times.

It looks like the Last Run Result field was cached in some strange way.

When executing a Powershell script through Task Manager (or running a task with sqlps which is essentially the same thing), I've discovered that in order to prevent the task from ending with 0x1 return code, once needs to add -querytimeout 0 to the task action arguments.

It has to do with Task Scheduler and tasks that are taking a longer time to execute (for example a minute or more).

Souvik Banerjee. MSBI Lead, Zensar Technologies

We are both trying to do the same thing with WinSCP. The problem that I found was that the Administrator accounts, both Domain and Local, are not allowed to be the "Run As" account in Scheduled Tasks anymore. Need to create a Service Account, give the account "Log on as batch job" and "Log on as a service" in Local Security Policy>Local Policies>User Rights Assignment, create a service that runs as the user to create a local profile in UsersServiceAcctName profile folder. You have to run/Start the service once for the local profile to be created. It seems that CMD.exe requires appdata folder for the user that the batch file is running as.

Also, set the Scheduled Task to "Run with highest privileges". General tab of the task properties.

For the Action properties of the Task, put the full path to the batch file in Program/script: box including the batch file name. In the "Start in (optional):" box, make sure the local path (or full UNC path if not local) for the folder containing your batch file is entered there. It's not optional! NO QUOTATION MARKS! If your path has spaces in folder names, you will have to change the folder names or move the batch file because the "Start in (optional):" box can NOT have quotations. If your batch file has spaces in the name of it, then the "Program/script:" box will have to have the whole path surrounded by quotes.

Also, make sure that the path to the batch file has Security Rights setup for the Service account that you create. Then consider the action of your task. if it is moving a file, then does it have rights to do that at the source location and at the destination location?

Running Python script in Task Scheduler- Script will not run - Geographic Information Systems

A simple shell script to shutdown a Synology NAS if no authorized client is online. The main purpose of this script is to reduce power consumption.

The NAS can be used to store media content. If you want to access them, the system is switched on manually or by wake-on-lan. The system is in operation during this time. But what happens if the client is no longer online? The NAS continues to run and goes into standby - but it usually continues to consume power. This script helps to turn off the system completely and thus save power since media access usually only has a comparatively short duration. The next time the system is accessed, it is started again manually or by wake-on-lan.

The script also has the advantage that no inflated packages need to be installed on the NAS that could compromise the security or stability of the system. If you want to keep the system as clean as possible and know which features are running on the system, open source and a shell script is just what you need :)

At definable intervals, all systems of the current network segment (e.g. 10.0.0.x) are checked whether they are reachable. If a system could be detected, this is compared with the list of systems that were defined to avoid a shutdown. If no system could be found, the system continues to attempt to find systems for a defined period of time. If no systems are found during this time, the system is shut down. A named system found resets this check.

  • Bash Script (easy setup)
  • Out-of-the-box usable - no installation of other toos required (no system modification!)
  • Use of simple functions from Busy Box (no dependencies)
  • Connection to IFTTT (optional)
  • Logging
  • Self-inititalizing (with default values if no config is specified)
  • Self-restarting (on code changes)
  • Self-reconfiguring (on config changes)
  • Self-initializing of config file and missing config options
  • Warning times
  • Support of beep output to the internal NAS loudspeaker
  • Lightweight python webserver to shutdown NAS promptly
  • Alexa integration (via IFTTT webrequests)
  • simple solution
  • Use on different NAS possible
  • easy maintenance
  • Expandable
  • Support for electricity saving

On some systems, a system in standby continues to respond to pings from this script. These systems prevent the NAS from shutting down. This is especially the case for Mac systems that use Power Nap or do not use Safe Sleep Mode. Please check how systems behave in standby mode before using the script productively.

  • NAS (Synology with BusyBox like linux tested and verified on Linux xxxx 3.10.105 #24922 SMP Wed Jul 3 16:35:48 CST 2019 x86_64 GNU/Linux synology_cedarview_xxxxx)
  • own volume (recommended)
  • SSH access (recommended)
  • Scheduler (e.g. Cron) with possibility to execute shell scripts

  1. Copy shell script and configuration file to shared volume (e.g. control )an your NAS. Remember the path to the shell script (e.g. /volume1/control/syno-autoshutdown/ )
  2. Rename the default configuration file to autoshutdown.conf or autoshutdown-(hostname).conf where (hostname) is the host name of your NAS. This is helpful if you have multiple NAS where you want to share files but separate configurations.
  3. Proceed with scheduler configuration.
  1. Login to NAS.
  2. Define a new scheduled task at system start up to execute these commands

You must run this task/script as root, as some commands are not allowed as users. The task must also be defined to start at boot time so that the execution of the script can be ensured.

  1. Define a second task to be started manually. This task help to deaktivate the shell script if you don't want to be interruped by a system shutdown (e.g. partition cleanup/repair if no client system is online)

The script must also be run as root, but the execution can be set to inactive (and thus manual). This task is only used to temporarily terminate a previously executed script or several instances of the script. If the autoshutdown script should be started again, the NAS does not have to be restarted, but the first task can be executed.

IFTTT (Notification) (optional)

  1. Create an account with IFTTT (
  2. Log on to IFTTT at the backend
  3. Click profile image and run "create" in menus
  4. Define the "if" statement
  5. Search for and select "webhooks"
  6. Select "receive a web request"
  7. Name your event (e.g. syno_event )
  8. Define the "that" statement
  9. Search for and select "notifications"
  10. Select "send a notification from the IFTTT app"
  11. Define the message <> (occurred <>)
  12. Click "create action"
  13. Define magic key to config file (IFTTT_KEY) *)
  14. Define name of event (see 7.) to config file (IFTTT_EVENT)
  15. Done.

*) Your magic key is viewable via -> profile -> my services -> webhooks -> settings -> URL

In addition to the bash script, a python script is provided, which optionally starts a web service that allows the user to shut down the NAS system immediately via HTTP request.

When the web server is started, a unique UUID is generated which can be used to control the web server. If the correct URL can be called by the user, the server is immediately shut down by calling another (confirmation) link.

The URL is protected by the following features by unintentional or deliberate calls:

  • Free choice of the external and internal port on which the server listens
  • Free choice of the component of the URL that is to be used for the shutdown
  • Creation of a new and unique UUID at each start of the web server

Calling up the website allows a further confirmation of the shutdown:

If the button shown in the picture is confirmed, the system will shut down immediately.


The web server has been supplemented by a magic key and magic word. With the help of these two very individual details, the web service can be controlled via a voice command and a Werrequest without prior consultation.

These data have been additionally integrated to enable static data, so that the security of the dynamic keys for normal access can be maintained.

Two factors are required for a successful call: the magic key, which is generated automatically if it is not already specified. And also a magic word, which can be freely assigned by the user. Both specifications are combined and result in a unique path specification for the web server. If this path is called, the system shuts down immediately.

To make this address callable via voice commands, the following steps are necessary (Alexa and IFTTT are examples):

  1. Add an Alexa trigger (or an other speech trigger)
  2. Select the Alexa-Webhooks action (
  3. Select "Use Alexa with hook automate" (
  4. Name your trigger
  5. Define phrase Alexa will listen to

Your public ip and port depends on your router configuration. Have a look at section Webserver (shutdown) for more details.

The next time you ask Alexa "Alexa, trigger shutdown Synology" the device will be shut down.

Placeholders can be specified for messages in the configuration file. The following placeholders are permitted:

Placeholders can be specified for filename in the configuration file. The following placeholders are permitted:

File containing the hash value of its own running configuration (*.config). This hash value is compared to the hash value of the saved configuration file. If the values differ, the configuration has been changed and the script reads the configuration again in the next cycle.

File that contains the process ID of the running instance of the script.

File containing the hash value of a running shell script. This hash value is compared to the hash value of the saved shell script. If the values differ, the shell script has been changed and the script must be restarted. The running instance is terminated in the next cycle.

The following sources have made this project possible, as the authors have provided impulses for the further development of this project.

Watch the video: PYTHON+MySQL - ΜΑΘΗΜΑ 1 - ΣΥΝΔΕΣΗ και ΕΚΤΕΛΕΣΗ ΕΡΩΤΗΜΑΤΩΝ - 25 - Εκτέλεση Ερωτημάτων