-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
72 lines (61 loc) · 2.3 KB
/
install.ps1
File metadata and controls
72 lines (61 loc) · 2.3 KB
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
#!/usr/bin/env powershell
# 1. Create path and add it to environment
$path = "$env:USERPROFILE\Scripts"
if (!(Test-Path $path)) {
mkdir $path
[System.Environment]::SetEnvironmentVariable("PATH", $env:PATH + ";$path", "User")
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "User")
}
if (!(Copy-Item -Path "bunnyfetch.ps1" -Destination "${path}\bunnyfetch.ps1" -Force)) {
Copy-Item -Path "$env:USERPROFILE\Documents\bunnyfetch\bunnyfetch.ps1" -Destination "${path}\bunnyfetch.ps1" -Force
}
if (!(Copy-Item -Path "bunnyfetches.ps1" -Destination "${path}\bunnyfetches.ps1" -Force)) {
Copy-Item -Path "$env:USERPROFILE\Documents\bunnyfetch\bunnyfetches.ps1" -Destination "${path}\bunnyfetches.ps1" -Force
}
# 2. Create autostart to run bunnyfetches every start
# --- Configurations ---
$taskname = "Bunnyfetches"
$taskpath = "$env:USERPROFILE\Scripts\bunnyfetches.ps1"
$taskdesc = "Autorun bunnyfetches at start"
$taskfold = "\Autostart"
# --- Components ---
$action = New-ScheduledTaskAction `
-Execute "powershell.exe" `
-Argument "-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$taskpath`""
$trigger = New-ScheduledTaskTrigger -AtLogOn
$principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -LogonType Interactive -RunLevel Highest
$settings = New-ScheduledTaskSettingsSet `
-AllowStartIfOnBatteries:$true `
-DontStopIfGoingOnBatteries:$true `
-ExecutionTimeLimit ([TimeSpan]::Zero) `
-StartWhenAvailable:$false `
# --- Ensure the folder exist ---
$service = New-Object -ComObject "Schedule.Service"
$service.Connect()
$rootFolder = $service.GetFolder("\")
try {
$null = $rootFolder.GetFolder("Autostart")
} catch {
$rootFolder.CreateFolder("Autostart") | Out-Null
}
# --- Remove old task if exist ---
try {
$existing = Get-ScheduledTask -TaskName $taskname -ErrorAction Stop
if ($existing) {
Unregister-ScheduledTask -TaskName $taskname -Confirm:$false
Write-Host "Old task '$taskname' removed."
}
} catch {
Write-Host "No existing task found, creating a new one..."
}
# --- Register Task ---
Register-ScheduledTask `
-TaskName $taskname `
-TaskPath $taskfold `
-Action $action `
-Trigger $trigger `
-Principal $principal `
-Settings $settings `
-Description $taskdesc
if ($?) { Write-Host "Task '$taskname' successfully registered in folder '$taskfold'." }
./bunnyfetches.ps1