Jump to content
Sign in to follow this  
Delphinus

Admin vs User rights

Recommended Posts

Delphinus

Greetings fellow coders, I have a script that changes the desktop wallpaper on a WinXP SP3 machine.

The script works fine under the administrator login but I need it to run under a user account with no administrator privileges but it will not change the wallpaper.

If anyone has any ideas I would greatly appreciate the help.

The code I have:

#NoTrayIcon
#include <GUIConstants.au3>

#region ### START Koda GUI section ### Form=
$gMain = GUICreate("Select Wallpaper", 154, 211, -1, -1, BitOR($WS_CAPTION, $WS_POPUP))
GUICtrlCreateGroup("Classification", 8, 8, 137, 161)
$rd_Unclass = GUICtrlCreateRadio("Unclassified", 40, 32, 81, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$rd_Conf = GUICtrlCreateRadio("Confidential", 40, 56, 81, 17)
$rd_Secret = GUICtrlCreateRadio("Secret", 40, 80, 81, 17)
$rd_TS = GUICtrlCreateRadio("Top Secret", 40, 104, 81, 17)
$rd_SCI = GUICtrlCreateRadio("SCI", 40, 128, 81, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$bt_OK = GUICtrlCreateButton("OK", 24, 176, 51, 25, 0)
$bt_Cancel = GUICtrlCreateButton("Cancel", 80, 176, 51, 25, 0)
GUISetState(@SW_SHOW)
#endregion ### START Koda GUI section ### Form=

Local $files[5] = ["Unclassified.bmp", "Confidential.bmp", "Secret.bmp", "TopSecret.bmp", "SCI.bmp"]
Local $nMsg, $iCurSel, $iOrigSel

$iInitial = RegRead("HKLM\Software\SSCC\BC", "")
If @error Then
    RegWrite("HKCU\Control Panel\Desktop", "WallPaper", "REG_SZ", @WindowsDir & "\Banner.bmp")
    RegWrite("HKCU\Control Panel\Desktop", "WallpaperStyle", "REG_SZ", "2")
    If @OSVersion = "WIN_VISTA" Then
        RunWait(@ComSpec & ' /c reg load HKLM\def "' & @HomeDrive & '\Users\Default\ntuser.dat"', @WindowsDir, @SW_HIDE)
    Else
        RunWait(@ComSpec & ' /c reg load HKLM\def "' & @HomeDrive & '\Documents and Settings\Default User\ntuser.dat"', @WindowsDir, @SW_HIDE)
    EndIf
    RegWrite("HKLM\def\Control Panel\Desktop", "WallPaper", "REG_SZ", @WindowsDir & "\Banner.bmp")
    RegWrite("HKLM\def\Control Panel\Desktop", "WallpaperStyle", "REG_SZ", "2")
    RunWait(@ComSpec & ' /c reg unload HKLM\def', @WindowsDir, @SW_HIDE)
EndIf
$iOrigSel = RegRead("HKLM\Software\SSCC\BC", "Classification")
Switch $iOrigSel
    Case 1
        GUICtrlSetState($rd_Conf, $GUI_CHECKED)
    Case 2
        GUICtrlSetState($rd_Secret, $GUI_CHECKED)
    Case 3
        GUICtrlSetState($rd_TS, $GUI_CHECKED)
    Case 4
        GUICtrlSetState($rd_SCI, $GUI_CHECKED)
    Case Else
        $iOrigSel = 0
EndSwitch
$iCurSel = $iOrigSel

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $rd_Conf And BitAND(GUICtrlRead($rd_Conf), $GUI_CHECKED) = $GUI_CHECKED
            $iCurSel = 1
        Case $nMsg = $rd_SCI And BitAND(GUICtrlRead($rd_SCI), $GUI_CHECKED) = $GUI_CHECKED
            $iCurSel = 4
        Case $nMsg = $rd_Secret And BitAND(GUICtrlRead($rd_Secret), $GUI_CHECKED) = $GUI_CHECKED
            $iCurSel = 2
        Case $nMsg = $rd_TS And BitAND(GUICtrlRead($rd_TS), $GUI_CHECKED) = $GUI_CHECKED
            $iCurSel = 3
        Case $nMsg = $rd_Unclass And BitAND(GUICtrlRead($rd_Unclass), $GUI_CHECKED) = $GUI_CHECKED
            $iCurSel = 0
        Case $nMsg = $bt_OK
            If $iCurSel <> $iOrigSel Then
                RegWrite("HKLM\Software\SSCC\BC", "Classification", "REG_DWORD", $iCurSel)
                FileCopy($files[$iCurSel], @WindowsDir & "\Banner.bmp", 9)
                RunWait("rundll32.exe user32.dll,UpdatePerUserSystemParameters ,1,True", @ScriptDir, @SW_HIDE)
            EndIf
            Exit
        Case $nMsg = $bt_Cancel
            Exit
    EndSelect
WEnd

Share this post


Link to post
Share on other sites
spudw2k
Delphinus

Then how does a user change the wallpaper via desktop properties?

Share this post


Link to post
Share on other sites
Delphinus

Thanks Jon but that's not what I am looking for. I was hoping to get a bit more help than to just have examples thrown at me. I wouldn't have gotten as far as I did without doing some research.

Turns out, the reason I couldn't do it as a user was that I was trying to write to the windows directory. That's something that isn't allowed as a user. I rewrote the program to have the registry reference an ini file that stores the path to the .bmp files I want to use as backgrounds.

Share this post


Link to post
Share on other sites
Jon

Thanks Jon but that's not what I am looking for. I was hoping to get a bit more help than to just have examples thrown at me. I wouldn't have gotten as far as I did without doing some research.

An exact example of the API call to change the desktop background in a totally supported way that will work on all versions of Windows rather than a nasty reg hack that likely won't?

Fine. My help here is done.

Share this post


Link to post
Share on other sites
Delphinus

Yes, that changes the desktop but not in the way that I was trying to change it.

Didn't mean to offend but all you did was throw an example at me without even looking at the code I wrote.

Share this post


Link to post
Share on other sites
spudw2k

Then how does a user change the wallpaper via desktop properties?

Any user can write to their own NTUSER.DAT file (mounted as HKEY_CURRENT_USER when logged in)

Share this post


Link to post
Share on other sites
Jon

From the script I'm not quite sure what you are trying to do. You are writing to the Default User wallpaper - but that is only used when a brand new user profile is created - it doesn't change existing wallpapers. Are you trying to change the wallpaper for ALL users that have already logged into a machine?

Share this post


Link to post
Share on other sites
Delphinus

I want to change it for the current user that is logged in when they run the script and for any user that already has a profile on the machine (including administrators) and for any new user that will login and create a new profile, ie the 'default user'.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.