static void Main(string[] args) { while (true) { using var la = new LocalAdmin(); la.Start(args); } // ReSharper disable once FunctionNeverReturns }
private void localAdminBindingSource_CurrentChanged(object sender, EventArgs e) { LocalAdmin localAdmin = localAdminBindingSource.Current as LocalAdmin; if (localAdmin == null) { return; } listBoxLocalAdmins.DataSource = localAdmin.AdminAccounts; }
public override async Task <DialogTurnResult> ContinueDialogAsync(DialogContext outerDc, CancellationToken cancellationToken = default(CancellationToken)) { var dialog = FindDialog(nameof(LocalAdminPrompt)); var dialogResult = await dialog.ContinueDialogAsync(outerDc, cancellationToken).ConfigureAwait(false); if (dialogResult.Status == DialogTurnStatus.Complete) { var result = dialogResult.Result as LocalAdminPrompt; LocalAdmin admin = new LocalAdmin() { AdminDuration = result.AdminDuration, MachineName = result.MachineName }; using (var db = new ContosoHelpdeskContext()) { db.LocalAdmins.Add(admin); db.SaveChanges(); } } return(dialogResult); }
public static void Main(string[] args) { var localAdmin = new LocalAdmin(); localAdmin.Start(args); }
protected bool Equals(LocalAdmin other) { return(string.Equals(Server, other.Server) && string.Equals(ObjectName, other.ObjectName) && string.Equals(ObjectType, other.ObjectType)); }
private static void ScanIp(string ip, string hostName = "") { try { LocalAdmin localAdmin = new LocalAdmin(); localAdmin.Ip = ip; localAdmin.HostName = hostName; DirectoryEntry localMachine = new DirectoryEntry("WinNT://" + ip); DirectoryEntry admGroup = localMachine.Children.Find("administrators", "group"); object members = admGroup.Invoke("members", null); foreach (object groupMember in (IEnumerable)members) { DirectoryEntry member = new DirectoryEntry(groupMember); localAdmin.AdminAccounts.Add(new Account { Path = member.Path, Name = member.Name, Type = member.SchemaClassName }); } try { sqlCommand.Parameters.Clear(); sqlCommand.CommandText = "[dbo].[InsertComputer]"; sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@computerName", localAdmin.HostName); sqlCommand.Parameters.AddWithValue("@localScan", DateTime.Now); sqlCommand.ExecuteNonQuery(); sqlCommand.Parameters.Clear(); sqlCommand.CommandType = CommandType.Text; sqlCommand.CommandText = "delete [dbo].[LocalAdmins] where ComputerName = @ComputerName"; sqlCommand.Parameters.AddWithValue("@ComputerName", localAdmin.HostName); sqlCommand.ExecuteNonQuery(); foreach (Account account in localAdmin.AdminAccounts) { sqlCommand.Parameters.Clear(); sqlCommand.CommandType = CommandType.Text; sqlCommand.CommandText = "INSERT INTO [dbo].[LocalAdmins] ([ComputerName],[AccountName],[Path],[AccountType]) VALUES (@ComputerName, @AccountName, @Path, @AccountType)"; sqlCommand.Parameters.AddWithValue("@ComputerName", localAdmin.HostName); sqlCommand.Parameters.AddWithValue("@AccountName", account.Name); sqlCommand.Parameters.AddWithValue("@Path", account.Path); sqlCommand.Parameters.AddWithValue("@AccountType", account.Type); sqlCommand.ExecuteNonQuery(); } } catch (Exception e) { } } catch (Exception e) { //taranamayan ipler } }