Sign in to follow this  
Followers 0
tAKTelapis

Set desktop backgroun on login

7 posts in this topic

Hey guys,

im after a way to set a desktop background when a computer logs in.

i have a 20 kb jpg file that i want to set. but cant work out how. ive tried things such as BGInfo.. but these change the jpg to a BMP, and then its like 4Mbs.. way to big IMHO.

any ideas appreciated.

cheers

/tAK

Share this post


Link to post
Share on other sites



Hey guys,

im after a way to set a desktop background when a computer logs in.

i have a 20 kb jpg file that i want to set. but cant work out how. ive tried things such as BGInfo.. but these change the jpg to a BMP, and then its like 4Mbs.. way to big IMHO.

any ideas appreciated.

cheers

/tAK

Is your question related to autoit3 or windows?

Share this post


Link to post
Share on other sites

im pretty sure images have to be in .bmp format to be used as a background...


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

im pretty sure images have to be in .bmp format to be used as a background...

WinXP can take .jpg but what does his posting in autoit forum has to do with this?

Share this post


Link to post
Share on other sites

Hey guys,

im after a way to set a desktop background when a computer logs in.

i have a 20 kb jpg file that i want to set. but cant work out how. ive tried things such as BGInfo.. but these change the jpg to a BMP, and then its like 4Mbs.. way to big IMHO.

any ideas appreciated.

cheers

/tAK

hey,

