// POST api/wordperfect public void Post([FromBody] Computer value) { comp = value; Process proc = new Process(); proc.StartInfo.UserName = AdminAccounts.GetAdminAccount1().UserName; proc.StartInfo.Password = AdminAccounts.GetAdminAccount1().SecurePassword; proc.StartInfo.Domain = Domain.GetDomain(); proc.StartInfo = new ProcessStartInfo(@"cmd.exe", String.Format(@"/c installWordPerfect.cmd {0}", value.IPAddress)); proc.StartInfo.WorkingDirectory = @"C:\Manage\WordPerfect"; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.RedirectStandardError = true; //proc.EnableRaisingEvents = true; proc.OutputDataReceived += (sender, args) => UpdateStatus(args.Data); proc.ErrorDataReceived += (sender, args) => UpdateStatus(args.Data); noErrorCount = 0; proc.Start(); proc.BeginOutputReadLine(); proc.BeginErrorReadLine(); proc.WaitForExit(60); }
// POST api/estimatediskusage public DiskUsage Post([FromBody] Computer computer) { string IPAddress = computer.IPAddress; Process proc = new Process(); proc.StartInfo.UserName = AdminAccounts.GetAdminAccount1().UserName; SecureString secure = AdminAccounts.GetAdminAccount1().SecurePassword; proc.StartInfo.Domain = Domain.GetDomain(); proc.StartInfo.Password = secure; proc.StartInfo = new ProcessStartInfo(@"cmd.exe", String.Format(@"/c getDiskUsage.bat {0} C:", IPAddress)); proc.StartInfo.WorkingDirectory = @"C:\Manage\EstimateDiskSpace"; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardOutput = true; proc.Start(); string output = proc.StandardOutput.ReadToEnd(); proc.WaitForExit(10); string[] lines = output.Split(new string[] { "\r\n" }, StringSplitOptions.None); DiskUsage diskUsage = new DiskUsage() { TotalSpace = lines[0].Substring(13, lines[0].Length - 13), FreeSpace = lines[1].Substring(12, lines[1].Length - 12), UsedSpace = lines[2].Substring(12, lines[2].Length - 12), PercentUsed = lines[3].Substring(14, lines[3].Length - 14), PercentFree = lines[4].Substring(14, lines[4].Length - 14) }; return(diskUsage); }
private void CheckServices() { ConnectionOptions op = new ConnectionOptions(); op.Username = AdminAccounts.GetAdminAccount2().UserName; op.Password = AdminAccounts.GetAdminAccount2().Password; ManagementScope scope = new ManagementScope(String.Format(@"\\{0}\root\cimv2", comp.IPAddress), op); scope.Connect(); ManagementPath path = new ManagementPath("Win32_Service"); ManagementClass services = new ManagementClass(scope, path, null); bool foundTSM = false; for (int i = 0; i < 5 && !foundTSM; i++) { foundTSM = CheckForTSMService(services); if (!foundTSM) { UpdateStatus("Service error, trying again."); Thread.Sleep(1000); } } if (!foundTSM) { UpdateStatus("There was an error setting up TSM Scheduler."); } }
public ActionResult MoveInAD(string computerName, string ADPath) { const int ldapErrorInvalidCredentials = 0x31; ViewBag.ComputerName = computerName; ViewBag.CurrentOUDN = ADPath; string server = Domain.GetDomain() + ":636"; string domain = Domain.GetDomain(); SecureString secure = AdminAccounts.GetAdminAccount3().SecurePassword; if (String.IsNullOrWhiteSpace(ADPath)) { ADPath = ADPaths.GetDefaultPath(); } try { using (var ldapConnection = new LdapConnection(server)) { var networkCredential = new NetworkCredential(AdminAccounts.GetAdminAccount3().UserName, secure, Domain.GetDomain()); ldapConnection.SessionOptions.SecureSocketLayer = true; ldapConnection.AuthType = AuthType.Negotiate; ldapConnection.Bind(networkCredential); string DistinguishedName = GetObjectDistinguishedName(objectClass.computer, returnType.distinguishedName, computerName, Domain.GetDomain()); List <string> DNList = DistinguishedName.Split(',').ToList(); string finalOU = DNList.Skip(1).Take(1).First(); string finalOUName = finalOU.Substring(3, finalOU.Length - 3); ViewBag.CurrentOU = finalOUName; List <string> NewDNList = ADPath.Split(',').ToList(); string parentOU = NewDNList.Skip(1).Take(1).First(); string parentOUName = parentOU.Substring(3, parentOU.Length - 3); string parentOUDN = string.Join(",", NewDNList.Skip(1).ToArray()); ViewBag.ParentOUDN = parentOUDN; List <string> Children = EnumerateOU(ADPath); ViewBag.Children = Children; } } catch (LdapException ldapException) { if (ldapException.ErrorCode.Equals(ldapErrorInvalidCredentials)) { } } return(View()); }
public ActionResult EnableAD(string computerName) { Process proc = new Process(); proc.StartInfo.UserName = AdminAccounts.GetAdminAccount1().UserName; proc.StartInfo.Password = AdminAccounts.GetAdminAccount1().SecurePassword; proc.StartInfo.Domain = Domain.GetDomain(); proc.StartInfo = new ProcessStartInfo(@"cmd.exe", "/c enable.cmd " + computerName); proc.StartInfo.WorkingDirectory = @"C:\Manage\EnableAD"; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardOutput = true; proc.Start(); proc.WaitForExit(10); ViewBag.ComputerName = computerName; return(View()); }
// GET api/computerfromou/5 public List <string> Get(string id) { List <string> ComputerNames = new List <string>(); string ADPath = id; const int ldapErrorInvalidCredentials = 0x31; string server = Domain.GetDomain() + ":636"; SecureString secure = AdminAccounts.GetAdminAccount3().SecurePassword; if (String.IsNullOrWhiteSpace(ADPath)) { ADPath = ADPaths.GetDefaultPath(); } try { using (var ldapConnection = new LdapConnection(server)) { var networkCredential = new NetworkCredential(AdminAccounts.GetAdminAccount3().UserName, secure, Domain.GetDomain()); ldapConnection.SessionOptions.SecureSocketLayer = true; ldapConnection.AuthType = AuthType.Negotiate; ldapConnection.Bind(networkCredential); foreach (var child in EnumerateOU(ADPath)) { ComputerNames.Add(child.Split(',').ToList().Take(1).First().Substring(3, child.Split(',').ToList().Take(1).First().Length - 3)); } } } catch (LdapException ldapException) { if (ldapException.ErrorCode.Equals(ldapErrorInvalidCredentials)) { } } return(ComputerNames); }
public ActionResult MoveInADConfirmed(string computerName, string ADPath) { ViewBag.ComputerName = computerName; string DistinguishedName = GetObjectDistinguishedName(objectClass.computer, returnType.distinguishedName, computerName, Domain.GetDomain()); Process proc = new Process(); proc.StartInfo.UserName = AdminAccounts.GetAdminAccount1().UserName; SecureString secure = AdminAccounts.GetAdminAccount1().SecurePassword; proc.StartInfo.Password = secure; proc.StartInfo = new ProcessStartInfo(@"cmd.exe", "/c move.cmd \"" + DistinguishedName.Replace("LDAP://", "") + "\" \"" + ADPath + "\""); proc.StartInfo.WorkingDirectory = @"C:\Manage\MoveAD"; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardOutput = true; proc.Start(); proc.WaitForExit(10); return(View()); }
public static bool IsAppInstalled(string p_machineName) { ConnectionOptions op = new ConnectionOptions(); op.Username = AdminAccounts.GetAdminAccount2().UserName; op.Password = AdminAccounts.GetAdminAccount2().Password; ManagementScope scope = new ManagementScope(String.Format(@"\\{0}\root\cimv2", p_machineName), op); scope.Connect(); ManagementPath path = new ManagementPath("Win32_Product"); ManagementClass programs = new ManagementClass(scope, path, null); foreach (ManagementObject program in programs.GetInstances()) { object programName = program.GetPropertyValue("Name"); if (programName != null && programName.ToString().Equals("WordPerfect Office 11", StringComparison.OrdinalIgnoreCase)) { return(true); } } return(false); }
// GET api/ou/5 public OUInfo Get(string id) { List <OU> ListOfContainers = new List <OU>(); string ADPath = id; const int ldapErrorInvalidCredentials = 0x31; string server = Domain.GetDomain() + ":636"; string domain = Domain.GetDomain(); SecureString secure = AdminAccounts.GetAdminAccount3().SecurePassword; if (String.IsNullOrWhiteSpace(ADPath)) { ADPath = ADPaths.GetDefaultPath(); } try { using (var ldapConnection = new LdapConnection(server)) { var networkCredential = new NetworkCredential(AdminAccounts.GetAdminAccount3().UserName, secure, Domain.GetDomain()); ldapConnection.SessionOptions.SecureSocketLayer = true; ldapConnection.AuthType = AuthType.Negotiate; ldapConnection.Bind(networkCredential); List <string> NewDNList = ADPath.Split(',').ToList(); string parentOU = NewDNList.Skip(1).Take(1).First(); string parentOUName = parentOU.Substring(3, parentOU.Length - 3); string parentOUDN = string.Join(",", NewDNList.Skip(1).ToArray()); OU ParentOU = new OU() { ShortName = "..", FullName = parentOUDN }; ListOfContainers.Add(ParentOU); foreach (var child in EnumerateOU(ADPath)) { OU ChildOU = new OU() { ShortName = child.Split(',').ToList().Take(1).First(), FullName = child }; ListOfContainers.Add(ChildOU); } } } catch (LdapException ldapException) { if (ldapException.ErrorCode.Equals(ldapErrorInvalidCredentials)) { } } return(new OUInfo { CurrentContainer = ADPath, ListOfContainers = ListOfContainers }); }