Ejemplo n.º 1
0
        /// <summary>
        /// Close an existing desktop
        /// </summary>
        /// <param name="name">Desktop name</param>
        /// <returns>True if sucessful, otherwise false.</returns>
        public static bool DesktopClose(string name)
        {
            Console.WriteLine("DesktopClose call!");
            Process[] processes = Desktops.GetInputProcesses(name);
            Process   thisProc  = Process.GetCurrentProcess();

            foreach (Process p in processes)
            {
                if (p.ProcessName != thisProc.ProcessName)
                {
                    Console.WriteLine("process p:" + p + " kill!!");
                    p.Kill();
                }
            }

            IntPtr handle = DesktopOpen(name);

            Console.WriteLine("closeHandle:" + handle);

            if (handle == IntPtr.Zero)
            {
                return(false);
            }
            else
            {
                Console.WriteLine("call closeDesktop");
                return(CloseDesktop(handle));
            }
        }//
Ejemplo n.º 2
0
        void DeleteScreenshots()
        {
            for (int index = 2; index < 5; index++)
            {
                string desktopName = "Desktop" + index.ToString();
                string path        = ".\\" + desktopName;

                // If file exists and desktop do not exists, delete the file
                if (File.Exists(path) && !Desktops.DesktopExists(desktopName))
                {
                    File.Delete(path);
                }
            }// for
        }
Ejemplo n.º 3
0
        private void DesktopInitialize(string name)
        {
            DesktopSave();

            if (!Desktops.DesktopExists(name))
            {
                Console.WriteLine("create" + name);
                Desktops.DesktopCreate(name);
                Desktops.ProcessCreate(name, System.Reflection.Assembly.GetExecutingAssembly().Location, "start");     // Start VirtualDesktop application
                Console.WriteLine(System.Reflection.Assembly.GetExecutingAssembly().Location);
            }

            Console.WriteLine(name + " desktop Handle ID" + Desktops.get_DesktopHandle(name));
            Desktops.DesktopSwitch(name);
        }
Ejemplo n.º 4
0
 private void Window_Closed(object sender, EventArgs e)
 {
     Console.WriteLine("sdlfkjsdsdfsdfsdfsdflfkj");
     if (Desktops.DesktopExists("Desktop2"))
     {
         var res = Desktops.DesktopClose("Desktop2");
         Console.WriteLine("desktop closed vlaue is:" + res);
     }
     if (Desktops.DesktopExists("Desktop3"))
     {
         Desktops.DesktopClose("Desktop3");
     }
     if (Desktops.DesktopExists("Desktop4"))
     {
         Desktops.DesktopClose("Desktop4");
     }
     Thread.Sleep(1000);
     this.Close();
 }
Ejemplo n.º 5
0
        void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (Start == "start")
            {
                Thread.Sleep(500);
                //Console.WriteLine("call loaded");

                Process myProcess = new Process();

                myProcess.StartInfo.FileName         = "C:\\Windows\\explorer.exe";
                myProcess.StartInfo.UseShellExecute  = true;
                myProcess.StartInfo.WorkingDirectory = System.Windows.Forms.Application.StartupPath;
                myProcess.StartInfo.CreateNoWindow   = true;


                myProcess.Start();
                foreach (ProcessThread pt in myProcess.Threads)
                {
                    Console.WriteLine("WindowLoaded~DesktopName:" + Desktops.GetThreadDesktop(pt.Id));
                }

                //Process proc = Process.Start("explorer.exe");

                /*
                 * var myId = Process.Start("explorer.exe"); //Process.GetCurrentProcess().Id;
                 * var query = string.Format("SELECT ParentProcessId FROM Win32_Process WHERE ProcessId = {0}", myId);
                 * var search = new ManagementObjectSearcher("root\\CIMV2", query);
                 * //var results = search.Get().GetEnumerator();
                 * //var queryObj;
                 * foreach (ManagementObject results in search.Get())
                 * {
                 *  // show the service
                 *  //queryObj = service.Current;
                 *  var parentId = (uint)results["ParentProcessId"];
                 *  var parent = Process.GetProcessById((int)parentId);
                 *  Console.WriteLine("I was started by {0}", parent.ProcessName);
                 *
                 *  //Console.WriteLine(service.ToString());
                 *
                 * }
                 *
                 *
                 * //results.MoveNext();
                 * // var queryObj = results.Current;
                 * //var parentId = (uint)queryObj["ParentProcessId"];
                 * //var parent = Process.GetProcessById((int)parentId);
                 * //Console.WriteLine("I was started by {0}", parent.ProcessName);
                 * //Console.ReadLine();
                 *
                 *                                   // Start explorer
                 * //Process.GetProcessById(proc.Handle).pare
                 * // uint pr = GetCurrentProcessId();
                 * //Console.WriteLine("parentHandle???pr" + pr);
                 * //Console.WriteLine("parentHandle@@@GetParent((IntPtr)pr)" + GetParent((IntPtr)pr));
                 * //Console.WriteLine("parentHandle!!!GetParent(proc.Handle)" + GetParent(proc.Handle));
                 * //GetParent(proc.Handle);
                 * // proc.WaitForInputIdle();
                 * //--------
                 *
                 * //Console.WriteLine("proc:"+proc.Handle);
                 * //Console.WriteLine("proc"+ proc);
                 * //SetParent(proc.MainWindowHandle, Desktops.get_DesktopHandle(currentDesktop));
                 * //SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
                 * */
                Thread.Sleep(500);                                                         // Wait explorer to initialize

                // Reposition window on taskbar
                this.Opacity     = 0;
                this.WindowState = WindowState.Normal;
                this.WindowState = WindowState.Minimized;
                Thread.Sleep(300);
                this.Opacity = 100;
            }



            // Initialize
            currentDesktop = Desktops.DesktopName(Desktops.DesktopOpenInput());
            DeleteScreenshots();

            //Console.WriteLine(currentDesktop);
        }