Jump to content

Recommended Posts

Posted

Hi there. This is my first post on the forum but I'm a long time lurker.

I would really appreciate some help with trying to run an MSI that's (by default) placed into the logged in users appdata\local\... directory from a script executed with elevated rights. 
I used _RunWithReducedPrivileges to install it which worked great however removing the application seems to need more work.

I'm looking to set my $path to the logged in users appdata directory and then run that MSI, I'm assuming, with _RunWithReducedPrivileges. I would also consider copying that file over to my @ScritpDir if I could just reach it. 

Every time I try to capture my path in a msgbox it shows the one of the admin, not the user. 

I found this script which does a nice job capturing the username but I'm having trouble passing that username into my $path.
 

#RequireAdmin

MsgBox(0, 0, @UserName)
MsgBox(0, 0, _GetUsername())

Func _GetUsername()
    Local $aResult = DllCall("Wtsapi32.dll", "int", "WTSQuerySessionInformationW", "int", 0, "dword", -1, "int", 5, "dword*", 0, "dword*", 0)
    If @error Or $aResult[0] = 0 Then Return SetError(1, 0, 0)
    Local $sUsername = BinaryToString(DllStructGetData(DllStructCreate("byte[" & $aResult[5] & "]", $aResult[4]), 1), 2)
    DllCall("Wtsapi32.dll", "int", "WTSFreeMemory", "ptr", $aResult[4])
    Return $sUsername
EndFunc   ;==>_GetUsername

 

Posted

Usually I use "@DocumentsCommonDir" which by default everyone has access to, otherwise you could use the code above but you need to strip white space from the beginning and end of $sUsername (I did anyway).

Global $g_sLocalAppData = _GetLocalAppData()
If @error Then MsgBox(4096, "Error", "Error: Local AppData Folder not found.")
MsgBox(4096, "Local AppData Folder", $g_sLocalAppData)

Func _GetLocalAppData()
    Opt("ExpandEnvStrings", 1)
        Local $sUsersDir = RegRead((@OSArch = "X64" ? "HKLM64" : "HKLM") & "\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList", "ProfilesDirectory")
            $sUsersDir = $sUsersDir
    Opt("ExpandEnvStrings", 0)
   Local $aResult = DllCall("Wtsapi32.dll", "int", "WTSQuerySessionInformationW", "int", 0, "dword", -1, "int", 5, "dword*", 0, "dword*", 0)
    If @error Or $aResult[0] = 0 Then Return SetError(1, 0, 0)
    Local $sUsername = BinaryToString(DllStructGetData(DllStructCreate("byte[" & $aResult[5] & "]", $aResult[4]), 1), 2)
    DllCall("Wtsapi32.dll", "int", "WTSFreeMemory", "ptr", $aResult[4])
    Local $sLocalAppData = $sUsersDir & "\" & StringStripWS($sUsername, 7) & "\AppData\Local"
    If FileExists($sLocalAppData) Then
        Return SetError(0, 0, $sLocalAppData)
    Else
        Return SetError(1, 0, "")
    EndIf
EndFunc   ;==>_GetUsername

 

Posted

Drop that script into the appropriate user's %APPDATA% directory. Then within the script use @scriptdir macro to retrieve the path the script has been dropped to before.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

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
  • Recently Browsing   0 members

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