Access logged-in user when executing Install dialog with elevated rights - Advanced Installer Community
OliverH
Posts: 2
Joined: Wed Mar 30, 2022 2:16 pm

Access logged-in user when executing Install dialog with elevated rights

Hi!
We have the following - hopefully common - scenario:
  • Our AI-installation menu requires elevated rights, therefore accounts who want to install but dont have rights need to start the installation menu using another user (lets call that one "admin")
  • We need the username of the logged-in user (NOT the "admin" who owns the install menu's session) because we want to change their user folder C:\users\[username]\...
  • The property [USERNAME] holds the "admin" user's name.
Question: Is there a built-in function in AI to get the logged-in users name?

In case there is no such function - We already tried the following powershell-script to retrieve the logged-in user:

Code: Select all

$actualUsername = query user | Select-String '^>(\w+)' | ForEach-Object { $_.Matches[0].Groups[1].Value }
Set-Property -name "ACTUAL_USERNAME" -value $actualUsername
We need to use the query command, because commands like %username%, $env:USERNAME only return the "admin" username...

Attempting to run that script in the installer.exe failed though, because the Powershell-executable which was used by AI was this one:
C:\Windows\SysWOW64\WindowsPowerShell\v1.0 - which does not have the program query installed, whereas:
C:\WINDOWS\System32\WindowsPowerShell\v1.0 does.

Any help would be appreciated :)
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Access logged-in user when executing Install dialog with elevated rights

Hello Oliver and welcome to our forums,

Have you tried using the "LogonUser" property?

This is a Windows Installer property which should store user name for the currently logged on user, as per the above article.

Hope this helps!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
OliverH
Posts: 2
Joined: Wed Mar 30, 2022 2:16 pm

Re: Access logged-in user when executing Install dialog with elevated rights

Hello Catalin,

thank you for your quick reply :)

Unfortunately, LogonUser also resolves to "Administrator".

With regards to the powershell-script, I found out that query must run with 64-bit powershell, so that works now.


I was just wondering whether there's a build-in solution to the problem of retrieving the "active" logged-on user. The scenario "need elevated rights for installation but want to install just for user x" seems too common.
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Access logged-in user when executing Install dialog with elevated rights

You are always welcome, Oliver!

Quite strange, because as per their documentation I would expect the LogonUser to resolve to the logged on user.

Anyway, I am glad you managed to get the custom action working.

If there is anything else I could help you with, do not hesitate to reach out to me and I will gladly do so.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”