80sGuy Posted November 27, 2020 Posted November 27, 2020 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
MattHiggs Posted November 29, 2020 Posted November 29, 2020 Have you tried using a macro to determine the path to use? Like @UserProfileDir or @LocalAppDataDir? Check out the below web page: https://www.autoitscript.com/autoit3/docs/macros.htm
Subz Posted November 30, 2020 Posted November 30, 2020 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
80sGuy Posted December 7, 2020 Author Posted December 7, 2020 On 11/28/2020 at 11:07 PM, MattHiggs said: Have you tried using a macro to determine the path to use? Like @UserProfileDir or @LocalAppDataDir? Check out the below web page: https://www.autoitscript.com/autoit3/docs/macros.htm I did try a few of these but as the script is being run as admin it only picks up that username and not the logged in user.
rudi Posted December 8, 2020 Posted December 8, 2020 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!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now