Remotely Starting a Batch File - cmd

SCHTASKS /create /S $strComputer /tn "David\Start Gecko" /tr
"'C:\eQube-Tools\Batch and Registry Files\gecko.bat'" /sc once /sd
01/01/2099 /st 01:00 /u Boss /p *password* /RU SYSTEM
pause
SCHTASKS /run /S $strComputer /tn "David\Start Gecko"
So, I have a problem with running the batch file this creates, it says it's running on the task scheduler on the remote pc, but nothing happens. But the odd thing is: if I locally create a "basic task" it runs fine both remotely and running it by hand at that pc.
My question is there any way to have it know you want to create a "basic task" I've looked at the switches but can't find anything for /create, I also tried the /xml but this is something I plan to create, use then destroy so simpler the better.
** the reason I'm using SCHtasks is because I had a lot of issues with redirect errors trying to run it directly using powershell.
Specs
All win 7 WORKGROUP
All have matching Admin Accounts with matching password
Firewall set to allow remote sch tasks
Batch file is on remote pc
the batch file I'm trying to run
#echo off
c:
cd \eQube-Tools\Batch and Registry Files
start virtualhelpscreen.exe
:top
c:
cd \gecko
timeout 12 /nobreak
gecko.exe
cls
goto :top

SCHTASKS /create /S $strComputer /xml "filesavedtomainpc" /tn "David\Start Gecko"
one issue left is it not forcing full screen like it does when you run the batch file but that might be down to the program, for now the question I asked is answered.

Related

I cannot shutdown clients from windows server 2012?

I have few windows 7 clients whom i need to reboot from windows server . i tried to setup a group policy
Action-create ,Name- Auto shut ,Account-NT/System,Action-shutdown.exe Trigger:4.00 AM :daily
This was applied for OU but it fails to deliver Can someone points where did i went wrong here and how to do it properly??
Have you consider using the command shutdown with the /m switch?
You can create a batch script will all machines you want to reboot
#echo off
for %%a in (computer1 computer2 computer3) do (
shutdown /r /f /m \\%%a /t 30
)
and create a task that executes the script.
schtasks /create /SC DAILY /ST "04:00" /TN "task-name" /RL HIGHEST /TR "script-name"/F

Run Scheduled Task in Windows Batch File?

My issue exists in another question here. I'm wondering whether it's possible to activate a scheduled task on one server from the command line of another server. I do not want to use psexec as it is known to be an enabled of malware and viruses. Does anyone know if this is possible?
You can use the the commands below to stop and start tasks remotely.
Stop:
schtasks /end /s <machine name> /U Username /P password /tn <task name>
Start:
schtasks /run /s <machine name> /U Username /P password /tn <task name>

Check if windows password is correct with batch

How can you check if a Windows password is correct with batch. Using runas you could check if you get an error after typing your password but I want to know how to do it automatically by adding the password into the batch file (I know its not secure and I know you can save credentials with runas). Thanks in advance!
Depending on what OS, user access, and how your machine is configured, you could issue a net use to the machine itself on a particular drive letter.
Eg:
Net use U: /delete /y
Net use U: \\machinename\c$ /user:machinename\username password
You could check if the U: drive ended up mapped to verify it worked.
This is not a good idea security-wise and also may not work on systems with simple file sharing enabled.
If you have permissions to create/delete windows scheduled tasks, you could always use SCHTASKS:
SCHTASKS /CREATE /RU "Username" /RP "Password" /TN CREDCHECK /TR NOTEPAD /SC ONSTART
IF %ERRORLEVEL%==0 (ECHO Valid) ELSE (ECHO Invalid)
SCHTASKS /DELETE /TN CREDCHECK /F
There's probably better values for the /TR and /SC parameters, but you get the idea

Windows XP batch command schtasks doesnt' run a remote script

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)

how to schedule a non-hidden task with schtasks?

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.

Resources