This commit is contained in:
2024-05-17 11:57:16 +07:00
parent 17b4e9424c
commit 2d00fb51b0

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Management;
using System.Linq;
using System.Text.RegularExpressions;
using System.Diagnostics;
namespace domain_utility
{
@@ -31,11 +32,13 @@ namespace domain_utility
// username = "user JDM17";
//}
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("net", username);
procStartInfo.CreateNoWindow = true;
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
System.Diagnostics.Process proc = new System.Diagnostics.Process { StartInfo = procStartInfo };
ProcessStartInfo procStartInfo = new ProcessStartInfo("net", username)
{
CreateNoWindow = true,
RedirectStandardOutput = true,
UseShellExecute = false
};
Process proc = new Process { StartInfo = procStartInfo };
proc.Start();
List<string> strArr = new List<string> { };
@@ -44,6 +47,9 @@ namespace domain_utility
strArr.Add(proc.StandardOutput.ReadLine());
}
proc.Close();
proc.Dispose();
//if (args.Length > 0)
// for (int i = 0; i < strArr.Count; i++)
// Console.WriteLine(strArr[i]);
@@ -52,15 +58,11 @@ namespace domain_utility
//{
// if (strArr[i].Contains("Системная ошибка 1355."))
// {
// proc.Close();
// proc.Dispose();
// Console.WriteLine("Программа работает только с доменом.");
// return;
// }
// if (strArr[i].Contains("Не найдено имя пользователя."))
// {
// proc.Close();
// proc.Dispose();
// Console.WriteLine("Пользователь не найден! Попробуйте еще раз.");
// return;
// }
@@ -94,16 +96,13 @@ namespace domain_utility
}
}
proc.Close();
proc.Dispose();
Console.WriteLine("\nНажмите чтобы закрыть...");
Console.ReadLine();
ShowDomainUserInfo();
}
private static void ShowComputerBootupTime()
{
Console.WriteLine("\nВведите имя компьютера (пр. 'R54-630300IT04'): ");
Console.WriteLine("\nВведите IP адрес или имя компьютера (пр. 'R54-630300IT04'): ");
string computerName = Console.ReadLine().Trim();
var scope = new ManagementScope(string.Format(@"\\{0}\root\cimv2", computerName));
try
@@ -112,7 +111,7 @@ namespace domain_utility
var query = new ObjectQuery("SELECT LastBootUpTime FROM Win32_OperatingSystem");
var searcher = new ManagementObjectSearcher(scope, query);
var firstResult = searcher.Get().OfType<ManagementObject>().First(); //assumes that we do have at least one result
Console.WriteLine("Last bootup time: " + ManagementDateTimeConverter.ToDateTime(firstResult["LastBootUpTime"].ToString()));
Console.WriteLine("Дата последней загрузки: " + ManagementDateTimeConverter.ToDateTime(firstResult["LastBootUpTime"].ToString()));
/*ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
@@ -127,22 +126,22 @@ namespace domain_utility
Console.WriteLine("Manufacturer : {0}", m["Manufacturer"]);
}*/
}
catch (Exception)
catch (System.Runtime.InteropServices.COMException)
{
//Console.WriteLine(ex.Message);
Console.WriteLine("Компьютер не найден. Попробуйте еще раз.");
ShowComputerBootupTime();
}
Console.WriteLine("\nНажмите чтобы закрыть...");
Console.ReadLine();
ShowComputerBootupTime();
}
static void Main(string[] args)
{
Console.WriteLine("Выберите действие:\n1 - посмотреть информацию о пользователе\n2 - посмотреть дату последней загрузки компьютера");
string choice = Console.ReadLine();
switch(Convert.ToInt32(choice))
switch (Convert.ToInt32(choice))
{
case 1: ShowDomainUserInfo(); break;
case 2: ShowComputerBootupTime(); break;