Pages

Tuesday, 7 March 2023

Wallpaer PS script

function Set-Wallpaper {
    param (

        [string]$Path,

        [ValidateSet('Tile', 'Center', 'Stretch', 'Fill', 'Fit', 'Span')]

        [string]$Style = 'Fill'

    )
    begin {
        try {
            Add-Type @"
                using System;
                using System.Runtime.InteropServices;
                using Microsoft.Win32;
                namespace Wallpaper
                {  public enum Style : int
                    {  Tile, Center, Stretch, Fill, Fit, Span, NoChange

                    }
                    public class Setter

                    {
                        public const int SetDesktopWallpaper = 20;

                        public const int UpdateIniFile = 0x01;

                        public const int SendWinIniChange = 0x02;

                        [DllImport( "user32.dll", SetLastError = true, CharSet = CharSet.Auto )]

                        private static extern int SystemParametersInfo ( int uAction, int uParam, string lpvParam, int fuWinIni );

                        public static void SetWallpaper ( string path, Wallpaper.Style style )

                        {

                            SystemParametersInfo( SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange );

                            RegistryKey key = Registry.CurrentUser.OpenSubKey( "Control Panel\\Desktop", true );

                            switch( style )

                            {

                                case Style.Tile :

                                key.SetValue( @"WallpaperStyle", "0" ) ;

                                key.SetValue( @"TileWallpaper", "1" ) ;

                                break;

                                case Style.Center :

                                key.SetValue( @"WallpaperStyle", "0" ) ;

                                key.SetValue( @"TileWallpaper", "0" ) ;

                                break;

                                case Style.Stretch :

                                key.SetValue( @"WallpaperStyle", "2" ) ;

                                key.SetValue( @"TileWallpaper", "0" ) ;

                                break;

                                case Style.Fill :

                                key.SetValue( @"WallpaperStyle", "10" ) ;

                                key.SetValue( @"TileWallpaper", "0" ) ;

                                break;

                                case Style.Fit :

                                key.SetValue( @"WallpaperStyle", "6" ) ;

                                key.SetValue( @"TileWallpaper", "0" ) ;

                                break;

                                case Style.Span :

                                key.SetValue( @"WallpaperStyle", "22" ) ;

                                key.SetValue( @"TileWallpaper", "0" ) ;

                                break;

                                case Style.NoChange :

                                break;

                            }

                            key.Close();

                        }

                    }

                }

"@

        } catch {}



        $StyleNum = @{

            Tile = 0

            Center = 1

            Stretch = 2

            Fill = 3

            Fit = 4

            Span = 5

        }

    }
    process {

        [Wallpaper.Setter]::SetWallpaper($Path, $StyleNum[$Style])
        sleep -s 5

        [Wallpaper.Setter]::SetWallpaper($Path, $StyleNum[$Style])

    }

}
#App Details

$str_App = 'INWPC000001ENGC1 - Inspire Wallpaper Update'

$str_PackageCode = 'INWPC000001ENGC1'

#Create Log folder

$Str_ProgramData = $env:ProgramData

$Str_LogFolder = "$Str_ProgramData\IntuneWin32Apps"

if(!(Test-Path -Path $Str_LogFolder )){

  New-Item -ItemType directory -Path $Str_LogFolder

}

$str_LogFile = "$Str_LogFolder\IntuneWin32Apps.log"

#Write App

$str_LogEntry = "$(Get-Date) ; $str_App"

Add-Content $str_LogFile $str_LogEntry



#Write Version

$str_LogEntry = "$(Get-Date) ; Version 1"

Add-Content $str_LogFile $str_LogEntry





#Write Start to Log File

$str_LogEntry = "$(Get-Date) ; Install Starting"

Add-Content $str_LogFile $str_LogEntry



# Setting up Wallaper

$StrLAppdata = $env:LOCALAPPDATA

$str_folder = split-path $script:MyInvocation.MyCommand.Path

$Str_Wallpaper = "$StrLAppdata\Unilever"

if(!(Test-Path -Path $Str_Wallpaper )){

  New-Item -ItemType directory -Path $Str_Wallpaper

}

$Source_path=Join-Path -Path $str_folder -ChildPath "\C19"

$Des_Path=Join-path -Path $StrLAppdata -ChildPath "\Unilever\"

Copy-item $Source_Path -Destination $Des_Path -Force -Recurse -Verbose

#Checking the screen resolution

Add-Type -AssemblyName System.Windows.Forms

$Resolution= "{0}x{1}" -f [System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Width,[System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Height

write-host $Resolution

#Write Log

$str_LogEntry = "$(Get-Date) ; ScreenResolution is: $Resolution"

Add-Content $str_LogFile $str_LogEntry

#Setting wallpaper based on screen resolution

if ($Resolution  -eq '1920x1080')

{ start-process (Set-WallPaper -Path "$StrLAppdata\Unilever\C19\Wallpaper1.jpg" -Style Fill)

  $str_LogEntry = "$(Get-Date) ; Wallpaper Set: $StrLAppdata\Unilever\C19\Wallpaper1.jpg"

  Add-Content $str_LogFile $str_LogEntry

}



elseif ($Resolution  -eq '2133x1600')

{ start-process (Set-WallPaper -Path "$StrLAppdata\Unilever\C19\Wallpaper2.jpg" -Style Fill)

  $str_LogEntry = "$(Get-Date) ; Wallpaper Set: $StrLAppdata\Unilever\C19\Wallpaper2.jpg"

  Add-Content $str_LogFile $str_LogEntry

}



elseif ($Resolution  -eq '4000x2250')

{ start-process (Set-WallPaper -Path "$StrLAppdata\Unilever\C19\Wallpaper3.jpg" -Style Fill)

  $str_LogEntry = "$(Get-Date) ; Wallpaper Set: $StrLAppdata\Unilever\C19\Wallpaper3.jpg"

  Add-Content $str_LogFile $str_LogEntry

}



else

{ start-process (Set-WallPaper -Path "$StrLAppdata\Unilever\C19\Wallpaper2.jpg" -Style Fill)

  $str_LogEntry = "$(Get-Date) ; Default Wallpaper Set: $StrLAppdata\Unilever\C19\Wallpaper2.jpg"

  Add-Content $str_LogFile $str_LogEntry

}

if (!(Test-Path -Path "HKCU:\SOFTWARE\Unilever\Packages")){

New-Item -Path "HKCU:\SOFTWARE\Unilever\Packages" -Force

}
New-ItemProperty "HKCU:\SOFTWARE\Unilever\Packages" -Name "INWPC000001ENGC1_Installed" -Value "Intune_WP_Installed" -PropertyType "String" -Force | Out-Null

#Close Log File

$str_LogEntry = "-----------------------"

Add-Content $str_LogFile $str_LogEntry 

No comments:

Post a Comment

User based detection

function getloggedindetails () {     ##Find logged in username     $user = Get-WmiObject Win32_Process - Filter "Name='explorer...

Search This Blog