Using RunAppFlags.NoElevation

Ask general questions here.
User avatar
doke
Posts: 112
Joined: Fri Mar 29, 2019 2:33 pm

Using RunAppFlags.NoElevation

Post by doke » Thu Dec 22, 2022 11:26 am

Hi,
I would like to use following code to make sure my Clickonce application is always started without admin rights

But the sut is not started when ranorex is running as admin:
using System.Security.Principal; //needed for IsAdministrator()

public void RunMy_application()
        {
            // old code Host.Local.RunApplication("C:\\Windows\\System32\\rundll32.exe", "C:\\Windows\\System32\\dfshim.dll,ShOpenVerbApplication "+ MySutAddress, "",false);
            var MyAppflag = RunAppFlags.None; 
            if (IsAdministrator()) {
            	MyAppflag = RunAppFlags.NoElevation;
            }
            Host.Local.RunApplication("C:\\Windows\\System32\\rundll32.exe", "C:\\Windows\\System32\\dfshim.dll,ShOpenVerbApplication "+ MySutAddress, "",false , MyAppflag);
            
        }

		public static bool IsAdministrator()
		{
		    using (WindowsIdentity identity = WindowsIdentity.GetCurrent())
		    {
		        WindowsPrincipal principal = new WindowsPrincipal(identity);
		        return principal.IsInRole(WindowsBuiltInRole.Administrator);
		    }
		}
Anyone have an idea how to solve this ?

Regards,
Don

User avatar
doke
Posts: 112
Joined: Fri Mar 29, 2019 2:33 pm

Re: Using RunAppFlags.NoElevation

Post by doke » Tue Oct 17, 2023 4:45 pm

Bump.
Anyone ?

How to use Host.Local.RunApplication with RunAppFlags.None when ranorex is elevated and not elevated ?