Click here to Skip to main content
Rate this:
 
Please Sign up or sign in to vote.
See more: C# Remote
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;

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! Smile | :)
Posted 17-Jul-12 9:32am
Edited 17-Jul-12 9:40am
v2
Comments
Wes Aday 17-Jul-12 14:39pm
   
And your question is what?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Web04 | 2.8.160207.1 | Advertise | Privacy
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100