win2000、xp或以上的系统下能否通过程序修改其他windows用户的注册表,如果可行能不能说一下方法
谢谢

解决方案 »

  1.   

    很难。注册表 HKEY_USERS下面是所有用户的配置,像HKEY_USERS\S-1-5-12这样的,但是其中只有一个是当前用户的,而且这个项被映射到了HKEY_CURRENT_USER下面,但是要想知道其他用户的像"S-1-5-12"这样的标识,是很难的。
      

  2.   

    大概这样试试,用LogonUser API取得其他用户的Security Token,用ImpersonateUser将当前线程转换到该用户名下,调用LoadUserProfile装入用户设定(包括注册表项),读写注册表,将当前线程转换回来。IntPtr tokenHandle;
    LogonUser(username, domain, password, ... , ref tokenHandle);         // 登录用户
    WindowsIdentity newId = new WindowsIdentity(tokenHandle);             // 创建用户身法
    WindowsImpersonationContext impersonatedUser = newId.Impersonate();   // 将当前线程转换到该用户名下
    LoadUserProfile(tokenHandle, ...);                                    // 装入用户注册表
    //... 读写注册表
    impersonatedUser.Undo();                                              // 将当前线程切换回来。WindowsImpersonationContext类 有调用LogonUser的例子
    LoadUserProfile 介绍了LoadUserProfile的用法。你也可以试着用该调用拿到的指向用户注册表项的句柄来读写注册表。读写注册表可参考Microsoft.Win32.RegistryKey等类。
      

  3.   

    要有管理员权限,
    Demo:
     RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\MSCRM", false);
                retval = (string)key.GetValue(keyName);key.Close();
                return retval;
      

  4.   

    C#修改注册表(IE),以修改IE代理服务器为例:using System;
    using System.Collections;
    using System.Threading;
    using System.Runtime.InteropServices;
    using System.Diagnostics;
    using Microsoft.Win32;namespace TestBlog
    {
        class Program
        {
            [DllImport(@"wininet",
            SetLastError = true,
            CharSet = CharSet.Auto,
            EntryPoint = "InternetSetOption",
            CallingConvention = CallingConvention.StdCall)]        public static extern bool InternetSetOption
            (
            int hInternet,
            int dmOption,
            IntPtr lpBuffer,
            int dwBufferLength
            );
            public static void SetProxy(string proxy)
            {
                //打开注册表
                RegistryKey regKey = Registry.CurrentUser;
                string SubKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";
                RegistryKey optionKey = regKey.OpenSubKey(SubKeyPath, true);
                //更改健值,设置代理,
                optionKey.SetValue("ProxyEnable", 1);
                optionKey.SetValue("ProxyServer", proxy);            //激活代理设置
                InternetSetOption(0, 39, IntPtr.Zero, 0);
                InternetSetOption(0, 37, IntPtr.Zero, 0);
            }
        }
      

  5.   


    "LocalMachine\\Software\\Microsoft\\MSCRM",没找到这一项,请问这项里包含什么内容
      

  6.   

    NetUserAdd FunctionThe NetUserAdd function adds a user account and assigns a password and privilege level.
      

  7.   

    注册表的数据文件不是一个,而是很多个。其中HKCU信息是从用户目录(c:\My Documents\username\...)
    下的NTUSER.DAT和USRCLASS.DAT中装载的。不用的用户登录后,注册表会加载不同的HKCU信息。有就是说,用户登录后HKCU中的信息,在该用户没有登录的情况下,是找不到的。即使你用了管理员权限也没有用。至于HKEY_USERS下的HKEY_USERS\S-1-5-12,并不是真正的用户,而是内置用户的SID。比如S-1-5-18是Local System帐号。
    真正用户的SID格式像这样(其中有个GUID):S-1-5-21-1547161642-813497703-xxxxxxxx-1003这就是为什么我在4楼的回复让你尝试LogonUser和LoadUserProfile。