我如何重命名密钥 [英] How I can rename a key

查看:132
本文介绍了我如何重命名密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我读了这个 RegRenameKey - 隐藏的注册表API Pavel的博客 [ ^ ]



我正在尝试重命名这个键:



代码:

Hello i read this RegRenameKey – Hidden registry API | Pavel's Blog[^]

I am trying to rename the key doing this:

Code:

using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication7
{
    class Program
    {
        private static readonly IntPtr HKEY_LOCAL_MACHINE = new IntPtr(-2147483646);
        [DllImport("advapi32")]
        public static extern int RegRenameKey(SafeRegistryHandle hKey, [MarshalAs(UnmanagedType.LPWStr)] string oldname,
        [MarshalAs(UnmanagedType.LPWStr)] string newname);
        static void Main(string[] args)
        {
            
            SafeRegistryHandle hKey = null;
            hKey = new SafeRegistryHandle(HKEY_LOCAL_MACHINE,true);
            RegRenameKey(hKey, "SOFTWARE\\Company", "SOFTWARE\\Compa");
            Console.ReadLine();
            
        }
    }
}





我尝试过:



i试图重命名程序编译好的密钥,但此刻我会重新命名关键帮助pls ..



What I have tried:

i was trying to rename the key the program compile fine but at the moment i dind get rename the key help pls..

推荐答案

这里有几个问题:

1)您正在使用未记录的函数。这是危险的,因为绝对不能保证它们会:

1.1)工作。

1.2)在一个操作系统上工作,而不是为它编写的。 />
1.3)存在以后的操作系统。



2)访问注册表受到严格限制 - 有充分理由 - 而且非常非常可能您需要管理员访问才能完成任务;可能的情况是,此类访问将来会受到更多限制,而不是更少。建议任何人都不要将注册表用于新项目。



你的应用程序中发生的事情最有可能是因为你未记录的功能失败了没有权限这样做并且函数吞下错误。



您可以尝试使用提升的应用程序,看看是否有效,但是说实话,你最好不要让所有人都使用更现代的设置文件。
There are a couple of problems here:
1) You are using undocumented functions. This is dangerous as there is absolutely no guarantee that they will:
1.1) Work.
1.2) Work on an operating system other than that it was written for.
1.3) Exist on later OSes.

2) Access to the registry is heavily restricted - for good reasons - and it is very,very likely that you require Admin access in order to do very much at all; the likelyhood is that such access will become more restricted in future, not less. It is not recommended that anyone use the registry for new projects at all.

What is happening in your app is most likely to be that the undocumented function is failing because you don't have permission to do that and that the function "swallows" the error.

You could try this with an elevated app and see if that works, but to be honest you would be better off leaving the registry well allone and using a more modern settings file.


这篇关于我如何重命名密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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