-
Notifications
You must be signed in to change notification settings - Fork 0
/
cygsu
executable file
·85 lines (79 loc) · 2.36 KB
/
cygsu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env bash
set -euo pipefail
export MSYS2_ARG_CONV_EXCL="*"
getsid() {
"$(cygpath -u $SYSTEMROOT)/System32/whoami" /user | tail -n 1 | awk '{print $NF}'
}
gettmpl() {
cat << EOF
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.6" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Author>CygwinSkipUAC</Author>
<URI>$tn</URI>
</RegistrationInfo>
<Triggers>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>$sid</UserId>
<LogonType>InteractiveToken</LogonType>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
<AllowHardTerminate>false</AllowHardTerminate>
<StartWhenAvailable>true</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>false</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>$cmd</Command>
<Arguments>$args</Arguments>
<WorkingDirectory>$dirrun</WorkingDirectory>
</Exec>
</Actions>
</Task>
EOF
}
subcmd="$1"
tn="${2//\//\\}"
shift; shift;
if [[ "$subcmd" == "check" ]]; then
schtasks /Query /TN "$tn"
elif [[ "$subcmd" == "del" ]]; then
elevate -w schtasks /Delete /TN "$tn" /F
elif [[ "$subcmd" == "run" ]]; then
schtasks /Run /TN "$tn"
elif [[ "$subcmd" == "make" ]]; then
sid="$(getsid | tr -d '\n\r')"
TMPFILE="$(mktemp --suffix=.xml)"
trap 'rm -fv "$TMPFILE"' EXIT
cmd="$(readlink -f "$1")"
dirrun="$(cygpath -aw "$(dirname "$cmd")")"
cmd="$(cygpath -aw "$cmd")"
shift;
args=""
for arg in "$@"; do
args+="\"$arg\" "
done
args="${args% }"
gettmpl > "$TMPFILE"
elevate -w schtasks /Create /TN "$tn" /xml "$(cygpath -aw "$TMPFILE")"
fi