########## # Win 10 Black Viper Service Configuration Script # # Script + Menu(GUI) By # Author: Madbomb122 # Website: https://GitHub.com/Madbomb122/BlackViperScript/ # # Black Viper's Service Configurations By # Author: Charles "Black Viper" Sparks # Website: http://www.BlackViper.com/ # $Script_Version = '6.2.3' $Script_Date = 'Jun-22-2020' #$Release_Type = 'Stable' ########## # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # !! !! # !! SAFE TO EDIT ITEM !! # !! AT BOTTOM OF SCRIPT !! # !! !! # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # !! !! # !! CAUTION !! # !! DO NOT EDIT PAST THIS POINT !! # !! !! # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! <#------------------------------------------------------------------------------#> $Copyright = ' Copyright (c) 2019 Zero Rights Reserved - Services Configuration by Charles "Black Viper" Sparks ------------------------------------------------------------------------ The MIT License (MIT) + an added Condition Copyright (c) 2017-2020 Madbomb122 - Black Viper Service Script Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice(s), this permission notice and ANY original donation link shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ' <#-------------------------------------------------------------------------------- .Prerequisite to run script System*: Windows 10 x64 (64-bit) Edition*: Home or Pro Min Build*: Creator's Update Max Build*: April 2018 Update Files: This script and 'BlackViper.csv' (Service Configurations) *Can run on x32/32-bit or other Edition, Build AT YOUR OWN RISK) .DESCRIPTION Script that can set services based on Black Viper's Service Configurations or your own custom services, or backup services (created by this script) .AT YOUR OWN RISK YOU CAN 1. Run the script on x86 (32-bit) w/o changing settings (But shows a warning) 2. Skip the check for A. Home/Pro ($EditionCheck variable bottom of script or use -sec switch) B. Creator's Update ($BuildCheck variable bottom of script or use -sbc switch) .BASIC USAGE 1. Run script with (Next Line) powershell.exe -NoProfile -ExecutionPolicy Bypass -File BlackViper-Win10.ps1 2. Use bat file provided Use Gui to Select the desired Choices and click Run .ADVANCED USAGE One of the following Methods... 1. Edit values at bottom of the script then run script 2. Edit bat file and run 3. Run the script with one of these switches (space between multiple) 4. Run the script and pick options in GUI Switch Description of Switch -- Basic Switches -- -atos Accepts ToS -auto Implies -atos...Runs the script to be Automated.. Closes on - User Input, Errors, or End of Script --Service Configuration Switches-- -default Runs the script with Services to Default Configuration -safe Runs the script with Services to Black Viper's Safe Configuration -tweaked Runs the script with Services to Black Viper's Tweaked Configuration -lcsc File.csv Loads Custom Service Configuration, File.csv = Name of your backup/custom file --Service Choice Switches-- -all Every windows services will change -min Just the services different from the default to safe/tweaked list -sxb Skips changes to all XBox Services --Update Switches-- -usc Checks for Update to Script file before running -use Checks for Update to Service file before running -sic Skips Internet Check, if you can't ping GitHub.com for some reason --Log Switches-- -log Makes a log file using default name Script.log -log File.log Makes a log file named File.log -baf Log File of Services Configuration Before and After the script --Backup Service Configuration-- -bscc Backup Current Service Configuration, Csv File -bscr Backup Current Service Configuration, Reg File -bscb Backup Current Service Configuration, Csv and Reg File --Display Switches-- -sas Show Already Set Services -snis Show Not Installed Services -sss Show Skipped Services --Misc Switches-- -dry Runs the Script and Shows what services will be changed -css Change State of Service -sds Stop Disabled Service --AT YOUR OWN RISK Switches-- -secp Skips Edition Check by Setting Edition as Pro -sech Skips Edition Check by Setting Edition as Home -sbc Skips Build Check --Dev Switches-- -devl Makes a log file with various Diagnostic information, Nothing is Changed -diag Shows diagnostic information, Stops -auto -diagf Forced diagnostic information, Script does nothing else --Help-- -help Shows list of switches, then exits script.. alt -h -copy Shows Copyright/License Information, then exits script ------------------------------------------------------------------------------#> ########## # Pre-Script/Needed Variable -Start ########## $WindowVersion = [Environment]::OSVersion.Version.Major If($WindowVersion -ne 10) { Write-Host 'Sorry, this Script supports Windows 10 ONLY.' -ForegroundColor 'cyan' -BackgroundColor 'black' If($Automated -ne 1){ Read-Host -Prompt "`nPress Any key to Close..." } ;Exit } If($Release_Type -eq 'Stable'){ $ErrorActionPreference = 'SilentlyContinue' } Else{ $Release_Type = 'Testing' } $PassedArg = $args If(!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator')) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" $PassedArg" -Verb RunAs ;Exit } $PCType = (Get-CimInstance Win32_ComputerSystem).PCSystemType $CimOS = Get-CimInstance Win32_OperatingSystem | Select-Object OperatingSystemSKU,Caption,BuildNumber,OSArchitecture $OSBit = $CimOS.OSArchitecture $WinSku = $CimOS.OperatingSystemSKU $WinSkuList = @(48,49,98,100,101) # 48 = Pro, 49 = Pro N # 98 = Home N, 100 = Home (Single Language), 101 = Home $FullWinEdition = $CimOS.Caption $WinEdition = $FullWinEdition.Split(' ')[-1] # Pro or Home # https://en.wikipedia.org/wiki/Windows_10_version_history $BuildVer = $CimOS.BuildNumber $Win10Ver = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name ReleaseID).ReleaseId # 1909, November 2019 Update # 1903, May 2019 Update # 1809, October 2018 Update $MaxVer,$MaxVerName = 1803, 'April 2018 Update' # 1709, Fall Creators Update $MinVer,$MinVerName = 1703, 'Creators Update' # 1607, Anniversary Update # 1511, November Update (First Major Update) # 1507, First Release $MySite = 'https://GitHub.com/madbomb122/BlackViperScript' $URL_Base = $MySite.Replace('GitHub','raw.GitHub')+'/master/' $Version_Url = $URL_Base + 'Version/Version.csv' $Service_Url = $URL_Base + 'BlackViper.csv' $Donate_Url = 'https://www.amazon.com/gp/registry/wishlist/YBAYWBJES5DE/' $ServiceEnd = (Get-Service *_*).Where({$_.ServiceType -eq 224}, 'First') -Replace '^.+?_', '_' $colors = @( 'black', #0 'blue', #1 'cyan', #2 'darkblue', #3 'darkcyan', #4 'darkgray', #5 'darkgreen', #6 'darkmagenta',#7 'darkred', #8 'darkyellow', #9 'gray', #10 'green', #11 'magenta', #12 'red', #13 'white', #14 'yellow') #15 $ColorsGUI = $Colors[14,15,7,3,4,5,6,2,8,9,10,11,12,13,0,1] $ServicesTypeList = @( 'Skip', #0 -Skip/Not Installed 'Disabled',#1 'Manual', #2 'Auto', #3 'Auto') #4 -Auto (Delayed) $ServicesTypeFull = $ServicesTypeList[0..4] $ServicesTypeFull[4] = 'Auto (Delayed)' $ServicesRegTypeList = @('','4','3','2','2') #Order is same as ServicesTypeFull $SrvStateList = @('Running','Stopped') $XboxServiceArr = @('XblAuthManager','XblGameSave','XboxNetApiSvc','XboxGipSvc','xbgm') $NetTCP = @('NetMsmqActivator','NetPipeActivator','NetTcpActivator') $FilterList = @('CheckboxChecked','CName','ServiceName','CurrType','BVType','SrvState','SrvDesc','SrvPath','RowColor') $DevLogList = @('WPF_ScriptLog_CB','WPF_Diagnostic_CB','WPF_LogBeforeAfter_CB','WPF_DryRun_CB','WPF_ShowNonInstalled_CB','WPF_ShowAlreadySet_CB') $FileBase = $(If($psISE -ne $Null){ Split-Path $psISE.CurrentFile.FullPath -Parent } Else{ $PSScriptRoot }) + '\' $SettingPath = $FileBase + 'BVSetting.xml' $ServiceFilePath = $FileBase + 'BlackViper.csv' $BVServiceFilePath = $ServiceFilePath $Black_Viper = 0 $Automated = 0 $All_or_Min = '-Min' $ServiceMaker = 'BV-' $RunScript = 2 $ErrorDi = '' $LogStarted = 0 $LoadServiceConfig = 0 $RanScript = $False $LaptopTweaked = 0 $ErrCount = $Error.Count $GuiSwitch = $False $ArgList = (0..28) $ArgList[0] = @{ Arg = '-all' ;Var = 'All_or_Min=-Full';Match = 1 ;Gui = $True } $ArgList[1] = @{ Arg = '-min' ;Var = 'All_or_Min=-Min' ;Match = 1 ;Gui = $True } $ArgList[2] = @{ Arg = '-bscc' ;Var = @('BackupServiceConfig=1','BackupServiceType=1') ;Match = 2 ;Gui = $True } $ArgList[3] = @{ Arg = '-bscr' ;Var = @('BackupServiceConfig=1','BackupServiceType=0') ;Match = 2 ;Gui = $True } $ArgList[4] = @{ Arg = '-bscb' ;Var = @('BackupServiceConfig=1','BackupServiceType=2') ;Match = 2 ;Gui = $True } $ArgList[5] = @{ Arg = '-baf' ;Var = 'LogBeforeAfter=1' ;Match = 1 ;Gui = $True } $ArgList[6] = @{ Arg = '-snis' ;Var = 'ShowNonInstalled=1' ;Match = 1 ;Gui = $True } $ArgList[7] = @{ Arg = '-sss' ;Var = 'ShowSkipped=1' ;Match = 1 ;Gui = $True } $ArgList[8] = @{ Arg = '-sas' ;Var = 'ShowAlreadySet=1' ;Match = 1 ;Gui = $True } $ArgList[9] = @{ Arg = '-sds' ;Var = 'StopDisabled=1' ;Match = 1 ;Gui = $True } $ArgList[10] = @{ Arg = '-sic' ;Var = 'InternetCheck=1' ;Match = 1 ;Gui = $True } $ArgList[11] = @{ Arg = '-css' ;Var = 'ChangeState=1' ;Match = 1 ;Gui = $True } $ArgList[12] = @{ Arg = '-usc' ;Var = 'ScriptVerCheck=1' ;Match = 1 ;Gui = $True } $ArgList[13] = @{ Arg = '-use' ;Var = 'ServiceVerCheck=1' ;Match = 1 ;Gui = $True } $ArgList[14] = @{ Arg = '-atos' ;Var = 'AcceptToS=Accepted' ;Match = 1 ;Gui = $True } $ArgList[15] = @{ Arg = '-dry' ;Var = 'DryRun=1' ;Match = 1 ;Gui = $True } $ArgList[16] = @{ Arg = '-devl' ;Var = 'DevLog=1' ;Match = 1 ;Gui = $True } $ArgList[17] = @{ Arg = '-sbc' ;Var = 'BuildCheck=1' ;Match = 1 ;Gui = $True } $ArgList[18] = @{ Arg = '-sxb' ;Var = 'XboxService=1' ;Match = 1 ;Gui = $True } $ArgList[19] = @{ Arg = '-sech' ;Var = 'EditionCheck=Home' ;Match = 1 ;Gui = $True } $ArgList[20] = @{ Arg = '-secp' ;Var = 'EditionCheck=Pro' ;Match = 1 ;Gui = $True } $ArgList[21] = @{ Arg = '-sec' ;Var = 'EditionCheck=Pro' ;Match = -1 ;Gui = $True } $ArgList[22] = @{ Arg = '-default' ;Var = @('Black_Viper=1','BV_ArgUsed=2') ;Match = 1 ;Gui = $False } $ArgList[23] = @{ Arg = '-safe' ;Var = @('Black_Viper=2','BV_ArgUsed=2') ;Match = 1 ;Gui = $False } $ArgList[24] = @{ Arg = '-tweaked' ;Var = If($PCType -eq 1){ @('Black_Viper=3','BV_ArgUsed=2') } Else{ @('Black_Viper=0','BV_ArgUsed=1') } ;Match = 1 ;Gui = $False } $ArgList[25] = @{ Arg = '-auto' ;Var = @('Automated=1','AcceptToS=Accepted') ;Match = 1 ;Gui = $False } $ArgList[26] = @{ Arg = '-diag' ;Var = @('Diagnostic=1','Automated=0') ;Match = 2 ;Gui = $True } $ArgList[27] = @{ Arg = '-log' ;Var = @('ScriptLog=1','LogName=-') ;Match = -1 ;Gui = $True } $ArgList[28] = @{ Arg = '-logc' ;Var = @('ScriptLog=2','LogName=-') ;Match = -1 ;Gui = $True } ########## # Pre-Script/Needed Variable -End ########## # Multi Use Functions -Start ########## Function AutomatedExitCheck([Int]$ExitBit) { If($Automated -ne 1){ Read-Host -Prompt "`nPress Any key to Close..." } If($ExitBit -eq 1){ LogEnd ;CloseExit } } Function LogEnd{ If(0 -NotIn $ScriptLog,$LogStarted){ Write-Output "--End of Log ($(Get-Date -Format 'MM/dd/yyyy hh:mm:ss tt'))--" | Out-File -LiteralPath $LogFile -Encoding Unicode -NoNewline -Append } } Function GetTime{ Return Get-Date -Format 'hh:mm:ss tt' } Function CloseExit{ If($GuiSwitch){ $Form.Close() } ;Exit } Function GetCurrServices{ $Script:CurrServices = Get-CimInstance Win32_service | Select-Object DisplayName, Name, @{ Name = 'StartType' ;Expression = {$_.StartMode} }, @{ Name = 'Status' ;Expression = {$_.State} }, Description, PathName } Function OpenWebsite([String]$Url){ Start $Url } Function ShowInvalid([Bool]$InvalidA){ If($InvalidA){ Write-Host "`nInvalid Input" -ForegroundColor Red -BackgroundColor Black -NoNewline } Return $False } Function DownloadFile([String]$Url,[String]$FilePath){ (New-Object System.Net.WebClient).DownloadFile($Url, $FilePath) } Function QMarkServices([String]$Srv){ If($Srv -Match '_\?+$'){ Return ($Srv -Replace '_\?+$',$ServiceEnd) } Return $Srv } Function SearchSrv([String]$Srv,[String]$Fil){ Return ($CurrServices.Where({$_.Name -eq $Srv}, 'First')).$Fil } Function AutoDelayTest([String]$Srv){ $tmp = (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\$Srv\").DelayedAutostart ;If($null -ne $tmp){ Return $tmp } Return 0 } Function AutoDelaySet([String]$Srv,[Int]$EnDi){ Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Services\$Srv\" -Name 'DelayedAutostart' -Type DWord -Value $EnDi } Function DisplayOut { Param ( [Alias('T')] [String[]]$Text, [Alias('C')] [Int[]]$Color, [Alias('L')] [Switch]$Log, [Alias('G')] [Switch]$Gui ) If($Gui){ TBoxService @args } For($i = 0 ;$i -lt $Text.Length ;$i++){ Write-Host $Text[$i] -ForegroundColor $colors[$Color[$i]] -BackgroundColor 'Black' -NoNewLine } ;Write-Host If($Log -and $ScriptLog -eq 1){ Write-Output "$(GetTime): $($Text -Join ' ')" | Out-File -LiteralPath $LogFile -Encoding Unicode -Append } } Function DisplayOutLML { Param ( [Alias('T')] [String]$Text, [Alias('C')] [Int[]]$Color, [Alias('L')] [Switch]$Log ) DisplayOut '| ',"$Text".PadRight(50),' |' -C 14,$Color,14 -L:$Log } Function DisplayMisc { Param ( [Switch]$Menu, [Switch]$Line, [String]$Misc ) $txt = If($Line){ '|'.PadRight(53,'-') + '|' } Else{ '|'.PadRight(53) + '|' } #Line or Blank Spaces $Splat = If($Menu) { @{ Text = $txt ;Color = 14 ;Log = [bool]$Misc } } Else { #For ToS @{ Text = $txt ;Color = [int]$Misc ;Log = $False } } DisplayOut @Splat } Function Error_Top { Clear-Host DiagnosticCheck 0 DisplayMisc -Menu -Line -Misc $True DisplayOutLML (''.PadRight(22)+'Error') -C 13 -L DisplayMisc -Menu -Line -Misc $True DisplayMisc -Menu -Misc $True } Function Error_Bottom { DisplayMisc -Misc $True DisplayMisc -Line -Misc $True If($Diagnostic -eq 1){ DiagnosticCheck 0 } AutomatedExitCheck 1 } ########## # Multi Use Functions -End ########## # TOS -Start ########## Function ShowCopyright { Clear-Host ;DisplayOut $Copyright -C 14 } Function TOSDisplay([Switch]$C) { If(!$C){ Clear-Host } $BC = 14 If($Release_Type -ne 'Stable') { $BC = 15 DisplayMisc -Line -Misc 15 DisplayOut '|'.PadRight(22),'Caution!!!'.PadRight(31),'|' -C 15,13,15 DisplayMisc -Misc 15 DisplayOut '|',' This script is still being tested. ','|' -C 15,14,15 DisplayOut '|'.PadRight(17),'USE AT YOUR OWN RISK.'.PadRight(36),'|' -C 15,14,15 DisplayMisc -Misc 15 } If($OSBit -ne '64-bit') { $BC = 15 DisplayMisc -Line -Misc 15 DisplayOut '|'.PadRight(22),'WARNING!!!'.PadRight(31),'|' -C 15,13,15 DisplayMisc -Misc 15 DisplayOut '|',' These settings are meant for x64 Bit. ','|' -C 15,14,15 DisplayOut '|'.PadRight(17),'USE AT YOUR OWN RISK.'.PadRight(36),'|' -C 15,14,15 DisplayMisc -Misc 15 } DisplayMisc -Line -Misc $BC DisplayOut '|'.PadRight(21),'Terms of Use'.PadRight(32),'|' -C $BC,11,$BC DisplayMisc -Line -Misc $BC DisplayMisc -Misc $BC DisplayOut '|',' This program comes with ABSOLUTELY NO WARRANTY. ','|' -C $BC,2,$BC DisplayOut '|',' This is free software, and you are welcome to ','|' -C $BC,2,$BC DisplayOut '|',' redistribute it under certain conditions. ','|' -C $BC,2,$BC DisplayMisc -Misc $BC DisplayOut '|',' Read License file for full Terms.'.PadRight(52),'|' -C $BC,2,$BC DisplayMisc -Misc $BC DisplayOut '|',' Use the switch ','-copy',' to see License Information or ','|' -C $BC,2,14,2,$BC DisplayOut '|',' enter ','L',' bellow.'.PadRight(44),'|' -C $BC,2,14,2,$BC DisplayMisc -Misc $BC DisplayMisc -Line -Misc $BC } Function TOS { $Invalid = $False $CR = $False While($TOS -ne 'Out') { TOSDisplay -C:$CR $CR = $False $Invalid = ShowInvalid $Invalid $TOS = Read-Host "`nDo you Accept? (Y)es/(N)o" If($TOS -In 'n','no') { Exit } ElseIf($TOS -In 'y','yes') { $TOS = 'Out' $Script:AcceptToS = 'Accepted' $Script:RunScript = 1 If($LoadServiceConfig -eq 1){ Black_Viper_Set } ElseIf($Black_Viper -eq 0){ GuiStart } Else{ Black_Viper_Set $Black_Viper $All_or_Min } } ElseIf($TOS -eq 'l') { $CR = $True ;ShowCopyright } Else { $Invalid = $True } } Return } ########## # TOS -End ########## # GUI -Start ########## Function OpenSaveDiaglog([Int]$SorO) { $SOFileDialog = If($SorO -eq 0){ New-Object System.Windows.Forms.OpenFileDialog } Else{ New-Object System.Windows.Forms.SaveFileDialog } $SOFileDialog.InitialDirectory = $FileBase $SOFileDialog.Filter = If($SorO -ne 2){ 'CSV (*.csv)| *.csv' } Else{ 'Registration File (*.reg)| *.reg' } $SOFileDialog.ShowDialog() $SOFPath = $SOFileDialog.Filename If($SOFPath) { If($SorO -eq 0) { $Script:ServiceConfigFile = $SOFPath ;$WPF_LoadFileTxtBox.Text = $ServiceConfigFile ;RunDisableCheck } ElseIf($SorO -eq 1) { Save_Service $SOFPath } ElseIf($SorO -eq 2) { RegistryServiceFile $SOFPath } } } Function HideShowCustomSrvStuff { $Vis,$TF,$WPF_CustomNoteGrid.Visibility = If(($WPF_ServiceConfig.SelectedIndex+1) -eq $BVCount){ 'Visible',$False,'Visible' } Else{ 'Hidden',$True,'Collapsed' } $WPF_RadioAll, $WPF_RadioMin | Where { $_.IsEnabled = $TF } $WPF_CustomNote, $WPF_LoadFileTxtBox, $WPF_btnOpenFile | Where { $_.Visibility = $Vis } } Function SetServiceVersion { If(Test-Path -LiteralPath $BVServiceFilePath -PathType Leaf) { $TMP = Import-Csv -LiteralPath $BVServiceFilePath $Script:ServiceVersion = $TMP[0].'BV-Def-Home' $Script:ServiceDate = $TMP[0].'BV-Def-Pro' Return $True } $Script:ServiceVersion = 'Missing File' $Script:ServiceDate = 'BlackViper.csv' Return $False } Function ClickedDonate{ OpenWebsite $Donate_Url ;$Script:ConsideredDonation = 'Yes' } Function UpdateSetting { $VarList.ForEach{ $SetValue = If($_.Value.IsChecked){ 1 } Else{ 0 } Set-Variable -Name ($_.Name.Split('_')[1]) -Value $SetValue -Scope Script } $Script:All_or_Min = If($WPF_RadioAll.IsChecked){ '-Full' } Else{ '-Min' } UpdateEdition $Script:LogName = $WPF_LogNameInput.Text $Script:BackupServiceType = $WPF_BackupServiceType.SelectedIndex } Function SaveSetting { UpdateSetting $Black_Viper = $WPF_ServiceConfig.SelectedIndex If(($Black_Viper+1) -eq $BVCount -or ($IsLaptop -eq '-Lap' -and $LaptopTweaked -ne 1 -and $Black_Viper -ge 2)){ $Black_Viper = 0 } $Settings = @{ AcceptToS = $AcceptToS EditionCheck = $EditionCheck BuildCheck = $BuildCheck LaptopTweaked = $LaptopTweaked Black_Viper = $Black_Viper All_or_Min = $All_or_Min BackupServiceConfig = $BackupServiceConfig BackupServiceType = $BackupServiceType InternetCheck = $InternetCheck ScriptVerCheck = $ScriptVerCheck ServiceVerCheck = $ServiceVerCheck ShowConsole = $ShowConsole XboxService = $XboxService StopDisabled = $StopDisabled ChangeState = $ChangeState ShowSkipped = $ShowSkipped } If($ConsideredDonation -eq 'Yes'){ $Settings.ConsideredDonation = 'Yes' } If($WPF_DevLogCB.IsChecked) { $Settings | ForEach-Object{ $_.ScriptLog = $Script_Log $_.LogName = $Log_Name $_.Diagnostic = $Diagn_ostic $_.LogBeforeAfter = $Log_Before_After $_.DryRun = $Dry_Run $_.ShowNonInstalled = $Show_Non_Installed $_.ShowAlreadySet = $Show_Already_Set } } Else { $Settings | ForEach-Object{ $_.ScriptLog = $ScriptLog $_.LogName = $LogName $_.Diagnostic = $Diagnostic $_.LogBeforeAfter = $LogBeforeAfter $_.DryRun = $DryRun $_.ShowNonInstalled = $ShowNonInstalled $_.ShowAlreadySet = $ShowAlreadySet } } If(Test-Path -LiteralPath $SettingPath -PathType Leaf) { $Tmp = (Import-Clixml -LiteralPath $SettingPath | ConvertTo-Xml).Objects.Object.Property."#text" If(($Tmp.Count/2) -eq $Settings.Count) { $T1 = While($Tmp){ $Key, $Val, $Tmp = $Tmp ;[PSCustomObject] @{ Name = $Key ;Val = $Val } } $Tmp = ($Settings | ConvertTo-Xml).Objects.Object.Property."#text" $T2 = While($Tmp){ $Key, $Val, $Tmp = $Tmp ;[PSCustomObject] @{ Name = $Key ;Val = $Val } } If(Compare-Object $T1 $T2 -Property Name,Val){ $SaveSettingFile = $True } } Else { $SaveSettingFile = $True } } Else { $SaveSettingFile = $True } If($SaveSettingFile){ $Settings | Export-Clixml -LiteralPath $SettingPath } } Function ShowConsoleWin([Int]$Choice){ [Console.Window]::ShowWindow($ConsolePtr, $Choice) }#0 = Hide, 5 = Show Function GuiStart { #Needed to Hide Console window Add-Type -Name Window -Namespace Console -MemberDefinition '[DllImport("Kernel32.dll")] public static extern IntPtr GetConsoleWindow() ;[DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);' $Script:ConsolePtr = [Console.Window]::GetConsoleWindow() Clear-Host DisplayOut 'Preparing GUI, Please wait...' -C 15 $Script:GuiSwitch = $True [xml]$XAML =@" Service Configurations: Configure Below