Page 1 of 2
[SOLVED]Switches and parameters for creating tasks
Posted: 12 Oct 2013 23:30
by serverdelux
Hi, I want to use the correct switches and parameters to create a task that runs a batch file silently
It will be called 1.bat and run as onlogon?
SCHTASKS /Create /tn "1" /tr %Systemdrive%\1\1.bat /sc onlogon /ru ""
Any help with a task that will run a batch silently would be appreciated
Re: How to pick which switches and parameters for creating t
Posted: 13 Oct 2013 00:46
by foxidrive
If it triggers UAC then you can't get around that, otherwise someone could do what you are doing and get malware to install easily.
Re: How to pick which switches and parameters for creating t
Posted: 13 Oct 2013 11:25
by serverdelux
foxidrive wrote:If it triggers UAC then you can't get around that, otherwise someone could do what you are doing and get malware to install easily.
Hi, thanks for the reply. It's not triggering UAC, just need a task that runs a bat silent as I don't want to see batch console flash at onlogon. No interaction is needed from user is needed as I'm just backing up my current theme and/or wallpaper
Would appreciate any help on the task please because I don't quite understand the appropriate switches, etc to run the bat silent
And if there are multiple ways to write the task I am curious about that?
Thanks for any further help
Re: How to pick which switches and parameters for creating t
Posted: 13 Oct 2013 13:17
by ShadowThief
Closest thing I can find would be to try calling the batch file with
which MIGHT work, but I haven't tested it.
Re: How to pick which switches and parameters for creating t
Posted: 13 Oct 2013 13:53
by serverdelux
ShadowThief wrote:Closest thing I can find would be to try calling the batch file with
which MIGHT work, but I haven't tested it.
Thanks for your help!
I have that in mind as last resort but found these three tasks and they all run the cmd or batch files silent so I was thinking the same thing could be done with "onlogon"
Code: Select all
schtasks /create /tn "Rearm" /tr "'%%SystemDrive%%\Windows\system32\cmd.exe' /c cscript.exe /b C:\Windows\System32\slmgr.vbs /rearm && net stop sppsvc && net start sppsvc" /sc daily /mo 30 /ru "" /f
Code: Select all
schtasks /create /tn "Tour" /tr "%SystemDrive%\LAS\7.bat" /sc onstart /ru ""
Code: Select all
schtasks /create /tn "Defrance" /tr "%SystemDrive%\Semi\5.bat" /sc daily /mo 1 /ru ""
One uses the
/f switch but all use the
"" but silently run batch
...lol
Re: How to pick which switches and parameters for creating t
Posted: 21 Oct 2013 15:13
by serverdelux
Hi, taking a break from creating silent task for now here is it is...
Code: Select all
schtasks /create /tn "task1" /tr "%SystemDrive%\1.bat" /sc onlogon /ru "" >nul
Right now I need help creating a task that runs as soon as it is created
Is it the "
once" parameter?
I went into the task scheduler and created a task that runs when it's created/modified
But need help putting it into batch form
Any help would be appreciated
Thanks
Re: How to pick which switches and parameters for creating t
Posted: 21 Oct 2013 15:48
by ShadowThief
Doesn't look like you can run the task with the same command you use to create the task, but you can manually run a task with
Code: Select all
SCHTASKS /Run [Connect_Options] /TN taskname
Re: How to pick which switches and parameters for creating t
Posted: 21 Oct 2013 16:00
by serverdelux
ShadowThief wrote:Doesn't look like you can run the task with the same command you use to create the task, but you can manually run a task with
Code: Select all
SCHTASKS /Run [Connect_Options] /TN taskname
I want to create a task that runs as soon as it created
This is possible and tested if using task scheduler to create it but I need the batch to do it so I don't have to open up task scheduler
Here is an exported XML that does it if anyone want's to look at in task scheduler
Code: Select all
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2013-10-21T14:41:03.8192848</Date>
<Author>Jesus-PC\Jesus</Author>
</RegistrationInfo>
<Triggers>
<RegistrationTrigger>
<Enabled>true</Enabled>
</RegistrationTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>Jesus-PC\Jesus</UserId>
<LogonType>Password</LogonType>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>P3D</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>%systemdrive%\remove1.bat</Command>
</Exec>
</Actions>
</Task>
Save as .xml and import to task scheduler to test
When created it will automatically run whatever actions you designate
So ultimately I wan't the task to be part of a batch file and not open task scheduler
Thanks
Re: How to pick which switches and parameters for creating t
Posted: 21 Oct 2013 16:05
by ShadowThief
serverdelux wrote:I want to create a task that runs as soon as it created
Code: Select all
schtasks /create /tn "task1" /tr "%SystemDrive%\1.bat" /sc onlogon /ru "" >nul
schtasks /run /tn "task1"
Re: How to pick which switches and parameters for creating t
Posted: 21 Oct 2013 16:35
by serverdelux
ShadowThief wrote:serverdelux wrote:I want to create a task that runs as soon as it created
Code: Select all
schtasks /create /tn "task1" /tr "%SystemDrive%\1.bat" /sc onlogon /ru "" >nul
schtasks /run /tn "task1"
I just have to code it into my function here
viewtopic.php?f=3&t=4993Ideally one schtasks cmd is what I want and would have resorted to schtasks /run eventually but I appreciate your help and creativity a lot so I can attempt to finish my function
Re: How to pick which switches and parameters for creating t
Posted: 23 Oct 2013 16:36
by serverdelux
Hi again, I'm working on my original task again to have it run silent but call another batch at
onlogonTask1Code: Select all
schtasks /create /tn "Task1" /tr "%SystemDrive%\1.bat" /sc onlogon /ru ""
It runs silent at
onlogon but it doesn't run 2.bat batch when called
...lol
Also if I open up task scheduler and run it also runs silent but doesn't call 2.bat to run
If I manually run 1.bat it will call 2.bat and it runs
What is going on here?
Is it cause the 1.bat is silent that it won't call 2.bat?
It's weird
Edit:
And 2.bat needs interaction so it needs to run non-silent
It's gotta be something about the task switches or silently run tasks can't call batch files but that doesn't make sense
Any help would be appreciated...
Thanks
Re: How to pick which switches and parameters for creating t
Posted: 24 Oct 2013 22:54
by serverdelux
Until I can perfect how to get the silent task to run 1.bat then call 2.bat does anyone know how to get this task
Code: Select all
schtasks /create /tn "Task1" /tr "%SystemDrive%\1.bat" /sc onlogon /ru ""
to start 1.bat with this cmd
Thanks
Edit:
Maybe something like this? I dunno
Code: Select all
schtasks /create /tn "T1" /tr "cmd.exe /c start /b /min C:\1\2\1.bat" /sc onlogon /ru ""
Code: Select all
schtasks /create /tn "T1" /tr "cmd.exe /c start /b /min C:\1\2\1.bat" /sc onlogon /rl highest /f
Re: How to pick which switches and parameters for creating t
Posted: 25 Oct 2013 22:02
by zoeyku
What is going on here?
Re: How to pick which switches and parameters for creating t
Posted: 26 Oct 2013 18:29
by serverdelux
zoeyku wrote:What is going on here?
lol...I wanted a task to run a batch file silent and call a non-silent batch but this is impossible as the call never happens to the second batch
Here is an interesting link that uses a .vbs file but tried that code too with no success
http://superuser.com/questions/62525/ru ... batch-fileAn silent batch cannot call a second batch!
So I'm going to take my 1st batch and write it in .vbs then task will just run it without flashing console and call second batch
[NOT SOLVABLE...LOL]
Re: [NOT SOLVABLE] Switches and parameters for creating task
Posted: 27 Oct 2013 22:22
by carlsomo
Try running hide.vbs with the batch file as parameter
Hide.vbs:
Code: Select all
Const HIDDEN_WINDOW = 12
if WScript.Arguments.Count = 0 then
WScript.Echo "Missing parameters"
end if
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = HIDDEN_WINDOW
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
errReturn = objProcess.Create("Wscript.Arguments(0)", null, objConfig, intProcessID