i could be wrong but ill think you will find that even if you manually set a JPG file as the background picture, windows still converts it to a BMP before displaying (try setting a JPG file as the background pic and then check out C:\Documents and Settings\username\Local Settings\Application Data\Microsoft and you should find a file in here called Wallpaper1.bmp which should be a BMP of the JPG file you selected.

As for your script i had something along those lines except i never worked out how to get it to refresh the Background Pic on login (always required a logoff to take effect... pretty sure there is a rundll32 call somewhere to refresh the desktop though).

;Checks to see if the Operating System is Windows XP
OS_check()

Func OS_check()
    $operating_system = @OSVersion ;@OSVersion returns what Windows Operating System the user is using
    If $operating_system = "WIN_XP" Then ;Just checks the $operating_system variable to make sure it is Windows XP
        bg_id() ;If so it proceeds to bg_id() function
    Else
        MsgBox(64, "Error #OS01: Operating System Unsupported", "Currently only Windows XP is supported by this program. Cheers, Shane.")
        Exit
    EndIf
EndFunc


;Checks to see if bg_id.ini file exists in C:\Documents and Settings\username\Local Settings\Application Data\Microsoft (this is where Windows places converted images that are used as backgrounds, it also converts them to BMP (bitmap) files
Func bg_id()
    $program_bgid = IniRead(@ScriptDir & "\bgsettings.ini", "bgc", "bgid", "0") ;@ScriptDir returns the path that the script is running from without a trailing backslash, it then points to the bgsettings.ini file which must be placed in the same folder for the script to run
    If $program_bgid = "0" Then
        MsgBox(64, "Error #INIr01: Unable to read the 'bgsettings.ini' file.", "The program was unable to read the 'bgsettings.ini' file.  Maybe it has been deleted or removed. The program will now exit.")
        Exit
    EndIf
    If FileExists(@UserProfileDir & "\Local Settings\Application Data\Microsoft\bgid.ini") Then ;This checks to see if the bgid.ini file exists, if not it proceeds copy_bg() function, if it does exist it checks to see if the bgid values are the same, if so it exits the program, if not it proceeds to copy_bg(0 function
        $local_bgid = IniRead(@UserProfileDir & "\Local Settings\Application Data\Microsoft\bgid.ini", "bgc", "bgid", "0")
        If $local_bgid = $program_bgid Then
            Exit
        Else
            copy_bg() ;Proceeds to copy_bg() function if the values are different
        EndIf
    Else
        copy_bg() ;Proceeds to copy_bg() function if no bgid.ini file exists (it will be created in that function)
    EndIf
EndFunc



;Copies a file named 'Wallpaper1.bmp' to the users profile directory into C:\Documents and Settings\username\Local Settings\Application Data\Microsoft, the wallpaper must be named Wallpaper1.bmp and must reside in the same file that the application is run from 
Func copy_bg()
    $bg_copy = FileCopy(@ScriptDir & "\Wallpaper1.bmp", @UserProfileDir & "\Local Settings\Application Data\Microsoft", 1)
    If $bg_copy = 0 Then
        MsgBox(64, "Error #FC01: Unable to copy the Background Picture", "Sorry but the program was unable to successfully copy the background picture to the User's Profile directory. The program will now exit.")
        Exit
    EndIf
    $changed_bgid = IniRead(@ScriptDir & "\bgsettings.ini", "bgc", "bgid", "0") ;Checks the new bgid value in the bgsettings.ini file from the program directory, it will use this same value on the local machine in the bgid.ini file. The next time the program is run if these to values are the same the program will exit and not bother copying the background 
    If $changed_bgid = "0" Then
        MsgBox(64, "Error #INIr04: Unable to read the 'bgsettings.ini' file.", "The program was unable to read the 'bgsettings.ini' file.  Maybe it has been deleted or removed. The program will now exit.")
        Exit
    EndIf
    $bgid_iniwrite = IniWrite(@UserProfileDir & "\Local Settings\Application Data\Microsoft\bgid.ini", "bgc", "bgid", $changed_bgid) ;Writes the value of $changed_bgid to the bgid.ini file used for comparison purposes for future runnings of the program
    If $bgid_iniwrite = 0 Then
        MsgBox(64, "Error #INIw01: Unable to write to the 'bgid.ini' file.", "The program was unable to write to the 'bgid.ini' file in the user's profile directory. The program will now exit.")
        Exit
    EndIf
    registry_change() ;Proceeds to the registry_change() function if the copy is successful
EndFunc


;Changes the Regsitry for the current user to point the background to the file that was just copied
Func registry_change()
    $bg_registry = RegRead("HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper") ;Reads the current value of HKEY_CURRENT_USER\Control Panel\Desktop\Wallpaper 
    If $bg_registry = @UserProfileDir & "\Local Settings\Application Data\Microsoft\Wallpaper1.bmp" Then ;If it already points to the users profile directory (@UserProfileDir\Local Settings\Application Data\Microsoft\Wallpaper1.bmp then the program exits here) it assumes the the originalwallpaper setting is also the same
        Exit
    Else
        $bg_regwrite1 = RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper", "REG_SZ", @UserProfileDir & "\Local Settings\Application Data\Microsoft\Wallpaper1.bmp") ;If it doesn't already point here it updates to registry entries, to point to the copied wallpaper
        If $bg_regwrite1 = 0 Then
            MsgBox(64, "Error #REG01: Unable to write value to registry", "Sorry but the program was unable to write the value to the registry. The program will now exit.")
            Exit
        EndIf
        $bg_regwrite2 = RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "OriginalWallpaper", "REG_SZ", @UserProfileDir & "\Local Settings\Application Data\Microsoft\Wallpaper1.bmp")
        If $bg_regwrite2 = 0 Then
            MsgBox(64, "Error #REG02: Unable to write value to registry", "Sorry but the program was unable to write the value to the registry. The program will now exit.")
            Exit
        EndIf       
    EndIf
EndFunc

Exit

This copies a file from where the script is being run (the file should be called Wallpaper1.bmp, simply open your JPG in MSPaint or equilavent and export as 24-bit BMP) to the current user's app data/microsoft folder. It also requires an ini file in the same directory called bgsettings.ini which when opened looks like:

[bgc]

bgid=3

^^ The number can be whatever you like as long as it's not 0 and if the program succeeds in copying the Wallpaper to the user profile it puts an ini file and won't copy the background again on next run (unless you change the value from the bgsettings.ini to a different value). I used this in a school environment via login scripts and it seemed to work well enough allthough it's got alot of fluff which probaly isn't needed.

Anyway hope it helps,

Cheers

Share this post


Link to post
Share on other sites

cheers for the info there,

it seems to do what i want.. however, in the mean time i have trawled through the GPO and found one for forcing a desktop BG.

it sets it on login.

i wanted it for a school environment myself, and students can still change the image if they know what they are doing, but at least next logon it gets forced back. they eventually lose interest in changing it.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Use this script:

;Writting data to the registry

RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop","Wallpaper","REG_SZ",locationOfYourImage.ext")

;;Call DLL for showing background now

DllCall("user32","int","SystemParametersInfo","int",20,"int",0,"str","locationOfYourImage.ext","int",0)

Compile the script and place it in your startup folder, so it will run every time the (or an) user logon

This is the very basic version of the scipt, you will maybe add some things by yourself.

Only tested on Windows XP SP2 (Dutch version)

sorry for my bad english,

I'm dutch

Edited by djo4ever

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0