[SOLVED]Switches and parameters for creating tasks

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
serverdelux
Posts: 36
Joined: 04 Oct 2013 14:14

[SOLVED]Switches and parameters for creating tasks

#1 Post by serverdelux » 12 Oct 2013 23:30

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

:mrgreen:
Last edited by serverdelux on 31 Oct 2013 21:23, edited 2 times in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How to pick which switches and parameters for creating t

#2 Post by foxidrive » 13 Oct 2013 00:46

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.

serverdelux
Posts: 36
Joined: 04 Oct 2013 14:14

Re: How to pick which switches and parameters for creating t

#3 Post by serverdelux » 13 Oct 2013 11:25

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 :idea:

:D

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: How to pick which switches and parameters for creating t

#4 Post by ShadowThief » 13 Oct 2013 13:17

Closest thing I can find would be to try calling the batch file with

Code: Select all

start /min
which MIGHT work, but I haven't tested it.

serverdelux
Posts: 36
Joined: 04 Oct 2013 14:14

Re: How to pick which switches and parameters for creating t

#5 Post by serverdelux » 13 Oct 2013 13:53

ShadowThief wrote:Closest thing I can find would be to try calling the batch file with

Code: Select all

start /min
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 :shock:...lol

serverdelux
Posts: 36
Joined: 04 Oct 2013 14:14

Re: How to pick which switches and parameters for creating t

#6 Post by serverdelux » 21 Oct 2013 15:13

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 :mrgreen:

Thanks

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: How to pick which switches and parameters for creating t

#7 Post by ShadowThief » 21 Oct 2013 15:48

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

serverdelux
Posts: 36
Joined: 04 Oct 2013 14:14

Re: How to pick which switches and parameters for creating t

#8 Post by serverdelux » 21 Oct 2013 16:00

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

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: How to pick which switches and parameters for creating t

#9 Post by ShadowThief » 21 Oct 2013 16:05

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"

serverdelux
Posts: 36
Joined: 04 Oct 2013 14:14

Re: How to pick which switches and parameters for creating t

#10 Post by serverdelux » 21 Oct 2013 16:35

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=4993

Ideally 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 :wink:

serverdelux
Posts: 36
Joined: 04 Oct 2013 14:14

Re: How to pick which switches and parameters for creating t

#11 Post by serverdelux » 23 Oct 2013 16:36

Hi again, I'm working on my original task again to have it run silent but call another batch at onlogon

Task1

Code: 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 :shock:

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

serverdelux
Posts: 36
Joined: 04 Oct 2013 14:14

Re: How to pick which switches and parameters for creating t

#12 Post by serverdelux » 24 Oct 2013 22:54

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

Code: Select all

start /min


Thanks :mrgreen:

Edit:

Maybe something like this? I dunno :lol:

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

zoeyku
Posts: 3
Joined: 20 Oct 2013 19:59
Location: usa
Contact:

Re: How to pick which switches and parameters for creating t

#13 Post by zoeyku » 25 Oct 2013 22:02

What is going on here?

serverdelux
Posts: 36
Joined: 04 Oct 2013 14:14

Re: How to pick which switches and parameters for creating t

#14 Post by serverdelux » 26 Oct 2013 18:29

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-file

An 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]

carlsomo
Posts: 91
Joined: 02 Oct 2012 17:21

Re: [NOT SOLVABLE] Switches and parameters for creating task

#15 Post by carlsomo » 27 Oct 2013 22:22

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

Post Reply