Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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...
C#
[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;


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! :)
Posted
Updated 17-Jul-12 8:40am
v2
Comments
[no name] 17-Jul-12 14:39pm    
And your question is what?

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[^]
 
Share this answer
 
Ended up going w/ RegistryKey.OpenRemoteBaseKey

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

//sample

C#
//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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900