-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These where individual parts of the development.
- Loading branch information
Showing
7 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
$path = $env:USERPROFILE + "\WeekdayWallPaper" | ||
|
||
|
||
|
||
if(!(Test-Path $path)){ | ||
Write-Output "Doesn't exist" | ||
New-Item -ItemType directory -Path $path | ||
} | ||
Write-Output $path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#Get Current user SID | ||
$input = whoami /user /fo list | ||
$regexperssion = "SID:\s+([\s\S_]+)" | ||
$sid = [regex]::Match($input,$regexperssion).captures.groups[1].value | ||
|
||
#Create Task | ||
$TaskName = 'Change Wallpaper1' | ||
$Action = New-ScheduledTaskAction -Execute 'powershell.exe'-Argument '-window hidden -NonInteractive -NoLogo -File "C:\Users\NKOOLS98\OneDrive - Conclusion\Bureaublad\wallpaper.ps1"' | ||
$Trigger = New-ScheduledTaskTrigger -AtLogOn | ||
$Settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries | ||
$Principal = New-ScheduledTaskPrincipal -LogonType Interactive -UserId $sid -Id 'Author' -RunLevel Highest | ||
$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings -Principal $Principal | ||
Register-ScheduledTask -TaskName $TaskName -InputObject $Task -Force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#SECTION VARIABLES | ||
$FileNames = @( | ||
"Monday.jpg", | ||
"Tuesday.jpg", | ||
"Wednesday.jpg", | ||
"Thursday.jpg", | ||
"Friday.jpg", | ||
"Saturday.jpg", | ||
"Sunday.jpg", | ||
"wallpaper.ps1") | ||
$Path = $env:USERPROFILE + "\WeekdayWallpaper\" | ||
$ScriptLocation = $path + $FileNames[7] | ||
$Uri = "https://github.com/BlaxadowFire/JapaneseBackground/blob/master/" | ||
#SECTION VARIABLES END | ||
|
||
#SECTION FUNCTIONS | ||
|
||
#Downloads give files from base URI to Path | ||
Function DownloadFiles($fileNames) | ||
{ | ||
foreach ($fileName in $fileNames) | ||
{ | ||
If (!([System.IO.File]::Exists($Path + $fileName))) | ||
{ | ||
DownloadFile -fileName $fileName | ||
} | ||
} | ||
} | ||
|
||
#Downloads given file from base URI to Path | ||
Function DownloadFile($fileName) | ||
{ | ||
$fileUri = $Uri + $fileName + "?raw=true" | ||
$outPutFile = $Path + $fileName | ||
Invoke-WebRequest -Uri $fileUri -OutFile $outputFile | ||
} | ||
|
||
Function DirCheck($fileNames) | ||
{ | ||
#Checks if Directory exists | ||
if(!(Test-Path $Path)) | ||
{ | ||
#Create Directory | ||
New-Item -ItemType directory -Path $Path | ||
} | ||
|
||
#Download all files if not existing | ||
DownloadFiles -fileNames $fileNames | ||
} | ||
|
||
Function Get-SID() | ||
{ | ||
#Get Current user SID | ||
$input = whoami /user /fo list | ||
$regexperssion = "SID:\s+([\s\S_]+)" | ||
return [regex]::Match($input,$regexperssion).captures.groups[1].value | ||
} | ||
|
||
Function CreateTask() | ||
{ | ||
$sid = Get-SID | ||
|
||
#Create Task | ||
$TaskName = 'Change Wallpaper' | ||
$Action = New-ScheduledTaskAction -Execute 'powershell.exe'-Argument '-window hidden -NonInteractive -NoLogo -File $ScriptLocation' | ||
$Trigger = New-ScheduledTaskTrigger -AtLogOn | ||
$Settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries | ||
$Principal = New-ScheduledTaskPrincipal -LogonType Interactive -UserId $sid -Id 'Author' -RunLevel Highest | ||
$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings -Principal $Principal | ||
Register-ScheduledTask -TaskName $TaskName -InputObject $Task -Force | ||
} | ||
|
||
#SECTION FUNCTIONS END | ||
|
||
#The executed code | ||
Dircheck -fileNames $FileNames | ||
CreateTask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
$input = whoami /user /fo list | ||
$regexperssion = "SID:\s+([\s\S_]+)" | ||
|
||
#$output = $input -match "SID:\s+([\s\S_]+)" | ||
$output = [regex]::Match($input,$regexperssion).captures.groups[1].value | ||
|
||
Write-Output $output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
$FileNames = @( | ||
"Monday.jpg", | ||
"Tuesday.jpg", | ||
"Wednesday.jpg", | ||
"Thursday.jpg", | ||
"Friday.jpg", | ||
"Saturday.jpg", | ||
"Sunday.jpg", | ||
"wallpaper.ps1" | ||
) | ||
$Uri = "https://github.com/BlaxadowFire/JapaneseBackground/blob/master/" | ||
$OutPath = $env:USERPROFILE + "\WeekdayWallpaper\" | ||
|
||
foreach ($fileName in $FileNames){ | ||
$FileUri = $Uri + $fileName + "?raw=true" | ||
$OutPutFile = $OutPath + $fileName | ||
Invoke-WebRequest -Uri $FileUri -OutFile $OutputFile | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Unregister-ScheduledTask -TaskName 'Change Wallpaper' -Confirm:$false |