2

I am preparing a PowerShell script to perform initial configuration on some Windows 10 hosts. One of the configuration steps involves a problem with an older piece of software requesting administration elevation, which it does not need. This software is not called by the script itself, but will be used by users as required. The solution requires that I set a compatibility flag forcing the program to run as invoker for all users - I'm trying to figure out a way to implement this solution in the configuration script.

To do this, I can add a string value to the registry key HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers. The string value's name is the absolute path of the executable in question, and its data value is ~ RUNASINVOKER. Putting this into a Powershell script is not a problem.

The problem is that this alone does not work, even after restarting the machine. In order to make it take effect, I need to right click on the executable in explorer and choose properties, select "Change settings for all users" under the compatibility tab, then simply click OK in the new dialogue without changing any settings.

It seems as though this process does something to refresh or initialise my compatibility settings, but I am unclear what happens, much less how to implement in a PowerShell script.

I should add that the process also works in reverse. I can add the registry value after doing the "Change settings for all users" fix and it will take effect immediately.

Does anyone understand what is happening to make my registry addition take effect, and how I can implement this in a PowerShell script?

Thank you.

RobBeltran
  • 21
  • 1
  • 4

2 Answers2

1

I'm guessing the software running is a call to start a .exe file? Could you try this line ABOVE the line that runs your application?

set __COMPAT_LAYER=RunAsInvoker
Joe Brailsford
  • 1,181
  • 8
  • 10
  • Hi Joe, sorry for not being clear - the .exe itself isn't run as part of the script, the script just performs initial configuration. The .exe will be run as needed throughout normal use. – RobBeltran Jun 23 '17 at 07:45
0

When you change the settings to be for all users, it takes the entry out of

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers

and then puts them into

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers

or

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers

If you have a key in both, I believe that the current user one overrides the local machine one and if they are different, it might not work as expected.

David Parvin
  • 101
  • 1