コード例 #1
0
ファイル: ComputerDetails.cs プロジェクト: TomasVetrik/GDS
        public void SetComputerDetails()
        {
            try
            {
                computerDetails = new List <string>();
                computerDetailsData.RealPCName = System.Environment.MachineName;
                computerDetails.Add("Computer Name||" + computerDetailsData.RealPCName);

                var MacAddress = HardwareInfo.GetMacAddresses();
                if (MacAddress.Count == 0)
                {
                    SetComputerDetails();
                    return;
                }

                computerDetailsData.macAddresses = MacAddress;
                computerDetailsData.MacAddress   = MacAddress[0];
                computerDetails.Add("MacAddress||" + MacAddress);
                computerDetailsData.OSInformations = HardwareInfo.GetOSInformation();
                computerDetails.Add("OS Informations||" + computerDetailsData.OSInformations);
                computerDetailsData.processorInfo = HardwareInfo.GetProcessorInformation();
                computerDetails.Add("Processor Informations||" + computerDetailsData.processorInfo);
                computerDetailsData.physicalMemoryInfo = HardwareInfo.GetPhysicalMemory();
                computerDetails.Add("Memory Size||" + computerDetailsData.physicalMemoryInfo);
                computerDetailsData.numberOfRamSLots = HardwareInfo.GetNoRamSlots();
                computerDetails.Add("Used Memory Slots||" + computerDetailsData.numberOfRamSLots);
                computerDetailsData.biosCaption = HardwareInfo.GetBIOScaption();
                computerDetails.Add("BIOS Caption||" + computerDetailsData.biosCaption);
                computerDetailsData.boardProductId = HardwareInfo.GetBoardProductId();
                computerDetails.Add("Board ID||" + computerDetailsData.boardProductId);
                computerDetailsData.accountName = HardwareInfo.GetAccountName();
                computerDetails.Add("User Account Name||" + computerDetailsData.accountName);
                computerDetailsData.baseImageName = GetBaseImageName();
                computerDetails.Add("BASE NAME||" + computerDetailsData.baseImageName);
                computerDetailsData.driveEImageName = GeDriveEImageName();
                computerDetails.Add("DRIVEE NAME||" + computerDetailsData.driveEImageName);
                computerDetailsData.dartInfo = GetDartViewerInfo(0);
                computerDetails.Add("Dart Viewer||" + computerDetailsData.dartInfo + "END");
            }
            catch
            {
                Console.WriteLine("SOMETHING WRONG WITH GET COMPUTER DETAILS");
                Thread.Sleep(5000);
                SetComputerDetails();
            }
        }
