示例#1
0
        //start threads
        public string StartThreads()
        {
            //set parameters to remoting
            CreateWmiProcess process = new CreateWmiProcess();

            process.ComputerName = ComputerName;
            process.Username     = Username;
            process.Password     = Password;
            process.Domain       = Domain;
            process.WmiTimeout   = WmiTimeout;

            //create temp directory
            process.CreateDirectory(@"\\" + ComputerName + @"\c$\deploy_temp");

            //copy files to temp directory
            process.CopyDirectory(SourceDirectory, @"\\" + ComputerName + @"\c$\deploy_temp");

            //execute remote command
            process.InvokeCommand(@"C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe -ExecutionPolicy Bypass -File C:\deploy_temp\" + ScriptToRun);

            //grab json files
            string json = process.ImportJSON();

            //remove temp directory
            process.RemoveDirectory(@"\\" + ComputerName + @"\c$\deploy_temp");

            //null process object
            process = null;

            //return json data
            return(json);
        }
示例#2
0
        // on disconnect event handler
        private void RdpConnectionOnOnDisconnected(object sender, IMsTscAxEvents_OnDisconnectedEvent e)
        {
            CreateWmiProcess wmi = new CreateWmiProcess();

            wmi.Username     = UserName;
            wmi.Domain       = Domain;
            wmi.Password     = Password;
            wmi.WmiTimeout   = "60";
            wmi.ComputerName = Server;
            wmi.InvokeCommand("cmd /c gpupdate /force /wait:0");
            Environment.Exit(0);
        }
示例#3
0
        static void Main(string[] args)
        {
            // Read switches from command line
            CommandLineParser parser = new CommandLineParser(typeof(SwitchParameters));
            SwitchParameters  sp     = (SwitchParameters)parser.Parse(args);

            // Verify required fields are not left blank
            if (sp.Server == null || sp.UserName == null || sp.Domain == null || sp.Password == null)
            {
                Console.Write("CLI Usage -- HeadlessRDP.exe -Server xxxx -UserName xxxx -Domain xxxx -Password xxxx");
                Console.ReadLine();
            }
            else
            {
                // Before we can initiate remote connection we need to remove the legal notice
                CreateWmiProcess wmi = new CreateWmiProcess();
                wmi.Username     = sp.UserName;
                wmi.Domain       = sp.Domain;
                wmi.Password     = sp.Password;
                wmi.WmiTimeout   = "60";
                wmi.ComputerName = sp.Server;
                wmi.InvokeCommand("C:\\Windows\\System32\\WindowsPowershell\\v1.0\\Powershell.exe -ExecutionPolicy Bypass -NoProfile -Command \"& {Remove-ItemProperty -Path \"HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System -Name LegalNoticeCaption, LegalNoticeText -Force}\"");

                // Now that legal notice is remove we can create remote connection
                var rdp = new ConfigureRdp();
                rdp.UserName = sp.UserName;
                rdp.Password = sp.Password;
                rdp.Domain   = sp.Domain;
                rdp.Server   = sp.Server;
                rdp.CreateRdpConnection();

                // destroy object
                wmi = null;
                rdp = null;
            }
        }