Jump to content

Runas with Regwrite


Recommended Posts

Hi

I'm trying to write some registry keys by using the RunAsSet command to elevate the users privileges then write the registry entries and then set the user privileges back to the current logged in user. I've tried this using the script below.

; Set the RunAs parameters to use domain Loginscript account

RunAsSet($Username2, $Domain2, $Password2)

; Initialization of the variables

$Username2 = "LoginScript"

$Password2 = "LoginScript"

$Domain2 = "Domain"

RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "OriginalWallpaper", "REG_SZ", "C:\WINDOWS\web\Wallpaper\Wallpaper.bmp")

; Write registry Eetries for Wallpaper to current and default users

RegWrite("HKEY_USERS\.DEFAULT\Control Panel\Desktop", "OriginalWallpaper", "REG_SZ", "C:\WINDOWS\web\Wallpaper\Wallpaper.bmp")

; Reset user's permissions

RunAsSet()

I have 2 problems.

1. The HKEY_USERS entry doesn't appear therefore the users haven't got the rights to enter it (ie the runas isn't working).

2. When I use the RunAs does the HKEY_CURRENT_USER become the LoginScript user (ie the one with the elevated privileges) or does it insert the entry for the currently logged in user?

Help would be appreciated or if there's a better way then I'm all ears.

Basic Plan

Login script run on a domain server to insert backgrounds and copy the file to local drives, set keys to point to background. I know I can use GP for this but it isn't very good and I'd rather try it this way.

Eventually the script will check for the wallpaper and won't copy it across if it's not needed but I need to get the permissions sorted first.

Thanks in advance.

Swabynnaf

Link to comment
Share on other sites

  • Administrators

This is the script I've added as an example to RunAsSet.

; This example will rerun itself with admin rights on using a local account
; Note on Vista this may not work as even though the user is admin it may 
; not be elevated even after the RunAs call.  In that case use #RequireAdmin
; at the top of the script.

; Are we already admin?
If Not IsAdmin() Then
    RunAsSet('USER', @Computername, 'PASSWORD')
    Run('"' & @AutoItExe & '"' & ' "' & @ScriptFullPath & '"', @WorkingDir)
    Exit
EndIf

MsgBox(0, 'Message', 'Now running with admin rights.')

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...