Jump to content

Profile problem in RunAsSet()


kftang
 Share

Recommended Posts

I have a script run in domain. When the users login with a generic account (No Admin permission), the script will activate the RunAsSet() function to 'runas' an Admin account which is transparency to the users. The problem is once runas Admin account, the profile will change. What I want is when users login with a generic account, it loads the current profile as normal. This current profile don't change even though it runas Admin account.

I did set the RunAsSet parameter to 0 and 1 respectively, but it doesn't help. If the parameter set to 0, it do not load the profile, the @UserProfileDir = "c:\documents and settings\Dafult user. If the parameter set to 1, it loads the profile but the @UserProfileDir = "c:\documents and settings\Admin. These are not I want. I would like to have

@UserProfileDir = "c:\documents and settings\generic" even when it is running inside RunAsSet() function.

Appreicate if anybody can help!

Link to comment
Share on other sites

Hi Blakel,

I still cannot get your mind in "use $myProfile vs @UserProfileDir". For my understand, RunAsSet(user, domain, password) is used to run the process as another account. Once activate this function, it can only use Run() or RunWait() function to achieve the process. After finish the process, use RunAsSet() to reset back to current login account. How to use $myProfile instead of @UserProfileDir within Run() or RunWait() function? Below is portion of my script, can you show me how to modify it? Thanks.

;*****************************************************************

; Function to run the scripts with Admin account

;*****************************************************************

Func Runas_Exec($RunasUser, $RunasPass, $KixScript, $ConsoleSize)

Dim $SeatrackMsg

Dim $KixSoftware, $ScriptPath

Dim $NetLogon, $SubNetLogon, $RunScript

$KixSoftware = "Kix32"

$NetLogon = "Netlogon"

$SubNetLogon = "Seatrack"

$ScriptPath = @LogonServer & "\" & $NetLogon & "\" & $SubNetLogon _

& "\" & $KixScript

If FileExists($ScriptPath) <> 1 Then

$SeatrackMsg = $ScriptPath & " does not exist"

MsgBox(48, @ScriptName, $SeatrackMsg, 6)

Else

$SeatrackMsg = $ScriptPath & " exists"

; MsgBox(64, @ScriptName, $SeatrackMsg, 6)

EndIf

RunAs_Convert($RunasUser, $RunasPass)

$RunScript = RunWait($KixSoftware & " " & $KixScript, @LogonServer _

& "\" & $NetLogon & "\" & $SubNetLogon, $ConsoleSize)

; MsgBox(64, @ScriptName, "RunScript = " & $RunScript _

; & " Error no.= " & @error, 6)

RunAsSet()

If $RunScript <> 0 Then

$SeatrackMsg = $KixScript & " return error " _

& $RunScript

MsgBox(48, @ScriptName, $SeatrackMsg, 5)

Else

$SeatrackMsg = $KixScript & " return success"

; MsgBox(64, @ScriptName, $SeatrackMsg, 5)

EndIf

EndFunc

;*****************************************************************

; Function to switch to Admin account

;*****************************************************************

Func RunAs_Convert($RunasUser, $RunasPass)

Dim $SeatrackMsg

Dim $RunAsConvert

$RunAsConvert = RunAsSet($RunasUser, @LogonDomain, $RunasPass, 1)

; MsgBox(64, @ScriptName, "RunAsConvert = " & $RunAsConvert _

; & " Error no.= " & @error, 6)

If $RunAsConvert <> 1 Then

$SeatrackMsg = "Runas Admin return error " _

& $RunAsConvert

MsgBox(16, @ScriptName, $SeatrackMsg & @CRLF & _

"Press 'OK' button to shutdown the PC")

Shutdown(13)

Else

$SeatrackMsg = "Runas Admin return success"

; MsgBox(64, @ScriptName, $SeatrackMsg, 5)

EndIf

EndFunc

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...