C#通过变量获取远程注册表值 [英] C# pulling remote registry value w/ variables

查看:130
本文介绍了C#通过变量获取远程注册表值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试从远程域计算机中提取注册表值,以查看上次登录的用户.

因此,我有几个字段用于用户名,密码和计算机名..基于这些数据,我试图查看远程计算机的注册表并提取此键...当前,我在Powershell中执行此操作...

Trying to pull registry values from remote domain machines to see who last logged on.

So I have a couple of fields for username, pass and computername..Based on that data I am trying to view the registry of the remote machine and pull this key...Currently I do this in Powershell...

[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine","remotepcname").OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI").getvalue("LastLoggedOnUser")

string Username;
string Password;
String Computer;
Computer = txtIP.Text;
Username = txtUsername.Text;
Password = txtPassword.Text;



我需要的是当我执行一个按钮时,该按钮将填充Admin auth和计算机名称的那些变量,并将该值拉入txtResult字段..

抱歉,我是C#的新手,非常感谢您的帮助!我在Google上找到了一些东西,但我还没到那里...再次感谢! :)



What I need is when I execute a button that it fills in those variables for Admin auth and the computer name and pulls that value into txtResult field..

Sorry I am new to C# so I really appreciate any help! I found some stuff on google but I am not quite there yet... Thanks again! :)

推荐答案

OpenSubKey()是否返回您需要的值?

它返回一个RegistryKey对象.您可能应该从返回的对象中获取所需的信息.

http://msdn.microsoft.com/en-us/library/z9f66s0a.aspx [ ^ ]
Doesn''t OpenSubKey() return the values you need?

It returns a RegistryKey object. You should probably get the info you need from the returned object.

http://msdn.microsoft.com/en-us/library/z9f66s0a.aspx[^]


最终通过RegistryKey.OpenRemoteBaseKey

IE.
RegistryKey配置单元= RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine,remotemachine,RegistryView.Registry64);

//样本

Ended up going w/ RegistryKey.OpenRemoteBaseKey

I.e.
RegistryKey hive = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, remotemachine, RegistryView.Registry64);

//sample

//Clears last run result
            txtResult.Clear();
            //Begin Error Handling
            try
            {
                //Sets variable for remote machine field
                string remotemachine;
                remotemachine = txtComputer.Text;
                // hourglass cursor
                Cursor.Current = Cursors.WaitCursor;

                //Begin Code to check Registry
                RegistryKey hive = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, remotemachine, RegistryView.Registry64);
                var key = hive.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI");
                if (key == null)
                {
                }
                object oVal = key.GetValue("LastLoggedOnUser"); if (null != oVal)
                {
                txtResult.Text = oVal.ToString();
                //Return Curson
                Cursor.Current = Cursors.Default;
                //End Registry Check


这篇关于C#通过变量获取远程注册表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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