Skip to content

Commit

Permalink
Added original files
Browse files Browse the repository at this point in the history
These where individual parts of the development.
  • Loading branch information
NanKooDev committed Nov 20, 2019
1 parent b87e767 commit b8f9447
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 0 deletions.
Binary file added Powershell/Change Wallpaper.xml
Binary file not shown.
9 changes: 9 additions & 0 deletions Powershell/CheckAndCreateFolder.ps1
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
13 changes: 13 additions & 0 deletions Powershell/CreateTask.ps1
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
77 changes: 77 additions & 0 deletions Powershell/CreationScript.ps1
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
7 changes: 7 additions & 0 deletions Powershell/CurrentUserSID.ps1
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
18 changes: 18 additions & 0 deletions Powershell/DownloadImages.ps1
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
}
1 change: 1 addition & 0 deletions Powershell/RemoveTask.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unregister-ScheduledTask -TaskName 'Change Wallpaper' -Confirm:$false

0 comments on commit b8f9447

Please sign in to comment.