コード例 #2
0
ファイル: MessageHandler.cs プロジェクト: TomasVetrik/GDS
        public void HandleMessage(Packet packet, Connection connection)
        {
            try
            {
                WriteToLogs(packet.ID.ToString());
                switch (packet.ID)
                {
                case FLAG.REFRESH_COMPUTER_DETAILS_DATA:
                {
                    listener.computerDetails.computerDetailsData.CustomLog = HardwareInfo.GetInstalledApps();
                    listener.SendMessage(new Packet(FLAG.SYN_FLAG, listener.computerDetails.computerDetailsData));
                    break;
                }

                case FLAG.SYN_FLAG:
                {
                    listener.SendMessage(new Packet(FLAG.SYN_FLAG, listener.computerDetails.computerDetailsData));
                    break;
                }

                case FLAG.CLOSE:
                {
                    //Environment.Exit(0);
                    break;
                }

                case FLAG.SEND_TASK_CONFIG:
                {
                    bool error = false;
                    try
                    {
                        packet.taskData.TargetComputers = new System.Collections.Generic.List <ComputerDetailsData>
                        {
                            listener.computerDetails.computerDetailsData
                        };
                        if (listener.computerDetails.computerDetailsData.inWinpe)
                        {
                            try
                            {
                                if (File.Exists(@"X:\TaskData.my"))
                                {
                                    File.Delete(@"X:\TaskData.my");
                                    Thread.Sleep(1000);
                                }
                                FileHandler.Save <TaskData>(packet.taskData, @"X:\TaskData.my");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("There is problem with TASK DATA SAVING!!" + ex.ToString());
                            }
                        }
                        else
                        {
                            FileHandler.Save <TaskData>(packet.taskData, @".\TaskData.my");
                        }
                    }
                    catch (Exception ex)
                    {
                        error = true;
                        Console.WriteLine("There is problem with TASK DATA!!" + ex.ToString());
                    }
                    if (!error)
                    {
                        listener.SendMessage(new Packet(FLAG.SEND_TASK_CONFIG, listener.computerDetails.computerDetailsData));
                    }
                    break;
                }

                case FLAG.FINISH_RUN_COMMAND:
                {
                    Console.WriteLine("WAITING FOR FINISH RUN COMMAND");
                    break;
                }

                case FLAG.RUN_COMMAND:
                {
                    listener.SendMessage(new Packet(FLAG.RUN_COMMAND, listener.computerDetails.computerDetailsData));
                    if (!runningCommands)
                    {
                        runningCommands = true;
                        string pathTaskData = @".\TaskData.my";
                        if (listener.computerDetails.computerDetailsData.inWinpe)
                        {
                            pathTaskData = @"X:\TaskData.my";
                        }
                        if (File.Exists(pathTaskData))
                        {
                            var taskData     = FileHandler.Load <TaskData>(pathTaskData);
                            var listCommands = taskData.CommandsInOS;
                            if (listener.computerDetails.computerDetailsData.inWinpe)
                            {
                                listCommands = taskData.CommandsInWINPE;
                            }
                            foreach (string arguments in listCommands)
                            {
                                RunCommand("cmd.exe", "/C " + arguments);
                            }
                            listener.SendMessage(new Packet(FLAG.FINISH_RUN_COMMAND, listener.computerDetails.computerDetailsData));
                            runningCommands = false;
                        }
                    }
                    break;
                }

                case FLAG.CLONING:
                {
                    listener.SendMessage(new Packet(FLAG.CLONING, listener.computerDetails.computerDetailsData));
                    if (!cloning)
                    {
                        cloningThread = new Thread(WorkingOnTask);
                        cloningThread.Start();
                    }
                    break;
                }

                case FLAG.RESTART:
                {
                    if (cloning)
                    {
                        Process[] procs = Process.GetProcessesByName("wdsmcast");
                        foreach (Process p in procs)
                        {
                            p.Kill();
                        }
                        Process p2 = Process.GetProcessById(CloneProcess.Id);
                        p2.Kill();
                        Process[] procs2 = Process.GetProcessesByName("diskpart");
                        foreach (Process p in procs2)
                        {
                            p.Kill();
                        }
                        File.WriteAllText(@"X:\CloneStatus.txt", "RESTART");
                    }
                    cloningDoneReceive = true;
                    break;
                }

                case FLAG.CLONING_DONE:
                {
                    cloning            = false;
                    cloningDoneReceive = true;
                    break;
                }

                case FLAG.SEND_CONFIG:
                {
                    listener.SendMessage(new Packet(FLAG.SEND_CONFIG, listener.computerDetails.computerDetailsData));
                    if (listener.computerDetails.computerDetailsData.inWinpe)
                    {
                        FileHandler.Save(packet.computerConfigData, @"X:\Configuration.my");
                        string pathTaskData = @"X:\TaskData.my";
                        if (File.Exists(pathTaskData))
                        {
                            var taskData = FileHandler.Load <TaskData>(pathTaskData);
                            if (taskData.WithoutVHD)
                            {
                                FileHandler.Save(packet.computerConfigData, @"D:\Configuration.my");
                            }
                            else
                            {
                                FileHandler.Save(packet.computerConfigData, @"C:\Configuration.my");
                            }
                        }
                    }
                    else
                    {
                        FileHandler.Save(packet.computerConfigData, @"D:\Configuration.my");
                        var FileName         = @"C:\windows\system32\WindowsPowershell\v1.0\powershell";
                        var args             = @"(Get-WmiObject -Class win32_ComputerSystem).rename(" + "\'" + packet.computerConfigData.Name + "\')";
                        var processStartInfo = new ProcessStartInfo
                        {
                            FileName  = FileName,
                            Arguments = args,
                            RedirectStandardOutput = true,
                            CreateNoWindow         = true,
                            WindowStyle            = ProcessWindowStyle.Hidden,
                            UseShellExecute        = false
                        };
                        var process = Process.Start(processStartInfo);
                        process.WaitForExit();
                        args             = @"(Get-WmiObject -Class Win32_ComputerSystem).JoinDomainOrWorkgroup(" + "\'" + packet.computerConfigData.Workgroup + "\')";
                        processStartInfo = new ProcessStartInfo
                        {
                            FileName  = FileName,
                            Arguments = args,
                            RedirectStandardOutput = true,
                            CreateNoWindow         = true,
                            WindowStyle            = ProcessWindowStyle.Hidden,
                            UseShellExecute        = false
                        };
                        process = Process.Start(processStartInfo);
                        process.WaitForExit();
                    }
                    break;
                }

                case FLAG.CLIENT_TO_WINPE:
                {
                    if (listener.computerDetails.computerDetailsData.inWinpe)
                    {
                        listener.SendMessage(new Packet(FLAG.CLIENT_TO_WINPE, listener.computerDetails.computerDetailsData));
                    }
                    else
                    {
                        if (!restarting)
                        {
                            restarting = true;
                            RunCommand(@"D:\Temp\GDS_Initialize.bat", "");
                        }
                    }
                    break;
                }

                case FLAG.FINISH_COPY_FILES:
                {
                    listener.SendMessage(new Packet(FLAG.FINISH_COPY_FILES, listener.computerDetails.computerDetailsData));
                    break;
                }

                case FLAG.START_COPY_FILES:
                {
                    listener.SendMessage(new Packet(FLAG.START_COPY_FILES, listener.computerDetails.computerDetailsData));
                    if (tcp_unicast == null)
                    {
                        tcp_unicast = new TCP_UNICAST(listener.serverIP, Convert.ToInt32(packet.clonningMessage));
                        if (tcp_unicast.error)
                        {
                            Packet packet_temp = new Packet(FLAG.ERROR_MESSAGE, listener.computerDetails.computerDetailsData)
                            {
                                clonningMessage = tcp_unicast.Message
                            };
                            listener.SendMessage(packet_temp);
                        }
                        tcp_unicast = null;
                    }
                    break;
                }

                case FLAG.TO_OPERATING_SYSTEM:
                {
                    if (listener.computerDetails.computerDetailsData.inWinpe)
                    {
                        if (!restarting)
                        {
                            restarting = true;
                            Process.Start(@"X:\Windows\System32\wpeutil.exe", "reboot");
                        }
                    }
                    else
                    {
                        listener.SendMessage(new Packet(FLAG.TO_OPERATING_SYSTEM, listener.computerDetails.computerDetailsData));
                    }
                    break;
                }

                case FLAG.SHUTDOWN:
                {
                    listener.SendMessage(new Packet(FLAG.SHUTDOWN, listener.computerDetails.computerDetailsData));
                    if (!shutdowning)
                    {
                        shutdowningThread = new Thread(Shutdowning);
                        shutdowningThread.Start();
                    }
                    break;
                }

                case FLAG.SHUTDOWN_DONE:
                {
                    shutdowningDoneReceive = true;
                    break;
                }

                case FLAG.ERROR_MESSAGE:
                {
                    if (cloning)
                    {
                        Process[] procs = Process.GetProcessesByName("wdsmcast");
                        foreach (Process p in procs)
                        {
                            p.Kill();
                        }
                        Process p2 = Process.GetProcessById(CloneProcess.Id);
                        p2.Kill();
                        Process[] procs2 = Process.GetProcessesByName("diskpart");
                        foreach (Process p in procs2)
                        {
                            p.Kill();
                        }
                        File.WriteAllText(@"X:\CloneStatus.txt", "FALSE");
                    }
                    cloning = false;
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
コード例 #3
0
        public void SetComputerDetails()
        {
            try
            {
                Console.WriteLine("LOOP");
                computerDetails = new List <string>();
                computerDetailsData.RealPCName = System.Environment.MachineName;
                computerDetails.Add("Computer Name||" + computerDetailsData.RealPCName);

                var MacAddress = HardwareInfo.GetMacAddresses();
                if (MacAddress.Count == 0)
                {
                    var Macs = HardwareInfo.GetMacAddresses2();
                    if (Macs.Count == 0)
                    {
                        SetComputerDetails();
                        return;
                    }
                    MacAddress = Macs;
                }
                Console.WriteLine("LOOP 2");
                computerDetailsData._sourceIdentifier = NetworkComms.NetworkIdentifier;
                computerDetailsData.macAddresses      = MacAddress;
                computerDetailsData.MacAddress        = MacAddress[0];
                computerDetails.Add("MacAddress||" + MacAddress);
                computerDetailsData.OSInformations = HardwareInfo.GetOSInformation();
                computerDetails.Add("OS Informations||" + computerDetailsData.OSInformations);
                computerDetailsData.processorInfo = HardwareInfo.GetProcessorInformation();
                computerDetails.Add("Processor Informations||" + computerDetailsData.processorInfo);
                computerDetailsData.physicalMemoryInfo = HardwareInfo.GetPhysicalMemory();
                computerDetails.Add("Memory Size||" + computerDetailsData.physicalMemoryInfo);
                computerDetailsData.numberOfRamSLots = HardwareInfo.GetNoRamSlots();
                computerDetails.Add("Used Memory Slots||" + computerDetailsData.numberOfRamSLots);
                computerDetailsData.biosCaption = HardwareInfo.GetBIOScaption();
                computerDetails.Add("BIOS Caption||" + computerDetailsData.biosCaption);
                Console.WriteLine("LOOP 3");
                computerDetailsData.boardProductId = HardwareInfo.GetBoardProductId();
                computerDetails.Add("Board ID||" + computerDetailsData.boardProductId);
                computerDetailsData.accountName = HardwareInfo.GetAccountName();
                computerDetails.Add("User Account Name||" + computerDetailsData.accountName);
                computerDetailsData.baseImageName = GetBaseImageName();
                computerDetails.Add("BASE NAME||" + computerDetailsData.baseImageName);
                computerDetailsData.driveEImageName = GeDriveEImageName();
                computerDetails.Add("DRIVEE NAME||" + computerDetailsData.driveEImageName);
                computerDetailsData.dartInfo = GetDartViewerInfo(0);
                computerDetails.Add("Dart Viewer||" + computerDetailsData.dartInfo);
                computerDetailsData.CustomLog = "";
                if (!computerDetailsData.inWinpe)
                {
                    computerDetailsData.CustomLog = RunScript("$Templates = Get-SCVMTemplate\n"
                                                              + "foreach ($Template in $Templates){$Template.Name}");
                }
                computerDetails.Add("Custom Log||" + computerDetailsData.CustomLog);
                Console.WriteLine("LOOP 4");
            }
            catch (Exception ex)
            {
                WriteToLogs("SOMETHING WRONG WITH GET COMPUTER DETAILS: " + ex.ToString());
                Console.WriteLine("SOMETHING WRONG WITH GET COMPUTER DETAILS");
                Thread.Sleep(5000);
                SetComputerDetails();
            }
        }