Beispiel #1
0
 static void Main(string[] args)
 {
     while (true)
     {
         using var la = new LocalAdmin();
         la.Start(args);
     }
     // ReSharper disable once FunctionNeverReturns
 }
Beispiel #2
0
        private void localAdminBindingSource_CurrentChanged(object sender, EventArgs e)
        {
            LocalAdmin localAdmin = localAdminBindingSource.Current as LocalAdmin;

            if (localAdmin == null)
            {
                return;
            }
            listBoxLocalAdmins.DataSource = localAdmin.AdminAccounts;
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        public static void Main(string[] args)
        {
            var localAdmin = new LocalAdmin();

            localAdmin.Start(args);
        }
Beispiel #5
0
 protected bool Equals(LocalAdmin other)
 {
     return(string.Equals(Server, other.Server) && string.Equals(ObjectName, other.ObjectName) && string.Equals(ObjectType, other.ObjectType));
 }
Beispiel #6
0
        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
            }
        }