Workaround for registry control restriction problems in Windows 7?

Well, since in xp most users are registered as administrators - it is easy for a programmer to make the program work with the registry. I am trying to do the following:

The software is launched and added as a startup process in the registry, however this should only be done when the application is closed, and not earlier.

However, this does not work in xp when the user is limited and the same in Vista 7,2008.

What are the workarounds? I thought that the program created the scheduled task or was attached to the process with higher privileges? Any work way? I taggin it as .net, since my software is connected to .net - actually the same thing happens in C ++, but I secretly hope that the network offers simpler methods for developing it. 10 times in advance!

0
source share
3 answers

Um, this is not a limitation of Windows 7; it is actually a design. See my answer here for more details .

What you need is called the height of the process . This is the standard way to deal with this - a mechanism built into the UAC that allows users to authenticate as administrators and temporarily gain all the privileges and responsibilities that are included in this header. Windows itself uses this everywhere:

Example of elevation shield displayed in Windows UI

There is a fantastic article on how to do this: Screen icons, UAC, and process height in .NET .
But just to generalize in case of rotting the link, here are the steps:

  • Determine if the user has the appropriate permissions. The easiest way is to call the IsUserAnAdmin API function.

  • Inform the user that the height is required using the shield icon. In WinForms, you need to set the FlatStyle button FlatStyle to System and use P / Invoke to display the screen. Code example:

     [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); public const int BCM_SETSHIELD = 0x0000160C; public static void SetButtonShield(Button btn, bool showShield) { // Verify that we're running on Vista or later if ((Environment.OSVersion.Platform == PlatformID.Win32NT) && (Environment.OSVersion.Version.Major >= 6)) { SendMessage(btn.Handle, BCM_SETSHIELD, IntPtr.Zero, showShield ? new IntPtr(1) : IntPtr.Zero); } } 
  • Restart the process with administrator privileges. This includes showing the height dialog so that the user can pick up the program. Code example:

     ProcessStartInfo psi = new ProcessStartInfo { Arguments = "-justelevated", ErrorDialog = true, // Handle is the handle for your form ErrorDialogParentHandle = Handle, FileName = Application.ExecutablePath, Verb = "runas" }; try { Process.Start(psi); Close(); } catch (Exception ex) { // the process couldn't be started. This happens for 1 of 3 reasons: // 1. The user cancelled the UAC box // 2. The limited user tried to elevate to an Admin that has a blank password // 3. The limited user tries to elevate as a Guest account MessageBox.Show(ex.Message); } 
  • [Optional] Mark the sign of your application to replace the yellow-yellow UAC box with a nicer gray or blue one.

+5
source

In any case, this should be for each user, and then you will not have problems with permission. HKCU \ Software \ Microsoft \ Windows \ CurrentVersion \ Run

+1
source

the whole purpose of limited users is to prevent this.

0
source

All Articles