We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

stefan_riediger
Posts: 33
Joined: Fri Feb 18, 2022 4:07 pm

How to check if DOMAIN_NAME/USER_NAME has Administrator privileges

Dear Advanced Installer Team,

Summary
  • How to check if DOMAIN_NAME/USER_NAME has Administrator privileges?
  • How to Import-Module Microsoft.Powershell.LocalAccounts?
Details
I'm using the build-in LoginInformationDlg with DOMAIN_NAME and USER_NAME properties for specifying the credentials of the windows service, which I want to install.

The service must have administrator privileges. Therefore I want to check whether the user is part of the admin group.
I want to check this with Get-LocalGroupMember

Code: Select all

    
    $admins_sid = [System.Security.Principal.SecurityIdentifier]::new("S-1-5-32-544")
    $administrators = Get-LocalGroupMember -SID $admins_sid | Select-Object -ExpandProperty name
    $userHasAdministratorPrivileges = $administrators -icontains $domainUser
When i run the script I get an error when I call Get-LocalGroupMember
The term 'Get-LocalGroupMember' is not recognized as the name of a cmdlet, function, script file, or operable program
The reason is that the Microsoft.Powershell.LocalAccounts module is not loaded.

Therefore I want to import the module with

Code: Select all

Import-Module Microsoft.Powershell.LocalAccounts
Unfortunately I get an error ResourceUnavailable.

You can reproduce it with an PowerShell inline Script

Code: Select all

#Requires -version 3
Param()

# Let's see which Powershell we're using. Feel free to remove this function
Function Say-Hello() {
Get-Module
Import-Module Microsoft.Powershell.LocalAccounts
Get-Module
}

# Your code goes here
Say-Hello
Im running Windows Server 2019.
When i execute Get-Module from a PowerShell command prompt the LocalAccounts module is available. The problem is that it is not available when I run it from within Advanced Installer or the MSI setup.

Do you have any hints?

best regards,
Stefan
Catalin
Posts: 7853
Joined: Wed Jun 13, 2018 7:49 am

Re: How to check if DOMAIN_NAME/USER_NAME has Administrator privileges

Hello Stefan,

I've run some tests on my end and can confirm this behavior.

Please give me some more time to further investigate this and I will followup here once I will reach a conclusive answer.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Catalin
Posts: 7853
Joined: Wed Jun 13, 2018 7:49 am

Re: How to check if DOMAIN_NAME/USER_NAME has Administrator privileges

Hello Stefan,

As promised, here is my followup.

After further testing, it looks like a limitation of the PowerShell platform.

That module looks to only be available for x64 PowerShell.

Screenshot_22.png
Screenshot_22.png (4.74 KiB) Viewed 9122 times
Screenshot_25.png
Screenshot_25.png (66.77 KiB) Viewed 9122 times
Screenshot_26.png
Screenshot_26.png (17.93 KiB) Viewed 9117 times

To work this around, you can set your PowerShell script to run on x64 platform by following these steps:

- go to "Custom Actions" page

- select your PowerShell custom action

- click on the "PowerShell Script Options" hyperlink

- select x64 for "Platform"
Screenshot_24.png
Screenshot_24.png (13.72 KiB) Viewed 9122 times

However, please keep in mind that this would fail on 32-bit operating systems.

We can also leave the "Platform" on "Auto". What this does is:

- on x86 OSs, the 32-bit PowerShell will be used (since it's the only one available anyway)

- on x64 OSs, the 64-bit PowerShell will be used

Once again, this will fail on 32-bit Operating Systems since this module is only available for x64.

Hope this helps!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
stefan_riediger
Posts: 33
Joined: Fri Feb 18, 2022 4:07 pm

Re: How to check if DOMAIN_NAME/USER_NAME has Administrator privileges

Yes, perfect, that works for my use case. Thank you very much. :)
Catalin
Posts: 7853
Joined: Wed Jun 13, 2018 7:49 am

Re: How to check if DOMAIN_NAME/USER_NAME has Administrator privileges

You are always welcome, Stefan!

Glad to hear it works! :)


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

Return to “Common Problems”