RamonUnch / AltSnap

Maintained continuation of Stefan Sundin's AltDrag
GNU General Public License v3.0
2.21k stars 74 forks source link

Add batch files to setup Scheduled task #477

Closed RamonUnch closed 1 year ago

RamonUnch commented 1 year ago

Well, basically the option is schtasks.exe /CREATE /XML .\AltSnap.xml /TR "%~dp0AltSnap.exe" The task can be created without the xml file but it will get terminated after 3 days and there are no ways to change that unless yu use an xml file.

jefflord commented 1 year ago

Nice, thanks!

shodanx2 commented 10 months ago

Note the following command will create a task to start altsnap as administrator when you login

schtasks /create /f /tn "RunAltSnap" /tr "%appdata%\AltSnap\AltSnap.exe" /sc onlogon /rl highest

RamonUnch commented 10 months ago

The problem with the above is that AltSanp will be killed after 3 days. The only way to disable this killing is to use an .xml file. Also if you probably want to add a small delay, this is done with the /DELAY 0:10 option.

jefflord commented 10 months ago

@RamonUnch, why is a delay useful? Is it just because you don't need to slowdown the login and also not (likely) need to move a window in the first 10-30 seconds?

Also, I think "/st 99999:00" would basically allow it to run forever, effectively.

RamonUnch commented 10 months ago

I added the delay because some users experienced problems when AltSnap starts before after the explorer, so I keep it as a safety measure. /st is for start time so it is supposed to be in the 24 hour format? I am misreading the doc?

jefflord commented 10 months ago

I think you are correct and all the options that look like they might work are not compatible with MINUTE, HOURLY, ONSTART, ONLOGON, ONIDLE, ONEVENT.

So you'd have to open the GUI and uncheck the box anyway.

If you can do it with schtasks it does not look simple. I'm with you now @RamonUnch, it's a bit of a fail on schtasks.

shodanx2 commented 10 months ago

Yes, I confirm the command line that I used will shut down altsnap after 3 days

image

I tried /st 99999:00

but it does refuse to work

image

Another potential problem is this task runs for every user, but the path of the executable refers to a specific user, it seems that %APPDATA% gets dereferenced on the command line.

image

One problem I notice with the AltSnap.xml is that it must be modified before use as it has a placeholder path

image

In the command line schtasks.exe /CREATE /XML .\AltSnap.xml /TR "%~dp0AltSnap.exe" does that override the action's command ?

Answer, no you cannot use /TR with /XML

image

As Is, this creates a task with the wrong executable

image

So I tried a relative path

image

image

promising

image

Well, I have to reboot to give this a test so this post ends here

shodanx2 commented 10 months ago

Ok, I have tested this and it works

Please modify the line of AltSnap.xml as follows

from <Command>C:\your\full\path\toAltSnap\AltSnap.exe</Command>

to <Command>%appdata%\AltSnap\AltSnap.exe</Command>

As per the attached copy of AltSnap.xml

AltSnap.zip

To create the task, (in an administrator command prompt)

schtasks /create /f /XML "%appdata%\AltSnap\AltSnap.xml" /tn "RunAltSnap"

image

To delete the task

schtasks /f /delete /tn "RunAltSnap"

image