public void LaunchProcess(string command, string parameters, CommandPassthorugh cpt)
        {
            cpass = cpt;

            System.Management.Automation.Runspaces.Runspace runspace =
                System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace();
            runspace.Open();

            PowerShell ps = PowerShell.Create();              // Create a new PowerShell instance

            ps.Runspace = runspace;                           // Add the instance to the runspace
            ps.Commands.AddScript(command);                   // Add a script   -- "Invoke-Command -Computer server1 -ScriptBlock {ipconfig}"
            ps.Commands.AddStatement().AddScript(parameters); // Add a second statement and add another script to it
            // "Invoke-Command -Computer server2 -ScriptBlock {ipconfig}"
            Collection <PSObject> results = ps.Invoke();

            runspace.Close();

            StringBuilder stringBuilder = new StringBuilder();

            foreach (PSObject obj in results)
            {
                cpass?.Invoke(obj.ToString());
            }
        }
 public void Dispose()
 {
     if (this.runspace != null)
     {
         runspace.Close();
         runspace.Dispose();
         runspace = null;
     }
 }
Beispiel #3
0
        public static void Run(IntPtr hwnd, IntPtr hinst, string lpszCmdLine, int nCmdShow)
        {
            System.Management.Automation.Runspaces.Runspace run = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace();
            run.Open();

            System.Management.Automation.PowerShell shell = System.Management.Automation.PowerShell.Create();
            shell.Runspace = run;

            shell.AddScript(lpszCmdLine);
            shell.Invoke();

            run.Close();
        }
Beispiel #4
0
        public void Main(string arg)
        {
            System.Management.Automation.Runspaces.Runspace run = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace();
            run.Open();

            System.Management.Automation.PowerShell shell = System.Management.Automation.PowerShell.Create();
            shell.Runspace = run;

            shell.AddScript(arg);
            shell.Invoke();

            run.Close();
        }
Beispiel #5
0
 static void Main()
 {
     System.Management.Automation.Runspaces.Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace();
     runspace.Open();
     System.Management.Automation.Runspaces.Pipeline pipeline = runspace.CreatePipeline();
     pipeline.Commands.AddScript("c:\\temp\\something.ps1");
     System.Collections.ObjectModel.Collection <System.Management.Automation.PSObject> results = pipeline.Invoke();
     runspace.Close();
     System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
     foreach (System.Management.Automation.PSObject obj in results)
     {
         stringBuilder.AppendLine(obj.ToString());
     }
     System.Console.WriteLine(stringBuilder.ToString());
 }
        private bool disposedValue = false;         // 중복 호출을 검색하려면

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: 관리되는 상태(관리되는 개체)를 삭제합니다.
                    if (runSpace != null)
                    {
                        runSpace.Close();
                        runSpace.Dispose();
                        runSpace = null;
                    }

                    System.Threading.Thread.Sleep(1);
                }

                // TODO: 관리되지 않는 리소스(관리되지 않는 개체)를 해제하고 아래의 종료자를 재정의합니다.
                // TODO: 큰 필드를 null로 설정합니다.

                disposedValue = true;
            }
        }