How to programmaticaly create task on windows - windows

There are some programs which can create some tasks for windows.
I need to create an exe file or batch file which will run, take some xml file(exported task by windows task manager) and create task.
The program Elevated Shortcut can do what I need, but i need to do the same with some command or by running the exe file, no user interface.
The commands like
schtasks.exe /create /tn MyTask /xml "C:\MyTask.xml" /f
NOT WORKING.
Hope someone can help.
Thank you.

Solved. To add the task the app must have administrator rights.

Related

Windows schedulded task execution

I created a schedulded task in windows in order to launch a .bat file at start or on remote sollicitation. I created it through command lines from my remote computer (I couldn't do it from the target computer itself, it raised an error ... ).
I used the following command :
schtasks /create /S \\<remote_pc> /U <my_login> /P <my_pwd> /tn Launch_simulators_on_start /sc ONSTART /tr C:\Users\SIMULATEUR\Desktop\StartAll.bat
I can launch this task from the computer itself or remotely, it works as expected.
However, I would like it to launch on computer restart and when I restart the computer, nothing happens.
Is there a particular option that should be set at creation ? if so, online help is not explicit
has anyone been through this kind of issue ?
thank you
Alexandre
Create a New trigger with a condition of 'At StartUp'. This will run the task on every start\restart of the machine.

How to create a Windows Service from .vbs file?

I have a .vbs file which I execute using cscript. Now that the script is sable; I want to run in background all the time.
Hence, I want this .vbs file to run as a service.
How do I create (install) it?
Scripts are usually not prepared to run as a service (they don't provide the interfaces required for managing the service). You're probably better off creating a scheduled task that launches your script at system boot (or at logon).
schtasks /create /sc onstart /tn "name" /tr "cscript.exe C:\path\to\your.vbs" /ru SYSTEM

scheduling task from the command line + windows7 + spaces + arguments

I am trying to become familliar with add task to task scheduler via the command prompt. I seem to be having difficuly with spaces.
This command works successfully in creating a task:
schtasks /create /tn \Daily\SOTask /tr "C:\Users\User Name\FolerWhereScriptIs\vbsScript.vbs" /sc daily /mo 1 /st 08:50
SUCCESS: The scheduled task "\Daily\SOTask" has successfully been created.
However, when I open the properties of this task in task scheduler i see in:
Program/script: C:\Users\User
Add arguments(optional): Name\FolerWhereScriptIs\vbsScript.vbs
Start in(optional): empty
this is obviously not what I want. ideally I would like:
Program/script: C:\Windows\System32\WScript.exe
Add arguments(optional): "C:\Users\User Name\FolerWhereScriptIs\vbsScript.vbs"
Start in(optional): C:\Users\User Name\FolerWhereScriptIs\
How do I achive this from the command line?
This lists all tasks in the Daily folder (so I can see the one I jst created)
schtasks /query /TN Daily\
NOTE: To get this far I ahve gotten help for here and here
EDIT1 I found help here and it mentions using a /V1 flag but todate I cannot get to work. Another Option would be to use XML, whcih I will investigate again. For now I will use the command for setting up my schedule and then go into task scheduler to set the Start in(optional): in directory.

Creating a batch file to run a command on command prompt as administrator

I would like to create a batch file in order to run a windows command on command prompt as administrator whenever I start the PC.
For example I would like to run the command prompt as administrator and run the command Ping 8.8.8.8 on startup of windows.
Can anyone please explain the full procedures with snapshots?
Thanks in advance
M. Ashraful Haque
You could try something like this create another batch file and add the below command it will run it as the user you specify
#echo off
Runas /env /user:PCNAME\Administrator test.bat
Or
you can add your batch file to the Scheduled task list link below on how to do this. In Scheduled Task you can set what account to use and when it should run.
Change when it runs in create task go to Triggers tab click new and change "Begin the task" to start up
Create Scheduled Task
First with SCHTASKS you can create add a batch file to run as a service and you can give the top privileges , example:
SCHTASKS /Create /TN "Ping My Web Host" /SC HOURLY /TR "C:\services\pinghost.cmd" /RU username /RP password /RL HIGHEST
Here's the documentation documentation and here
And this you'd wanted to read this.

How to schedule a task with the command prompt?

I want to know how to schedule a task using the command prompt.
Now I know you can probably find this on the internet, but I haven't found what I've been looking for.
The problem is that the operating system I have to do it on is in Swedish (Windows Server 2003 in Swedish).
It needs to run a program located at: 'C:\Documents and Setting\Administratör\Skrivbord\Midnight.exe'.
It should run around midnight, every day.
Does anybody know how to schedule this in cmd?
I do have administrator rights, so privileges shouldn't be a problem.
Just use schtasks windows utility in a .bat file or manually in CMD :
schtasks /create /ru Admin /rp paswd /tn "daily work" /tr "C:\Documents and Setting\Administratör\Skrivbord\Midnight.exe" /sc daily /st 23:55:00
Swedish should'nt be a special case :)
off course /ru is the username which we'll be used to run the task
You want the AT command to put an entry in the scheduler service TechNet on AT

Resources