解决方法针对Windows 7的注册表操作的限制? [英] Workaround against registry manipulation limitation in windows 7?

查看:273
本文介绍了解决方法针对Windows 7的注册表操作的限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定这样的,因为在XP中大多数人都记录为管理员 - 很容易为程序员做的注册表程序的工作。我所试图做的是这样的:

Ok so since in xp most people are logged as admins - it's easy for a programmer to make a program work with the registry. What I am trying to do is this:

该软件启动,它的添加为登记处启动过程不过应该是这样的,只有当应用程序被关闭 - 而不是之前。

The software is started and it's added as a startup process in the registry- however this should be done only when the application is closing - not before.

不过,这并不在XP中,当用户在Vista中,7,2008年度有限的,同样的事情。

However this doesn't work in xp when the user is limited and same thing in vista,7,2008.

什么解决方法?我想,以使程序创建计划任务或者被连接到进程具有较高privilleges?任何工作方式?我taggin这是.NET,因为我的软件是.NET相关 - 其​​实同样的事情发生在C ++ - 但我暗暗希望,净提供更容易的方法来解决它。 10X提前!

What are the workarounds? I was thinking to make the program create a scheduled task or being attached to a process with higher privilleges? Any working way? I am taggin this as .net since my software is .net related - actually same thing happens and in c++ - but i secretly hope that net offers easier methods to work it out. 10x in advance!

推荐答案

嗯,这不是一个的限制的的Windows 7;它实际上是由设计。 <一href="http://stackoverflow.com/questions/5210575/does-windows-7-have-the-same-problem-as-vista/5210642#5210642">See我的答案这里了解详细信息。

Um, this isn't a limitation of Windows 7; it's actually by-design. See my answer here for details.

您需要什么叫做工艺海拔。这是处理这个问题的标准方式,内置的UAC机制,允许用户验证自己的管理员,并暂时获得所有这一切都与这个称号的权限和职责。 Windows本身使用这一切的地方:

What you need is called process elevation. It's the standard way of dealing with this, a mechanism built into UAC to allow users to authenticate themselves as Administrators and temporarily gain all of the privileges and responsibilities that come with this title. Windows itself uses this all over the place:

有一个梦幻般的如何,在这里提供的文章: <一个href="http://wyday.com/blog/2009/using-shield-icons-uac-and-process-elevation-in-csharp-vb-net-on-windows-2000-xp-vista-and-7/">Shield图标,UAC和工艺抬高.NET 。
但为了在链路腐总结一下,这里的步骤:

There's a fantastic how-to article available here: Shield icons, UAC, and process elevation in .NET.
But just to summarize in case of link rot, here are the steps:

  1. 确定用户是否具有相应的权限了。最简单的方法是调用 IsUserAnAdmin API函数。

  1. Determine if the user has the appropriate permissions already. The simplest way is calling the IsUserAnAdmin API function.

通知高程使用屏蔽图标,需要的用户。在的WinForms,你需要设置按钮的的FlatStyle 属性设置为系统,并使用P / Invoke来显示屏蔽。样品code:

Notify the user that elevation is required using a "shield" icon. In WinForms, you need to set the button's FlatStyle property to "System", and use P/Invoke to display the shield. Sample code:

[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);
    }
}

  • 重新推出具有管理员权限的进程。这涉及到示出了提升对话框以允许用户提升该程序。样品code:

  • Re-launch the process with administrator privileges. This involves showing the elevation dialog to allow the user to elevate the program. Sample code:

    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);
    }
    

  • [可选] code签署您的应用程序,以取代敌对,面色发黄UAC提升盒,更加赏心悦目灰色或蓝色的。

  • [Optional] Code sign your application to replace the hostile-looking yellow UAC elevation box with a more pleasing gray or blue one.

    这篇关于解决方法针对Windows 7的注册表操作的限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