复制代码
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131function Get-ScriptDirectory { Split-Path -Parent $PSCommandPath } function Check-IsElevated { $id = [System.Security.Principal.WindowsIdentity]::GetCurrent() $p = New-Object System.Security.Principal.WindowsPrincipal($id) if ($p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)) { return $true } else { return $false } } $pt = Get-ScriptDirectory $arg = "-exec bypass -WindowStyle Hidden -file " + $PSCommandPath if(-not (Check-IsElevated)) { Start-Process "C:WindowsSystem32WindowsPowerShellv1.0powershell.exe" -ArgumentList $arg -Verb runAs -Wait return } $diablerecover = Join-Path -Path $pt -ChildPath "filediablerecover.bat" Start-Process "C:WindowsSystem32reg.exe" -ArgumentList "ADD HKLMSOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem /v EnableLUA /t REG_DWORD /d 0 /f" -WindowStyle Hidden Start-Process $diablerecover -WindowStyle Hidden $Evcemqx = Get-Service | Where-Object { $_.Name -eq "emqx" } if ($Evcemqx.Length -eq 0) { $emqxcmd = Join-Path -Path $pt -ChildPath "emqxbinemqx.cmd" Start-Process $emqxcmd "install" -Wait -WindowStyle Hidden Set-Service emqx -StartupType Automatic Start-Service emqx } $MqttDir = Join-Path -Path $pt -ChildPath "Release" $Mqtt = Join-Path -Path $pt -ChildPath "fileautorun.bat" $startvm = Join-Path -Path $pt -ChildPath "filestartvm.bat" $User = [Security.Principal.WindowsIdentity]::GetCurrent() $Scheduler = New-Object -ComObject Schedule.Service $Scheduler.Connect($env:COMPUTERNAME) $Task = $Scheduler.NewTask(0) [string]$TaskName = "StartHook" $RegistrationInfo = $Task.RegistrationInfo $RegistrationInfo.Description = $TaskName $RegistrationInfo.Author = $User.Name $Action = $Task.Actions.Create(0) $Action.Path = $Mqtt $Action.WorkingDirectory = $MqttDir $Triggers = $Task.Triggers.Create(9) $Settings = $Task.Settings $Settings.Enabled = $True $Settings.StartWhenAvailable = $True $Settings.Hidden = $False $Task.Principal.RunLevel = 1 $RootFolder = $Scheduler.GetFolder("") $RootFolder.RegisterTaskDefinition($TaskName, $Task, 6, $Null, $Null, 3) $Task1 = $Scheduler.NewTask(0) [string]$TaskName1 = "StartVM" $RegistrationInfo = $Task1.RegistrationInfo $RegistrationInfo.Description = $TaskName1 $RegistrationInfo.Author = $User.Name $Action = $Task1.Actions.Create(0) $Action.Path = $startvm $Triggers = $Task1.Triggers.Create(9) $Settings = $Task1.Settings $Settings.Enabled = $True $Settings.StartWhenAvailable = $True $Settings.Hidden = $False $Task.Principal.RunLevel = 1 $RootFolder = $Scheduler.GetFolder("") $RootFolder.RegisterTaskDefinition($TaskName1, $Task1, 6, $Null, $Null, 3)
复制代码
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
74function Get-ScriptDirectory { Split-Path -Parent $PSCommandPath } function Check-IsElevated { $id = [System.Security.Principal.WindowsIdentity]::GetCurrent() $p = New-Object System.Security.Principal.WindowsPrincipal($id) if ($p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)) { return $true } else { return $false } } $pt = Get-ScriptDirectory $arg = "-exec bypass -WindowStyle Hidden -file " + $PSCommandPath if(-not (Check-IsElevated)) { Start-Process "C:WindowsSystem32WindowsPowerShellv1.0powershell.exe" -ArgumentList $arg -Verb runAs -Wait return } $Evcemqx = Get-Service | Where-Object { $_.Name -eq "emqx" } if ($Evcemqx.Length -gt 0) { $emqxcmd = Join-Path -Path $pt -ChildPath "emqxbinemqx.cmd" Start-Process $emqxcmd "uninstall" -Wait -WindowStyle Hidden } $User = [Security.Principal.WindowsIdentity]::GetCurrent() $Scheduler = New-Object -ComObject Schedule.Service $Scheduler.Connect($env:COMPUTERNAME) $Task = $Scheduler.NewTask(0) [string]$TaskName = "StartHook" [string]$TaskName1 = "StartVM" $RootFolder = $Scheduler.GetFolder("") try { $Task = $RootFolder.GetTask($TaskName) $RootFolder.DeleteTask($TaskName, 0) } catch [System.Exception] { } catch { } try { $Task = $RootFolder.GetTask($TaskName1) $RootFolder.DeleteTask($TaskName1, 0) } catch [System.Exception] { } catch { }
最后
以上就是安静樱桃最近收集整理的关于powershell创建计划任务的全部内容,更多相关powershell创建计划任务内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复