Skip to content

Commit

Permalink
Added better user stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
krisdb2009 committed Jun 20, 2019
1 parent aa907ed commit 1256283
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 24 deletions.
16 changes: 12 additions & 4 deletions SuperGrate/Classes/Misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using Microsoft.Win32;
using System.Net.NetworkInformation;
using System.DirectoryServices.AccountManagement;

namespace SuperGrate
{
Expand Down Expand Up @@ -36,19 +37,26 @@ static public async Task<bool> Ping(string Host)
return false;
}
}
static public Task<string[]> GetUsersFromHost(string Host)
static public Task<Dictionary<string, string>> GetUsersFromHost(string Host)
{
return Task.Run(() =>
{
try
{
Dictionary<string, string> remoteUsers = new Dictionary<string, string>();
RegistryKey remoteReg = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, Host);
RegistryKey profileList = remoteReg.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList", false);
foreach (string profileKey in profileList.GetSubKeyNames())
PrincipalContext domContext = new PrincipalContext(ContextType.Domain);
foreach (string SID in profileList.GetSubKeyNames())
{
Logger.Success(profileKey);
UserPrincipal user = UserPrincipal.FindByIdentity(domContext, SID);
if(user != null)
{
Logger.Success("Found: " + user.Name);
remoteUsers.Add(SID, user.UserPrincipalName);
}
}
return new string[0];
return remoteUsers;
}
catch(System.Security.SecurityException e)
{
Expand Down
86 changes: 68 additions & 18 deletions SuperGrate/Main.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions SuperGrate/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,25 @@ private async void BtStart_Click(object sender, EventArgs e)
}
}

private async void TbSourceComputer_Leave(object sender, EventArgs e)
private async void BtnListSource_Click(object sender, EventArgs e)
{
lbxUsers.Items.Clear();
Logger.Information("Checking if source is online...");
if (await Misc.Ping(tbSourceComputer.Text))
{
Logger.Success("Source is online!");
Logger.Information("Gathering list of users from source...");
await Misc.GetUsersFromHost(tbSourceComputer.Text);
Dictionary<string, string> remoteUsers = await Misc.GetUsersFromHost(tbSourceComputer.Text);
if (remoteUsers != null)
{
lbxUsers.Items.AddRange(remoteUsers.Values.ToArray());
Logger.Success("Done!");
}
else
{
Logger.Error("An error has occured!");
}

}
else
{
Expand Down
1 change: 1 addition & 0 deletions SuperGrate/SuperGrate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.DirectoryServices.AccountManagement" />
<Reference Include="System.Net" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand Down

0 comments on commit 1256283

Please sign in to comment.