Tatyana Mykhnevych
Posts: 40
Joined: Thu Feb 13, 2020 4:47 pm

Show proper error on failure

Mon Jul 19, 2021 12:33 pm

Hello,

I extract Temp files for my App to Temp Folder. And after extracting the needed file I launch it using Custom Action. It looks like on the screen.

And Domain Users do not have access to Temp Folder. If add Domain User to Local Administrators Membership Group it will work.
But I want to show a proper error message for it ("User XXX os not part of ... ") and write this error to the log file (it is not written to the log). How can I achieve this?

Looking forward to hearing from you.

Best regards,
Tanya
Attachments
Untitled.png
Untitled.png (118.98KiB)Viewed 22275 times

Dan
Posts: 4513
Joined: Wed Apr 24, 2013 3:51 pm

Re: Show proper error on failure

Mon Jul 19, 2021 3:07 pm

Hi Tanya,

You can write your own custom action to check if the user belongs to Domain Users group and write into log file.

To do that you can run a PowerShell script, something like this:

Code: Select all

$user = $user = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name 
$groups = 'Domain Users'
 
foreach ($group in $groups) {
   $members = Get-ADGroupMember -Identity $group -Recursive | Select -ExpandProperty SamAccountName
 
   If ($members -contains $user) {
       Write-Output "$user is a member of $group"
   } Else {
       Write-Output "$user is not a member of $group"
   }
} 
Feel free to make any changes to the above script. You can write to the MSI installation log by simply using the "Write-Output" cmdlet into your PowerShell custom action code.

If you want to display a message, then you can use the predefined Display message box custom action. In the above script you can set a property that can be further used to condition the execution of the custom action that display the message.

If you want to display the message directly from the PowerShell script, please use the below code:

Code: Select all

[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
[System.Windows.Forms.MessageBox]::Show("$env:USERNAME" + " is not part of Domain Users group.")
Hope this helps. If you have any other questions, please don't hesitate to contact us.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Tatyana Mykhnevych
Posts: 40
Joined: Thu Feb 13, 2020 4:47 pm

Re: Show proper error on failure

Tue Jul 20, 2021 7:41 am

Can I check not user group but if user has an access to this folder and files?

Dan
Posts: 4513
Joined: Wed Apr 24, 2013 3:51 pm

Re: Show proper error on failure

Tue Jul 20, 2021 8:51 am

Hi Tanya,

You can do that using custom action. You can write your own program in C#/C++, something you are familiar with, or you can also use a script like PowerShell or VBScript. If you don't know how to do that, a good point to start is from Powershell command to check if user has permissions to a folder article.

Also, if you need to configure permissions for your installation folder, then you can use our "Permissions" support. Just go to "Files and Folders" page, right click on the "Application Folder", choose "Properties" and then go to "Permissions" tab. More information on Permissions article.

Hope this works! If you have any other questions, please don't hesitate to contact us.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”