Task scheduler multilanguage parameter - windows

I'm using the schtasks command from C# like this:
schtasks /create /sc ONCE ...
This works fine until i get a machine with a other language. For example, a german windows wants something like this:
schtasks /create /sc EINMAL ...
I wonder how anyone on this planet can write a working command line for machines with different languages. (BTW: what is the reason for making a command line tool schtasks with language-dependant parameterss?)
So there are two questions:
1) How can i write a language-independant command line for schtasks ?
2) Is there a way to set the command line processor's language to english?
EDIT:
Sorry - i missed something:
- I use .NET framework 2.0
- The target systems are Win7 and also XP. Therefore i can't use the TaskScheduler 2.0 API.

You can use Microsoft.Win32.TaskScheduler for this.
Please see the detailed answer by Dmitry here: https://stackoverflow.com/a/7394955/16522

Related

Windows 10 task scheduler errors "task not supported"

After updating to W10 I think task scheduler worked normally. Today I tried to open %windir%\system32\taskschd.msc /s and got a long list of errors that said "this version of task object is not supported or invalid" all being tasks made in W7 I guess. After escaping the messages all kinds of tasks "are not there" anymore, although when opening taskschd again the same thing happens. I am working on it and I succeeded in importing one of those tasks and comparing the xml. Hope someone has already found a good solution. Will update my findings.
You can solve this using cmd:
C:\>schtasks /Query > tasks.txt
This command prints all configured tasks into a txt on your C: drive (or your current working directory). I used cmd as administrator I think that's neccessary. Afterwards you can delete all tasks which are wrong:
C:\>schtasks /Delete /TN "\ASUS\ASUS AI Suite II Execute" /F
ERFOLGREICH: Die geplante Aufgabe "\ASUS\ASUS AI Suite II Execute" wurde erfolgreich gelöscht.
I hope that works for you too.
Regards
Steffen

Can't find file when trying to open via command line.

I wonder if someone can help, I want to run a schedule task and I discovered that I can put a command line command in there, which is good.
What I need to happen is for a PHP file to run a bit like a cronjob.
The system I am using recommends I do the below but it's not working, now I believe it's due to the file being on E and not C, but I have no idea how to correct this, if anyone could give me some pointers that would be great.
"C:\Program Files (x86)\PHP\v5.3\php.exe E:\pathtofile\tasks\frequently.php -f"
System info is win 7
You've got your quote characters all fouled up, but there are separate entries for the various parts of the command in Task Scheduler.
Try this:
When creating the new task, set the Action: dropdown to Start a program.
In the Program/Script: entry, use
"C:\Program Files (x86)\PHP\v5.3\php.exe"
In the Add arguments (optional) entry use
"E:\pathtofile\tasks\frequently.php" -f
I believe what you want to know is how to schedule the php program to process a php file via command prompt (Note that the -f needs to come immediately after the php.exe:
schtasks /Create /tn MyJob /tr #"C:\Program Files (x86)\PHP\v5.3\php.exe -f E:\pathtofile\tasks\frequently.php" /sc onlogon

running an R script in batch mode without the command prompt popping up

I have a scheduled task (using SCHTASKS) to run every minute.
SCHTASKS /Create /SC MINUTE /MO 1 /TN READSCALE /TR "Rcmd BATCH --vanilla --slave q:\workspace\waga\readScale.R"
On each run command prompt window pops up. It's slightly irritating and perhaps a potential health hazard for people with epilepsy. In Java, one can use javaw.exe (see this thread) that doesn't pop up a command prompt. Is there an equivalent for R?
Kudos to serverfault.com, where some people solved the problem using no external tools at least in two ways. Here's the thread.
First is to write a .vbs script. This requires some knowledge of this scripting language and may not be appropriate for everyone.
The second method is to run the task (as I'm doing) under SYSTEM (and not the currently logged in user).
Ah, Windows... There is a tool called hstart which may help here.

Windows scheduled task

I have created a Windows 7 scheduled task:
schtasks /create /tn MyTask /tr C:\temp\test\MyScript.bat /sc MINUTE
Problem is that this task seems to get executed by Windows but I think it can not find the running BAT script. There is a quick flash window but can't read what the problem is.
On the other hand, if I place the script under Windows/System32 everything works fine.
schtasks /create /tn MyTask /tr C:\windows\system32\MyScript.bat /sc MINUTE
Anyone knows why the second schedule task works compared to the first one?
This whole thing is part of installing a program on a windows machine from a web page. So I would like to have the BAT file installed in its correct directory and not the System32.
Thanks for you help.
C:\temp is a temporary directory may be cleaned by the OS periodically. So you should first check to make sure that batch file is actually there, and then consider moving it to a more permanent location.
Second, have you tried running the task manually from its intended location? That should help you see what the output is. You can also add PAUSE to the bottom of the batch file (as suggested by commenters) to ensure that it stays up long enough for you to see the output.
Some likely problems are:
You're using some resource which is in %windir% via a relative path, which won't work when the batch file is run from a different location.
The scheduled task is running as a different user and doesn't have the proper permissions.
The task is doing something that requires elevation, but the task itself is not set to run elevated.
IIRC, schtasks does not load user profile: Most probably a variable is not set that you need.
Try to prepend your command line (after /tr) with cmd /K. It will make the console kept alive.
HTH

Schtasks.exe does not accept blank spaces when giving file path

I'm rolling out a new python script at the office and to make this run smooth I also made a batch file which will install it, and make it run on user logon.
I use schtasks.exe to schedule a task for this, so here is what i'm trying to run
schtasks /create /TN "fooname" /SC ONLOGON /TR "C:\foo - bar\fooscript.exe" /Delay 0005:00
The error I get is 0x80070002 which means the file cannot be found. After exporting the task I created, I can see that it separated the first and last bit of the path into
<Command>C:\foo</Command>
<Arguments>bar\fooscript.exe</Arguments>
I have tried microsofts own help article, but no luck. I wish to run this without any arguments regarding fooscript.exe.
As Magoo pointed out I was able to use the short name of the folder, which can be accessed with a
dir /x
tossing back a name like "FOO~1". Using this in my path made it work.
Thank you!
Sorry old thread but just found a workaround better than these here. Put the dir name in a prompt variable and then use the var in the command.
SET fname="c:\path with spaces\target.exe"
SchTasks [args] /TR %fname%

Resources