Ejemplo n.º 1
0
 public void start(string[] args)
 {
     if (args[0] == "")
     {
         usage(); return;
     }
     else if (args[0] == "-h")
     {
         usage();
     }
     else if (args[0] == "-w")
     {
         PSConsole.getNewConsole();
         this.interact();
     }
     else if (args[0] == "-i")
     {
         pp = Process.GetCurrentProcess().Parent();
         pp.Suspend();
         PSConsole.stealConsole(pp);
         Console.Title           = "PowerShdll";
         Console.CancelKeyPress += delegate {
             this.cleanup();
         };
         Console.SetCursorPosition(0, Console.CursorTop + 1);
         Console.WriteLine("Press Enter to get started:");
         Console.Write("\n");
         this.interact();
         ps.close();
         pp.Resume();
     }
     else if (args[0] == "-f")
     {
         if (args.Length < 2)
         {
             usage(); return;
         }
         pp = Process.GetCurrentProcess().Parent();
         PSConsole.stealConsole(pp);
         Console.CancelKeyPress += delegate {
             this.cleanup();
         };
         Console.SetCursorPosition(0, Console.CursorTop + 1);
         string script = PowerShdll.LoadScript(args[1]);
         if (script != "error")
         {
             Console.Write(ps.exe(script));
         }
     }
     else
     {
         pp = Process.GetCurrentProcess().Parent();
         PSConsole.stealConsole(pp);
         Console.CancelKeyPress += delegate {
             this.cleanup();
         };
         Console.SetCursorPosition(0, Console.CursorTop + 1);
         string script = string.Join(" ", args);
         Console.Write(ps.exe(script));
         ps.close();
     }
     return;
 }
Ejemplo n.º 2
0
        public void start(string[] args)
        {
            int    i          = 0;
            bool   useConsole = true;
            string ret;

            if (args.Length == 0)
            {
                PSConsole.getNewConsole();
                this.interact();
            }
            if (args[i] == "-n")
            {
                i++;
                useConsole = false;
            }
            if (args[i] == "-h")
            {
                usage(); return;
            }
            else if (args[i] == "-w" || args[i] == "")
            {
                PSConsole.getNewConsole();
                this.interact();
            }
            else if (args[i] == "-i")
            {
                pp = Process.GetCurrentProcess().Parent();
                pp.Suspend();
                PSConsole.stealConsole(pp);
                Console.Title           = "PowerShdll";
                Console.CancelKeyPress += delegate
                {
                    this.cleanup();
                };
                Console.SetCursorPosition(0, Console.CursorTop + 1);
                Console.WriteLine("Press Enter to get started:");
                Console.Write("\n");
                this.interact();
                ps.close();
                pp.Resume();
            }
            else if (args[i] == "-f")
            {
                i++;
                if (args.Length < 2)
                {
                    usage(); return;
                }
                if (args[i] == "-n")
                {
                    if (args.Length < 3)
                    {
                        usage(); return;
                    }
                    i++;
                    useConsole = false;
                }
                string script = LoadScript(args[i]);
                if (script != "error")
                {
                    ret = ps.exe(script);
                    if (useConsole)
                    {
                        pp = Process.GetCurrentProcess().Parent();
                        PSConsole.stealConsole(pp);
                        Console.CancelKeyPress += delegate
                        {
                            this.cleanup();
                        };
                        Console.SetCursorPosition(0, Console.CursorTop + 1);
                        Console.WriteLine(ret);
                    }
                }
            }
            else
            {
                string script = string.Join(" ", args, i, args.Length - i);
                if (script[0] == '"' && script[script.Length - 1] == '"')
                {
                    script = script.Substring(1, script.Length - 2);
                }
                ret = ps.exe(script);
                if (useConsole)
                {
                    pp = Process.GetCurrentProcess().Parent();
                    PSConsole.stealConsole(pp);
                    Console.CancelKeyPress += delegate
                    {
                        this.cleanup();
                    };
                    Console.SetCursorPosition(0, Console.CursorTop + 1);
                    Console.WriteLine(ret);
                }
                ps.close();
            }
            return;
        }