Click here to Skip to main content
12,954,856 members (77,985 online)
Rate this:
 
Please Sign up or sign in to vote.
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...
[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 17-Jul-12 8:32am
Updated 17-Jul-12 8: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
OriginalGriff 6,539
CHill60 3,490
Maciej Los 3,153
ppolymorphe 2,030
Jochen Arndt 1,975


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 20 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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