I am trying to schedule a task with cmd prompt.The command that I am running is:
C:\Windows\system32\schtasks.exe /CREATE /SC ONLOGON /TN "mytask" /TR "C:\samp.txt" /RU "NT AUTHORITY\SYSTEM" /RP /F
The task is showing in task manager with username as SYSTEM ,and its status is Running with code 0x41301.But it(samp.txt) is not showing in desktop.
The same command if I am replacing the "NT AUTHORITY\SYSTEM" with currently logged on user then it(samp.txt) is showing on desktop.
How can I make the task to display on desktop with /RU "NT AUTHORITY\SYSTEM"
Did you try to add /IT ?
This is the only option which may allow you to display something on the active session using scheduled tasks. However, I am not sure that Windows will allow to interact with the desktop of another user.
Edit : You may use /RU BUILTIN\Users /IT, so any user will be able to run it interactively. What is you constraint on /RU system ?
If your goal is to display the samp.txt file content when a user logs on, another solution is to put the samp.txt in the startup folder of the "all users" start menu : C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
could you try with psexec ?
your command will be something like :
PSEXEC -i -s -d -w c:\ notepad.exe samp.txt
Related
I'm creating a task in windows Task Scheduler via command line using following commmand -
schtasks /Create /SC ONSTART /TN "MyTask" /TR "C:\Program Files (x86)\MyApp\MyApp.exe" /RL HIGHEST /NP
Is there any parameter to schtasks /create to uncheck "do not store password" under "user is logged in or not"?.
Also, is there any parameter to uncheck "Stop task if it runs longer than"
I tried following Microsoft Task Scheduler Reference. But, couldn't get the result needed.
Remove /NP from the command. I can get the desired output.
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.
I'm trying to create a batch file in order to run automatic scripts on several remote PCs.
My main machine should be able to connect to any remote PCs and set a local scheduled task.
The batch file uses these commands:
schtasks /delete <--- remove any previous version
/S \\10.1.2.3 <--- the remote PC's IP
/U theAdministrator <--- the username to access the PC
/P MyPassword <--- the password to access the PC
/TN MyTask <--- task name
/F <--- don't ask, just do it option
schtasks /create
/S \\10.1.2.3
/U theAdministrator
/P MyPassword
/RU theAdministrator <--- the username to execute the task
/RP MyPassword <--- the password to execute the task
/SC dayly /MO 1 <--- run every day
/TN MyTask
/TR C:\task.bat <--- the script to run on the remote PC
When I launch the first /delete command everything works, but the second returns a warning:
"task has been created but probably it will not run because it hasn't been possible to set the account information" (I'm sorry if this is not the exact error message but I have to translate it by myself)
I'm sure that username and password are correct because the /delete command is OK, and also /create one creates the task, even if it doesn't run.
Therefore the problem should be with /RU and /RP options...
Solution:
I wasn't able to execute the command itself without this error message, anyway I've reached my aim and found two different options:
The simplest way using the AT command:
AT \\10.1.2.3 12:00 C:\task.bat
It has no problem but needs to have specified an hour to run; this means if you want the task to be executed immediately you'll have to chatch %time% variable.
This option also doesn't allow to set an user to run the task (I've tested it as Administrator and the task was set to execute as NT AUTHORITY/SYSTEM)
The full featured way using PsTools:
Passing the schtasks /create command to PsExec
set command=schtasks /create /SC dayly /MO 1 /TN MyTask /TR C:\task.bat /RU theAdministrator /RP MyPassword
PsExec \\10.1.2.3 -u theAdministrator -p MyPassword %command%
NB.
The target IP, user and password to access the remote PC have to be set within PsExec command, therefore you don't need them on schtasks.
The script task.bat already exists on root C:\ of the target PC.
Are the PC's on a domain??
I've used schtasks on a domain before, and it works without the /ru and /rp. I just used /u and /p as the username and password of the machine that I was scheduling the task on.
Never tried it on standard workgroup/homegroup machines though.
You may also want to look at this, and make sure UAC is off on all remote machines, as thes could cause issues later.
Edit
I've just tried from one laptop to another (no domain involved).
These two lines work (in CMD, so should work through batch) for me
schtasks /delete /S \\xxx.xxx.xxx.xxx /U USERNAME /P PASSWORD /TN MyTask /F
schtasks /create /S \\xxx.xxx.xxx.xxx /U USERNAME /P PASSWORD /TN MyTask /SC once /st START_TIME /it /TR c:\test.bat
Things to note are;
- Obviously, replace the x's with the IP you need, and the USERNAME and PASSWORD with relevant data
- I used /sc once /st START_TIME, and not your /sc daily /mo 1, but that shouldn't make a difference
- I've added /it which (taken from CMD) "Enalbes the task to run interactively..." (in my experience, not using it has cause problems)
- The user on the laptop I was scheduling the task for does not exist on the laptop I ran schtasks from
- The user on the laptop I ran schtasks from does not exist on the laptop i was scheduling the task for (so users not existing on client/host does not matter)
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
I've been trying to create a scheduled task from the command prompt. The task is created, but it runs hidden. Is there any way of running it in a non-hidden way? The process is very long and I would like to see what is going on...
I'm running it on a Vista, but the task is meant to run on pre-vista OS as well...
SCHTASKS /Create /RU \"NT AUTHORITY\SYSTEM\" /SC DAILY /ST 00:00 /TN Backup /TR \"C:\Sis\Backup\Backup.vbs\" /F /V1
Tks,
Filipe Scur
Running as NT AUTHORITY\SYSTEM means it is a system task and will run hidden.
Try run as a different username.