Esempio n. 1
0
        //Restart the process
        async Task RestartProcessAuto(ProcessMulti processMulti, DataBindApp dataBindApp, bool useLaunchArgument)
        {
            try
            {
                //Check the application category
                if (!useLaunchArgument && dataBindApp.Category != AppCategory.Process)
                {
                    await CloseSingleProcessAuto(processMulti, dataBindApp, true, false);
                    await LaunchProcessDatabindAuto(dataBindApp);

                    return;
                }

                //Check keyboard controller launch
                string fileNameNoExtension = Path.GetFileNameWithoutExtension(dataBindApp.NameExe);
                bool   keyboardProcess     = vCtrlKeyboardProcessName.Any(x => x.String1.ToLower() == fileNameNoExtension.ToLower() || x.String1.ToLower() == dataBindApp.PathExe.ToLower());
                bool   keyboardLaunch      = (keyboardProcess || dataBindApp.LaunchKeyboard) && vControllerAnyConnected();

                //Restart the process
                if (processMulti.Type == ProcessType.UWP)
                {
                    await PrepareRestartProcessUwp(dataBindApp, processMulti, useLaunchArgument, keyboardLaunch);
                }
                else if (processMulti.Type == ProcessType.Win32Store)
                {
                    await PrepareRestartProcessWin32Store(dataBindApp, processMulti, useLaunchArgument, keyboardLaunch);
                }
                else
                {
                    await PrepareRestartProcessWin32(dataBindApp, processMulti, useLaunchArgument, keyboardLaunch);
                }
            }
            catch { }
        }
Esempio n. 2
0
 //Get threads from ProcessMulti
 public static ProcessThreadCollection GetProcessThreads(ProcessMulti processMulti)
 {
     try
     {
         return(GetProcessById(processMulti.Identifier).Threads);
     }
     catch { }
     return(null);
 }
Esempio n. 3
0
 //Close open Windows system menu
 public static async Task CloseOpenWindowsSystemMenu(ProcessMulti foregroundProcess)
 {
     try
     {
         Debug.WriteLine("Closing system menu for window: " + foregroundProcess.WindowHandle);
         SendMessage(foregroundProcess.WindowHandle, (int)WindowMessages.WM_CANCELMODE, 0, 0);
         await Task.Delay(10);
     }
     catch { }
 }
Esempio n. 4
0
        //Get multi process from window handle
        public static ProcessMulti GetProcessMultiFromWindowHandle(IntPtr targetWindowHandle)
        {
            try
            {
                ProcessMulti processMulti = new ProcessMulti();

                //Set window handle
                processMulti.WindowHandle = targetWindowHandle;

                //Get window classname
                processMulti.ClassName = GetClassNameFromWindowHandle(processMulti.WindowHandle);

                //Get window process
                Process focusedProcess = null;
                if (processMulti.ClassName == "ApplicationFrameWindow")
                {
                    focusedProcess = GetUwpProcessByWindowHandle(processMulti.WindowHandle);
                }
                else
                {
                    focusedProcess = GetProcessById(GetProcessIdFromWindowHandle(processMulti.WindowHandle));
                }

                //Set the identifier
                processMulti.Identifier = focusedProcess.Id;

                //Set the process name
                processMulti.Name = focusedProcess.ProcessName;

                //Get and set the process path
                string processAppUserModelId = GetAppUserModelIdFromProcess(focusedProcess);
                if (!string.IsNullOrWhiteSpace(processAppUserModelId))
                {
                    processMulti.Path = processAppUserModelId;
                }
                else
                {
                    processMulti.Path = GetExecutablePathFromProcess(focusedProcess);
                }

                //Get the window title
                processMulti.Title = GetWindowTitleFromWindowHandle(processMulti.WindowHandle);
                if (processMulti.Title == "Unknown")
                {
                    processMulti.Title = GetWindowTitleFromProcess(focusedProcess);
                }

                return(processMulti);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to get multi process: " + ex.Message);
                return(null);
            }
        }
Esempio n. 5
0
        //Close open start menu, cortana or search
        public static async Task CloseOpenWindowsStartMenu(ProcessMulti foregroundProcess)
        {
            try
            {
                if (foregroundProcess.Name == "SearchUI")
                {
                    Debug.WriteLine("Start menu is currently open, pressing escape to close it.");
                    await KeyPressSingleAuto(KeysVirtual.Escape);

                    await Task.Delay(10);
                }
            }
            catch { }
        }
Esempio n. 6
0
 //Close single process
 async Task CloseSingleProcessAuto(ProcessMulti processMulti, DataBindApp dataBindApp, bool resetProcess, bool removeProcess)
 {
     try
     {
         if (processMulti.Type == ProcessType.UWP)
         {
             await CloseSingleProcessUwp(dataBindApp, processMulti, resetProcess, removeProcess);
         }
         else if (processMulti.Type == ProcessType.Win32 || processMulti.Type == ProcessType.Win32Store)
         {
             await CloseSingleProcessWin32AndWin32Store(dataBindApp, processMulti, resetProcess, removeProcess);
         }
     }
     catch { }
 }
Esempio n. 7
0
 //Close all processes
 async Task CloseAllProcessesAuto(ProcessMulti processMulti, DataBindApp dataBindApp, bool resetProcess, bool removeProcess)
 {
     try
     {
         if (processMulti.Type == ProcessType.UWP)
         {
             await CloseAllProcessesUwp(dataBindApp, resetProcess, removeProcess);
         }
         else
         {
             await CloseAllProcessesWin32AndWin32Store(dataBindApp, resetProcess, removeProcess);
         }
     }
     catch { }
 }
Esempio n. 8
0
        void ResetFpsCounter()
        {
            try
            {
                //Debug.WriteLine("Resetting the frames per second counter.");

                //Reset the target process
                vTargetProcess = new ProcessMulti();

                //Reset the frames variables
                vLastFrameTimeStamp = 0;
                vListFrameTime.Clear();
            }
            catch { }
        }
Esempio n. 9
0
        //Close all processes UWP
        async Task <bool> CloseAllProcessesUwp(DataBindApp dataBindApp, bool resetProcess, bool removeProcess)
        {
            try
            {
                //Get the multi process
                ProcessMulti processMulti = dataBindApp.ProcessMulti.FirstOrDefault();

                await Notification_Send_Status("AppClose", "Closing " + dataBindApp.Name);

                Debug.WriteLine("Closing all UWP processes: " + dataBindApp.Name + " / " + processMulti.Identifier);

                //Close the process
                bool closedProcess = CloseProcessById(processMulti.Identifier);
                if (closedProcess)
                {
                    await Notification_Send_Status("AppClose", "Closed " + dataBindApp.Name);

                    Debug.WriteLine("Closed all UWP processes: " + dataBindApp.Name);

                    //Reset the process running status
                    if (resetProcess)
                    {
                        dataBindApp.StatusRunning         = Visibility.Collapsed;
                        dataBindApp.StatusSuspended       = Visibility.Collapsed;
                        dataBindApp.RunningProcessCount   = string.Empty;
                        dataBindApp.RunningTimeLastUpdate = 0;
                        dataBindApp.ProcessMulti.Clear();
                    }

                    //Remove the process from the list
                    if (removeProcess)
                    {
                        await RemoveAppFromList(dataBindApp, false, false, true);
                    }

                    return(true);
                }
                else
                {
                    await Notification_Send_Status("AppClose", "Failed to close the app");

                    Debug.WriteLine("Failed to close the application.");
                    return(false);
                }
            }
            catch { }
            return(false);
        }
Esempio n. 10
0
 //Check process windows
 async Task <IntPtr> CheckProcessWindowsAuto(DataBindApp dataBindApp, ProcessMulti processMulti)
 {
     try
     {
         if (processMulti.Type == ProcessType.UWP)
         {
             return(processMulti.WindowHandle);
         }
         else if (processMulti.Type == ProcessType.Win32 || processMulti.Type == ProcessType.Win32Store)
         {
             return(await CheckProcessWindowsWin32AndWin32Store(dataBindApp, processMulti));
         }
     }
     catch { }
     return(IntPtr.Zero);
 }
Esempio n. 11
0
        //Convert Process to a ProcessMulti
        public static ProcessMulti ConvertProcessToProcessMulti(ProcessType processType, Process convertProcess)
        {
            ProcessMulti convertedProcess = new ProcessMulti();

            try
            {
                convertedProcess.Type         = processType;
                convertedProcess.Identifier   = convertProcess.Id;
                convertedProcess.WindowHandle = convertProcess.MainWindowHandle;

                //Get the process launch argument
                string processExecutablePath = GetExecutablePathFromProcess(convertProcess);
                convertedProcess.Argument = GetLaunchArgumentsFromProcess(convertProcess, processExecutablePath);
            }
            catch { }
            return(convertedProcess);
        }
Esempio n. 12
0
        //Close single UWP process
        async Task <bool> CloseSingleProcessUwp(DataBindApp dataBindApp, ProcessMulti processMulti, bool resetProcess, bool removeProcess)
        {
            try
            {
                await Notification_Send_Status("AppClose", "Closing " + dataBindApp.Name);

                Debug.WriteLine("Closing UWP process: " + dataBindApp.Name);

                //Close the process
                bool closedProcess = await CloseProcessUwpByWindowHandleOrProcessId(dataBindApp.Name, processMulti.Identifier, processMulti.WindowHandle);

                if (closedProcess)
                {
                    await Notification_Send_Status("AppClose", "Closed " + dataBindApp.Name);

                    Debug.WriteLine("Closed UWP process: " + dataBindApp.Name);

                    //Reset the process running status
                    if (resetProcess)
                    {
                        dataBindApp.StatusRunning         = Visibility.Collapsed;
                        dataBindApp.StatusSuspended       = Visibility.Collapsed;
                        dataBindApp.RunningProcessCount   = string.Empty;
                        dataBindApp.RunningTimeLastUpdate = 0;
                        dataBindApp.ProcessMulti.Clear();
                    }

                    //Remove the process from the list
                    if (removeProcess)
                    {
                        await RemoveAppFromList(dataBindApp, false, false, true);
                    }

                    return(true);
                }
                else
                {
                    await Notification_Send_Status("AppClose", "Failed to close the app");

                    Debug.WriteLine("Failed to close the application.");
                    return(false);
                }
            }
            catch { }
            return(false);
        }
Esempio n. 13
0
        async Task <bool> PrepareRestartProcessUwp(DataBindApp dataBindApp, ProcessMulti processMulti, bool useLaunchArgument, bool launchKeyboard)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(dataBindApp.PathExe))
                {
                    await Notification_Send_Status("Close", "Failed restarting " + dataBindApp.Name);

                    Debug.WriteLine("Failed to restart process: " + dataBindApp.Name);
                    return(false);
                }

                await Notification_Send_Status("AppRestart", "Restarting " + dataBindApp.Name);

                Debug.WriteLine("Restarting UWP application: " + dataBindApp.Name + " / " + processMulti.Identifier + " / " + processMulti.WindowHandle);

                //Set the launch argument
                string launchArgument = string.Empty;
                if (useLaunchArgument)
                {
                    Debug.WriteLine("Setting restart argument: " + processMulti.Argument);
                    launchArgument = processMulti.Argument;
                }

                //Restart the process
                Process restartProcess = await RestartProcessUwp(dataBindApp.Name, dataBindApp.PathExe, processMulti.Identifier, processMulti.WindowHandle, launchArgument);

                if (restartProcess == null)
                {
                    await Notification_Send_Status("Close", "Failed restarting " + dataBindApp.Name);

                    Debug.WriteLine("Failed to restart process: " + dataBindApp.Name);
                    return(false);
                }

                //Launch the keyboard controller
                if (launchKeyboard)
                {
                    await KeyboardControllerHideShow(true);
                }
            }
            catch { }
            return(false);
        }
Esempio n. 14
0
        //Check which launch method needs to be used
        async Task LaunchProcessSelector(DataBindApp dataBindApp)
        {
            try
            {
                //Check if the shortcut is available
                if (dataBindApp.Category == AppCategory.Shortcut && dataBindApp.StatusAvailable == Visibility.Visible)
                {
                    Debug.WriteLine("Remove shortcut prompt: " + dataBindApp.ShortcutPath);
                    await RemoveShortcutFilePrompt(dataBindApp);

                    return;
                }

                //Check the application category
                if (dataBindApp.Category == AppCategory.Process)
                {
                    //Get the process multi
                    ProcessMulti processMulti = null;
                    foreach (ProcessMulti processMultiFor in dataBindApp.ProcessMulti)
                    {
                        if (processMultiFor.WindowHandle != IntPtr.Zero)
                        {
                            processMulti = processMultiFor;
                        }
                    }

                    //Show the process window
                    await ShowProcessWindow(dataBindApp, processMulti);
                }
                else
                {
                    //Run process url protocol
                    if (dataBindApp.PathExe.Contains(":\\\\") || dataBindApp.PathExe.Contains("://"))
                    {
                        await LaunchProcessUrlProtocol(dataBindApp);

                        return;
                    }

                    //Refresh the processes list
                    await Notification_Send_Status("AppLaunch", "Preparing launch");
                    await RefreshListProcessesWithWait(true);

                    //Check if process is running
                    ProcessMulti processMulti = await SelectProcessMulti(dataBindApp, true);

                    if (processMulti == null)
                    {
                        Debug.WriteLine("Process is not running, launching the application.");
                        await LaunchProcessDatabindAuto(dataBindApp);
                    }
                    else if (processMulti.Action == "Cancel")
                    {
                        Debug.WriteLine("Process is already running, skipping the launch.");
                    }
                    else if (processMulti.Action == "CloseAll")
                    {
                        Debug.WriteLine("Closing all processes, skipping the launch.");
                        await CloseAllProcessesAuto(processMulti, dataBindApp, true, false);
                    }
                    else
                    {
                        Debug.WriteLine("Process is already running, checking the app.");
                        await CheckLaunchProcessStatus(dataBindApp, processMulti);
                    }
                }
            }
            catch
            {
                Debug.WriteLine("Failed launch process selector.");
            }
        }
Esempio n. 15
0
        async Task ShowProcessWindow(DataBindApp dataBindApp, ProcessMulti processMulti)
        {
            try
            {
                Debug.WriteLine("Showing the application: " + dataBindApp.Name);

                //Check if application has multiple windows
                IntPtr processWindowHandle = await CheckProcessWindowsAuto(dataBindApp, processMulti);

                //Check if application window has been found
                if (processWindowHandle == new IntPtr(-50))
                {
                    await LaunchProcessDatabindAuto(dataBindApp);
                }
                else if (processWindowHandle == new IntPtr(-75))
                {
                    await RestartProcessAuto(processMulti, dataBindApp, true);
                }
                else if (processWindowHandle == new IntPtr(-80))
                {
                    await RestartProcessAuto(processMulti, dataBindApp, false);
                }
                else if (processWindowHandle == new IntPtr(-100))
                {
                    await CloseSingleProcessAuto(processMulti, dataBindApp, true, false);
                }
                else if (processWindowHandle == new IntPtr(-200))
                {
                    Debug.WriteLine("Cancelled window selection.");
                }
                else if (processWindowHandle != IntPtr.Zero)
                {
                    //Minimize the CtrlUI window
                    if (Convert.ToBoolean(Setting_Load(vConfigurationCtrlUI, "MinimizeAppOnShow")))
                    {
                        await AppMinimize(true);
                    }

                    //Check keyboard controller launch
                    string fileNameNoExtension = Path.GetFileNameWithoutExtension(dataBindApp.NameExe);
                    bool   keyboardProcess     = vCtrlKeyboardProcessName.Any(x => x.String1.ToLower() == fileNameNoExtension.ToLower() || x.String1.ToLower() == dataBindApp.PathExe.ToLower());
                    bool   keyboardLaunch      = (keyboardProcess || dataBindApp.LaunchKeyboard) && vControllerAnyConnected();

                    //Force focus on the app
                    await PrepareFocusProcessWindow(dataBindApp.Name, processMulti.Identifier, processWindowHandle, 0, false, false, false, keyboardLaunch);
                }
                else
                {
                    Debug.WriteLine("Show application has no window.");

                    //Focus or Close when process is already running
                    List <DataBindString> Answers      = new List <DataBindString>();
                    DataBindString        AnswerLaunch = new DataBindString();
                    AnswerLaunch.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppLaunch.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                    AnswerLaunch.Name        = "Launch new instance";
                    Answers.Add(AnswerLaunch);

                    DataBindString AnswerRestartCurrent = new DataBindString();
                    if (!string.IsNullOrWhiteSpace(processMulti.Argument))
                    {
                        AnswerRestartCurrent.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppRestart.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                        AnswerRestartCurrent.Name        = "Restart application";
                        AnswerRestartCurrent.NameSub     = "(Current argument)";
                        Answers.Add(AnswerRestartCurrent);
                    }

                    DataBindString AnswerRestartWithout = new DataBindString();
                    AnswerRestartWithout.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppRestart.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                    AnswerRestartWithout.Name        = "Restart application";
                    if (!string.IsNullOrWhiteSpace(dataBindApp.Argument) || dataBindApp.Category == AppCategory.Shortcut || dataBindApp.Category == AppCategory.Emulator || dataBindApp.LaunchFilePicker)
                    {
                        AnswerRestartWithout.NameSub = "(Default argument)";
                    }
                    else
                    {
                        AnswerRestartWithout.NameSub = "(Without argument)";
                    }
                    Answers.Add(AnswerRestartWithout);

                    DataBindString AnswerClose = new DataBindString();
                    AnswerClose.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppClose.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                    AnswerClose.Name        = "Close application";
                    Answers.Add(AnswerClose);

                    //Show the messagebox
                    DataBindString messageResult = await Popup_Show_MessageBox("Application has no window", "", "", Answers);

                    if (messageResult != null)
                    {
                        if (messageResult == AnswerClose)
                        {
                            await CloseSingleProcessAuto(processMulti, dataBindApp, true, false);
                        }
                        else if (messageResult == AnswerRestartCurrent)
                        {
                            await RestartProcessAuto(processMulti, dataBindApp, true);
                        }
                        else if (messageResult == AnswerRestartWithout)
                        {
                            await RestartProcessAuto(processMulti, dataBindApp, false);
                        }
                        else if (messageResult == AnswerLaunch)
                        {
                            await LaunchProcessDatabindAuto(dataBindApp);
                        }
                    }
                }
            }
            catch { }
        }
Esempio n. 16
0
        async Task RightClickProcess(ListBox listboxSender, int listboxSelectedIndex, DataBindApp dataBindApp)
        {
            try
            {
                //Get the process multi
                ProcessMulti processMulti = dataBindApp.ProcessMulti.FirstOrDefault();

                //Get process details
                string processDetails = dataBindApp.PathExe;
                if (!string.IsNullOrWhiteSpace(dataBindApp.NameExe))
                {
                    processDetails += " (" + dataBindApp.NameExe + ")";
                }

                //Get process running time
                string processRunningTimeString = ApplicationRunningTimeString(dataBindApp.RunningTime, "process");
                if (string.IsNullOrWhiteSpace(processRunningTimeString))
                {
                    processRunningTimeString = processDetails;
                }
                else
                {
                    processRunningTimeString += "\n" + processDetails;
                }

                List <DataBindString> Answers    = new List <DataBindString>();
                DataBindString        AnswerShow = new DataBindString();
                AnswerShow.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppMiniMaxi.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                AnswerShow.Name        = "Show application";
                Answers.Add(AnswerShow);

                DataBindString AnswerClose = new DataBindString();
                AnswerClose.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppClose.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                AnswerClose.Name        = "Close application";
                Answers.Add(AnswerClose);

                DataBindString AnswerLaunch = new DataBindString();
                AnswerLaunch.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppLaunch.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                AnswerLaunch.Name        = "Launch new instance";
                Answers.Add(AnswerLaunch);

                DataBindString AnswerRestartCurrent = new DataBindString();
                if (!string.IsNullOrWhiteSpace(processMulti.Argument))
                {
                    AnswerRestartCurrent.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppRestart.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                    AnswerRestartCurrent.Name        = "Restart application";
                    AnswerRestartCurrent.NameSub     = "(Current argument)";
                    Answers.Add(AnswerRestartCurrent);
                }

                DataBindString AnswerRestartWithout = new DataBindString();
                AnswerRestartWithout.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppRestart.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                AnswerRestartWithout.Name        = "Restart application";
                if (!string.IsNullOrWhiteSpace(dataBindApp.Argument) || dataBindApp.Category == AppCategory.Shortcut || dataBindApp.Category == AppCategory.Emulator || dataBindApp.LaunchFilePicker)
                {
                    AnswerRestartWithout.NameSub = "(Default argument)";
                }
                else
                {
                    AnswerRestartWithout.NameSub = "(Without argument)";
                }
                Answers.Add(AnswerRestartWithout);

                DataBindString messageResult = await Popup_Show_MessageBox("What would you like to do with " + dataBindApp.Name + "?", processRunningTimeString, "", Answers);

                if (messageResult != null)
                {
                    if (messageResult == AnswerShow)
                    {
                        await ShowProcessWindow(dataBindApp, processMulti);
                    }
                    else if (messageResult == AnswerClose)
                    {
                        await CloseSingleProcessAuto(processMulti, dataBindApp, false, true);
                    }
                    else if (messageResult == AnswerRestartCurrent)
                    {
                        await RestartProcessAuto(processMulti, dataBindApp, true);
                    }
                    else if (messageResult == AnswerRestartWithout)
                    {
                        await RestartProcessAuto(processMulti, dataBindApp, false);
                    }
                    else if (messageResult == AnswerLaunch)
                    {
                        await LaunchProcessDatabindAuto(dataBindApp);
                    }
                }
            }
            catch { }
        }
Esempio n. 17
0
        //Check process status before launching (True = Continue)
        async Task CheckLaunchProcessStatus(DataBindApp dataBindApp, ProcessMulti processMulti)
        {
            try
            {
                Debug.WriteLine("Checking launch process: " + dataBindApp.Name);

                //Focus or Close when process is already running
                List <DataBindString> Answers    = new List <DataBindString>();
                DataBindString        AnswerShow = new DataBindString();
                AnswerShow.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppMiniMaxi.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                AnswerShow.Name        = "Show application";
                Answers.Add(AnswerShow);

                DataBindString AnswerClose = new DataBindString();
                AnswerClose.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppClose.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                AnswerClose.Name        = "Close application";
                Answers.Add(AnswerClose);

                DataBindString AnswerLaunch = new DataBindString();
                AnswerLaunch.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppLaunch.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                AnswerLaunch.Name        = "Launch new instance";
                Answers.Add(AnswerLaunch);

                DataBindString AnswerRestartCurrent = new DataBindString();
                if (!string.IsNullOrWhiteSpace(processMulti.Argument))
                {
                    AnswerRestartCurrent.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppRestart.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                    AnswerRestartCurrent.Name        = "Restart application";
                    AnswerRestartCurrent.NameSub     = "(Current argument)";
                    Answers.Add(AnswerRestartCurrent);
                }

                DataBindString AnswerRestartWithout = new DataBindString();
                AnswerRestartWithout.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppRestart.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                AnswerRestartWithout.Name        = "Restart application";
                if (!string.IsNullOrWhiteSpace(dataBindApp.Argument) || dataBindApp.Category == AppCategory.Shortcut || dataBindApp.Category == AppCategory.Emulator || dataBindApp.LaunchFilePicker)
                {
                    AnswerRestartWithout.NameSub = "(Default argument)";
                }
                else
                {
                    AnswerRestartWithout.NameSub = "(Without argument)";
                }
                Answers.Add(AnswerRestartWithout);

                //Get process details
                string processDetails = dataBindApp.PathExe;
                if (!string.IsNullOrWhiteSpace(dataBindApp.NameExe))
                {
                    processDetails += " (" + dataBindApp.NameExe + ")";
                }

                //Get process running time and last launch time
                string processRunningTimeString = string.Empty;
                string lastLaunchTimeString     = string.Empty;
                if (dataBindApp.Category == AppCategory.Shortcut)
                {
                    processRunningTimeString = ApplicationRunningTimeString(dataBindApp.RunningTime, "shortcut process");
                }
                else
                {
                    processRunningTimeString = ApplicationRunningTimeString(dataBindApp.RunningTime, "application");
                    lastLaunchTimeString     = ApplicationLastLaunchTimeString(dataBindApp.LastLaunch, "Application");
                }

                //Set the running time string
                bool runningTimeEmpty = string.IsNullOrWhiteSpace(processRunningTimeString);
                bool launchTimeEmpty  = string.IsNullOrWhiteSpace(lastLaunchTimeString);
                if (runningTimeEmpty && launchTimeEmpty)
                {
                    processRunningTimeString = processDetails;
                }
                else
                {
                    if (!launchTimeEmpty)
                    {
                        processRunningTimeString += "\n" + lastLaunchTimeString;
                    }
                    processRunningTimeString += "\n" + processDetails;
                }

                //Show the messagebox
                DataBindString messageResult = await Popup_Show_MessageBox("What would you like to do with " + dataBindApp.Name + "?", processRunningTimeString, "", Answers);

                if (messageResult != null)
                {
                    if (messageResult == AnswerShow)
                    {
                        await ShowProcessWindow(dataBindApp, processMulti);
                    }
                    else if (messageResult == AnswerClose)
                    {
                        await CloseSingleProcessAuto(processMulti, dataBindApp, true, false);
                    }
                    else if (messageResult == AnswerRestartCurrent)
                    {
                        await RestartProcessAuto(processMulti, dataBindApp, true);
                    }
                    else if (messageResult == AnswerRestartWithout)
                    {
                        await RestartProcessAuto(processMulti, dataBindApp, false);
                    }
                    else if (messageResult == AnswerLaunch)
                    {
                        await LaunchProcessDatabindAuto(dataBindApp);
                    }
                }
                else
                {
                    Debug.WriteLine("Cancelling the process action.");
                }
            }
            catch (Exception ex)
            {
                await Notification_Send_Status("Close", "Failed showing or closing application");

                Debug.WriteLine("Failed closing or showing the application: " + ex.Message);
            }
        }
Esempio n. 18
0
        //Hide or recover the CtrlUI application
        async Task AppWindow_HideShow()
        {
            try
            {
                Debug.WriteLine("Show or hide the CtrlUI window.");

                //Get the current focused application
                ProcessMulti foregroundProcess = GetProcessMultiFromWindowHandle(GetForegroundWindow());

                if (vAppMinimized || !vAppActivated)
                {
                    PlayInterfaceSound(vConfigurationCtrlUI, "PopupOpen", false);

                    //Check previous focused application
                    try
                    {
                        //Check if application title or process is blacklisted
                        bool titleBlacklisted   = vCtrlIgnoreProcessName.Any(x => x.String1.ToLower() == foregroundProcess.Title.ToLower());
                        bool processBlacklisted = vCtrlIgnoreProcessName.Any(x => x.String1.ToLower() == foregroundProcess.Name.ToLower());
                        if (!titleBlacklisted && !processBlacklisted)
                        {
                            //Save the previous focused application
                            vPrevFocusedProcess = foregroundProcess;
                        }
                    }
                    catch { }

                    //Disable top most window from foreground process
                    try
                    {
                        Debug.WriteLine("Disabling top most from process: " + foregroundProcess.Name);
                        SetWindowPos(foregroundProcess.WindowHandle, (IntPtr)WindowPosition.NoTopMost, 0, 0, 0, 0, (int)WindowSWP.NOMOVE | (int)WindowSWP.NOSIZE);
                    }
                    catch { }

                    //Force focus on CtrlUI
                    await PrepareFocusProcessWindow("CtrlUI", vProcessCurrent.Id, vProcessCurrent.MainWindowHandle, 0, false, true, false, false);
                }
                else
                {
                    //Disable top most window from foreground process
                    try
                    {
                        Debug.WriteLine("Disabling top most from process: " + foregroundProcess.Name);
                        SetWindowPos(foregroundProcess.WindowHandle, (IntPtr)WindowPosition.NoTopMost, 0, 0, 0, 0, (int)WindowSWP.NOMOVE | (int)WindowSWP.NOSIZE);
                    }
                    catch { }

                    //Force focus on CtrlUI
                    await PrepareFocusProcessWindow("CtrlUI", vProcessCurrent.Id, vProcessCurrent.MainWindowHandle, 0, false, true, false, false);

                    //Check if a previous process is available
                    if (vPrevFocusedProcess == null)
                    {
                        Debug.WriteLine("Previous application process not found.");
                        await ApplicationPopupMinimize("No application to show found");

                        return;
                    }

                    //Check if application name is blacklisted
                    if (vCtrlIgnoreProcessName.Any(x => x.String1.ToLower() == vPrevFocusedProcess.Name.ToLower()))
                    {
                        Debug.WriteLine("Previous process name is blacklisted: " + vPrevFocusedProcess.Name);
                        await ApplicationPopupMinimize("Previous app name is blacklisted");

                        return;
                    }

                    //Check if application title is blacklisted
                    if (vCtrlIgnoreProcessName.Any(x => x.String1.ToLower() == vPrevFocusedProcess.Title.ToLower()))
                    {
                        Debug.WriteLine("Previous process title is blacklisted: " + vPrevFocusedProcess.Title);
                        await ApplicationPopupMinimize("Previous app title is blacklisted");

                        return;
                    }

                    //Check if application process is still running
                    if (!CheckRunningProcessByNameOrTitle(vPrevFocusedProcess.Name, false))
                    {
                        Debug.WriteLine("Previous process is no longer running.");
                        await ApplicationPopupMinimize("Previous app is no longer running");

                        return;
                    }

                    //Show application switch popup
                    await ApplicationPopupSwitch();
                }
            }
            catch
            {
                await Notification_Send_Status("Close", "Failed to minimize or show app");

                Debug.WriteLine("Failed to minimize or show application.");
            }
        }
Esempio n. 19
0
        //Select a process multi from the list
        async Task <ProcessMulti> SelectProcessMulti(DataBindApp dataBindApp, bool selectProcess)
        {
            try
            {
                List <DataBindString> multiAnswers = new List <DataBindString>();
                if (dataBindApp.ProcessMulti.Any())
                {
                    if (selectProcess && dataBindApp.ProcessMulti.Count > 1)
                    {
                        foreach (ProcessMulti multiProcess in dataBindApp.ProcessMulti)
                        {
                            try
                            {
                                //Get the process title
                                string ProcessTitle = GetWindowTitleFromWindowHandle(multiProcess.WindowHandle);
                                if (ProcessTitle == "Unknown")
                                {
                                    ProcessTitle += " (Hidden)";
                                }

                                DataBindString AnswerApp = new DataBindString();
                                AnswerApp.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppLaunch.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                                AnswerApp.Name        = ProcessTitle;
                                AnswerApp.NameSub     = multiProcess.Identifier.ToString();
                                multiAnswers.Add(AnswerApp);
                            }
                            catch { }
                        }

                        DataBindString Answer1 = new DataBindString();
                        Answer1.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppLaunch.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                        Answer1.Name        = "Launch new instance";
                        multiAnswers.Add(Answer1);

                        DataBindString Answer2 = new DataBindString();
                        Answer2.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppClose.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                        Answer2.Name        = "Close all the instances";
                        multiAnswers.Add(Answer2);

                        DataBindString messageResult = await Popup_Show_MessageBox(dataBindApp.Name + " has multiple running instances", "", "Please select the instance that you wish to interact with:", multiAnswers);

                        if (messageResult != null)
                        {
                            if (messageResult == Answer2)
                            {
                                //Get the first multi process type
                                ProcessType processType = dataBindApp.ProcessMulti.FirstOrDefault().Type;

                                //Return close all with process type
                                ProcessMulti processMultiNew = new ProcessMulti();
                                processMultiNew.Action = "CloseAll";
                                processMultiNew.Type   = processType;
                                return(processMultiNew);
                            }
                            else
                            {
                                return(dataBindApp.ProcessMulti[multiAnswers.IndexOf(messageResult)]);
                            }
                        }
                        else
                        {
                            ProcessMulti processMultiNew = new ProcessMulti();
                            processMultiNew.Action = "Cancel";
                            return(processMultiNew);
                        }
                    }
                    else
                    {
                        return(dataBindApp.ProcessMulti.FirstOrDefault());
                    }
                }
            }
            catch { }
            return(null);
        }
Esempio n. 20
0
        //Get all the active UWP processes and update the lists
        async Task ListLoadCheckProcessesUwp(List <int> activeProcessesId, List <IntPtr> activeProcessesWindow, IEnumerable <DataBindApp> currentListApps, bool showStatus)
        {
            try
            {
                //Check if there are active processes
                Process frameHostProcess = GetProcessByNameOrTitle("ApplicationFrameHost", false);
                if (frameHostProcess != null)
                {
                    //Show refresh status message
                    if (showStatus)
                    {
                        await Notification_Send_Status("Refresh", "Refreshing store apps");
                    }
                    //Debug.WriteLine("Checking store processes.");

                    //Add new running process if needed
                    foreach (ProcessThread threadProcess in frameHostProcess.Threads)
                    {
                        try
                        {
                            //Process variables
                            Process processApp            = null;
                            int     processIdentifier     = -1;
                            bool    processInterfaceCheck = false;
                            IntPtr  processWindowHandle   = IntPtr.Zero;

                            foreach (IntPtr threadWindowHandle in EnumThreadWindows(threadProcess.Id))
                            {
                                try
                                {
                                    //Get window class name
                                    string classNameString = GetClassNameFromWindowHandle(threadWindowHandle);

                                    //Get information from frame window
                                    if (classNameString == "ApplicationFrameWindow")
                                    {
                                        //Set window handle
                                        processWindowHandle = threadWindowHandle;

                                        //Get app process
                                        IntPtr threadWindowHandleEx = FindWindowEx(threadWindowHandle, IntPtr.Zero, "Windows.UI.Core.CoreWindow", null);
                                        if (threadWindowHandleEx != IntPtr.Zero)
                                        {
                                            processIdentifier = GetProcessIdFromWindowHandle(threadWindowHandleEx);
                                            if (processIdentifier > 0)
                                            {
                                                processApp = GetProcessById(processIdentifier);
                                            }
                                        }
                                    }

                                    //Check if uwp application has interface
                                    if (classNameString == "MSCTFIME UI")
                                    {
                                        processInterfaceCheck = true;
                                    }
                                }
                                catch { }
                            }

                            //Check if uwp application has interface
                            if (processInterfaceCheck)
                            {
                                //Process application type
                                ProcessType processType = ProcessType.UWP;

                                //Process Windows Store Status
                                Visibility processStatusStore = Visibility.Visible;

                                //Get the process title
                                string processTitle = GetWindowTitleFromWindowHandle(processWindowHandle);

                                //Check if application title is blacklisted
                                if (vCtrlIgnoreProcessName.Any(x => x.String1.ToLower() == processTitle.ToLower()))
                                {
                                    continue;
                                }

                                //Get the application user model id
                                string processPathExe = GetAppUserModelIdFromWindowHandle(processWindowHandle);
                                if (string.IsNullOrWhiteSpace(processPathExe))
                                {
                                    processPathExe = GetAppUserModelIdFromProcess(processApp);
                                }
                                string processPathExeLower = processPathExe.ToLower();

                                //Get detailed application information
                                Package     appPackage               = UwpGetAppPackageByAppUserModelId(processPathExe);
                                AppxDetails appxDetails              = UwpGetAppxDetailsFromAppPackage(appPackage);
                                string      processNameExe           = appxDetails.ExecutableName;
                                string      processNameExeLower      = processNameExe.ToLower();
                                string      processNameExeNoExt      = Path.GetFileNameWithoutExtension(processNameExe);
                                string      processNameExeNoExtLower = processNameExeNoExt.ToLower();

                                //Check if application name is blacklisted
                                if (vCtrlIgnoreProcessName.Any(x => x.String1.ToLower() == processNameExeNoExtLower))
                                {
                                    continue;
                                }

                                //Check if the process has been found
                                if (processApp == null)
                                {
                                    processApp        = GetUwpProcessByProcessNameAndAppUserModelId(processNameExeNoExt, processPathExe);
                                    processIdentifier = processApp.Id;
                                }

                                //Add active process to the list
                                activeProcessesId.Add(processIdentifier);
                                activeProcessesWindow.Add(processWindowHandle);

                                //Check the process running time
                                int processRunningTime = ProcessRuntimeMinutes(processApp);

                                //Check if the process is suspended
                                Visibility processStatusRunning        = Visibility.Visible;
                                Visibility processStatusSuspended      = Visibility.Collapsed;
                                ProcessThreadCollection processThreads = processApp.Threads;
                                if (CheckProcessSuspended(processThreads))
                                {
                                    processStatusRunning   = Visibility.Collapsed;
                                    processStatusSuspended = Visibility.Visible;
                                }

                                //Convert Process To ProcessMulti
                                ProcessMulti processMultiNew = new ProcessMulti();
                                processMultiNew.Type         = processType;
                                processMultiNew.Identifier   = processIdentifier;
                                processMultiNew.WindowHandle = processWindowHandle;

                                //Set the application search filters
                                Func <DataBindApp, bool> filterCombinedApp = x => x.PathExe != null && x.PathExe.ToLower() == processPathExeLower;
                                Func <DataBindApp, bool> filterProcessApp  = x => x.ProcessMulti.Any(z => z.WindowHandle == processWindowHandle);

                                //Check all the lists for the application
                                IEnumerable <DataBindApp> existingCombinedApps = currentListApps.Where(filterCombinedApp);
                                IEnumerable <DataBindApp> existingProcessApps  = List_Processes.Where(filterProcessApp);
                                bool appUpdatedContinueLoop = false;

                                //Check if process is in combined list and update it
                                foreach (DataBindApp existingCombinedApp in existingCombinedApps)
                                {
                                    //Update the process running time
                                    existingCombinedApp.RunningTime = processRunningTime;

                                    //Update the process running status
                                    existingCombinedApp.StatusRunning = processStatusRunning;

                                    //Update the process suspended status
                                    existingCombinedApp.StatusSuspended = processStatusSuspended;

                                    //Update the application last runtime
                                    existingCombinedApp.RunningTimeLastUpdate = GetSystemTicksMs();

                                    //Add the new process multi application
                                    if (!existingCombinedApp.ProcessMulti.Any(x => x.WindowHandle == processWindowHandle))
                                    {
                                        existingCombinedApp.ProcessMulti.Add(processMultiNew);
                                    }

                                    //Remove app from processes list
                                    if (Convert.ToBoolean(Setting_Load(vConfigurationCtrlUI, "HideAppProcesses")))
                                    {
                                        await ListBoxRemoveAll(lb_Processes, List_Processes, filterCombinedApp);

                                        appUpdatedContinueLoop = true;
                                    }
                                }
                                if (appUpdatedContinueLoop)
                                {
                                    continue;
                                }

                                //Check if process is in process list and update it
                                foreach (DataBindApp existingProcessApp in existingProcessApps)
                                {
                                    //Update the process title
                                    if (existingProcessApp.Name != processTitle)
                                    {
                                        existingProcessApp.Name = processTitle;
                                    }

                                    //Update the process running time
                                    existingProcessApp.RunningTime = processRunningTime;

                                    //Update the process suspended status
                                    existingProcessApp.StatusSuspended = processStatusSuspended;

                                    //Update the process multi identifier
                                    foreach (ProcessMulti processMulti in existingProcessApp.ProcessMulti.Where(x => x.Identifier <= 0))
                                    {
                                        processMulti.Identifier = processIdentifier;
                                    }

                                    //Update the process multi window handle
                                    foreach (ProcessMulti processMulti in existingProcessApp.ProcessMulti.Where(x => x.WindowHandle == IntPtr.Zero))
                                    {
                                        processMulti.WindowHandle = processWindowHandle;
                                    }

                                    appUpdatedContinueLoop = true;
                                }
                                if (appUpdatedContinueLoop)
                                {
                                    continue;
                                }

                                //Load the application image
                                BitmapImage processImageBitmap = FileToBitmapImage(new string[] { processTitle, processNameExeNoExt, appxDetails.SquareLargestLogoPath, appxDetails.WideLargestLogoPath }, vImageSourceFolders, vImageBackupSource, processWindowHandle, 90, 0);

                                //Create new ProcessMulti list
                                List <ProcessMulti> listProcessMulti = new List <ProcessMulti>();
                                listProcessMulti.Add(processMultiNew);

                                //Add the process to the process list
                                DataBindApp dataBindApp = new DataBindApp()
                                {
                                    Type = processType, Category = AppCategory.Process, ProcessMulti = listProcessMulti, ImageBitmap = processImageBitmap, Name = processTitle, NameExe = processNameExe, PathExe = processPathExe, StatusStore = processStatusStore, StatusSuspended = processStatusSuspended, RunningTime = processRunningTime
                                };
                                await ListBoxAddItem(lb_Processes, List_Processes, dataBindApp, false, false);

                                //Add the process to the search list
                                await AddSearchProcess(dataBindApp);
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine("Failed adding UWP application: " + ex.Message);
                        }
                    }
                }
            }
            catch { }
        }
Esempio n. 21
0
        //Focus on a process window
        public static async Task <bool> FocusProcessWindow(string processTitle, int processId, IntPtr processWindowHandle, WindowShowCommand windowShowCommand, bool setWindowState, bool setTempTopMost)
        {
            try
            {
                //Prepare the process focus
                async Task <bool> TaskAction()
                {
                    try
                    {
                        //Close open Windows prompts
                        await CloseOpenWindowsPrompts();

                        //Get the current focused application
                        ProcessMulti foregroundProcess = GetProcessMultiFromWindowHandle(GetForegroundWindow());

                        //Close open start menu, cortana or search
                        await CloseOpenWindowsStartMenu(foregroundProcess);

                        //Close open Windows system menu
                        await CloseOpenWindowsSystemMenu(foregroundProcess);

                        //Detect the previous window state
                        if (windowShowCommand == WindowShowCommand.None && setWindowState)
                        {
                            WindowPlacement processWindowState = new WindowPlacement();
                            GetWindowPlacement(processWindowHandle, ref processWindowState);
                            Debug.WriteLine("Detected the previous window state: " + processWindowState.windowFlags);
                            if (processWindowState.windowFlags == WindowFlags.RestoreToMaximized)
                            {
                                windowShowCommand = WindowShowCommand.ShowMaximized;
                            }
                            else
                            {
                                windowShowCommand = WindowShowCommand.Restore;
                            }
                        }

                        //Change the window state command
                        if (setWindowState)
                        {
                            ShowWindowAsync(processWindowHandle, windowShowCommand);
                            await Task.Delay(10);

                            ShowWindow(processWindowHandle, windowShowCommand);
                            await Task.Delay(10);
                        }

                        //Set the window as top most
                        if (setTempTopMost)
                        {
                            SetWindowPos(processWindowHandle, (IntPtr)WindowPosition.TopMost, 0, 0, 0, 0, (int)WindowSWP.NOMOVE | (int)WindowSWP.NOSIZE);
                            await Task.Delay(10);
                        }

                        //Retry to show the window
                        for (int i = 0; i < 2; i++)
                        {
                            try
                            {
                                //Allow changing window
                                AllowSetForegroundWindow(processId);
                                await Task.Delay(10);

                                //Bring window to top
                                BringWindowToTop(processWindowHandle);
                                await Task.Delay(10);

                                //Switch to the window
                                SwitchToThisWindow(processWindowHandle, true);
                                await Task.Delay(10);

                                //Focus on the window
                                UiaFocusWindowHandle(processWindowHandle);
                                await Task.Delay(10);
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine("Process focus error: " + ex.Message);
                            }
                        }

                        //Disable the window as top most
                        if (setTempTopMost)
                        {
                            SetWindowPos(processWindowHandle, (IntPtr)WindowPosition.NoTopMost, 0, 0, 0, 0, (int)WindowSWP.NOMOVE | (int)WindowSWP.NOSIZE);
                            await Task.Delay(10);
                        }

                        //Return bool
                        Debug.WriteLine("Focused process window: " + processTitle + " WindowHandle: " + processWindowHandle + " ShowCmd: " + windowShowCommand);
                        return(true);
                    }
                    catch { }
                    Debug.WriteLine("Failed focusing process: " + processTitle);
                    return(false);
                };

                //Focus the process
                return(await AVActions.TaskStartReturn(TaskAction).Result);
            }
            catch { }
            Debug.WriteLine("Failed focusing process: " + processTitle);
            return(false);
        }
Esempio n. 22
0
        //Get all the active Win32 processes and update the lists
        async Task ListLoadCheckProcessesWin32(Process[] processesList, List <int> activeProcessesId, List <IntPtr> activeProcessesWindow, IEnumerable <DataBindApp> currentListApps, bool showStatus)
        {
            try
            {
                //Check if processes list is provided
                if (processesList == null)
                {
                    processesList = Process.GetProcesses();
                }

                //Check if there are active processes
                if (processesList.Any())
                {
                    //Show refresh status message
                    if (showStatus)
                    {
                        await Notification_Send_Status("Refresh", "Refreshing desktop apps");
                    }
                    //Debug.WriteLine("Checking desktop processes.");

                    //Add new running process if needed
                    foreach (Process processApp in processesList)
                    {
                        try
                        {
                            //Process identifier
                            int processIdentifier = processApp.Id;

                            //Process window handle
                            IntPtr processWindowHandle = processApp.MainWindowHandle;

                            //Process application type
                            ProcessType processType = ProcessType.Win32;

                            //Process Windows Store Status
                            Visibility processStatusStore = Visibility.Collapsed;

                            //Get the process title
                            string processTitle = GetWindowTitleFromProcess(processApp);

                            //Check if application title is blacklisted
                            if (vCtrlIgnoreProcessName.Any(x => x.String1.ToLower() == processTitle.ToLower()))
                            {
                                continue;
                            }

                            //Validate the process state
                            if (!ValidateProcessState(processApp, true, true))
                            {
                                continue;
                            }

                            //Validate the window handle
                            bool windowValidation = ValidateWindowHandle(processWindowHandle);

                            //Get the executable path
                            string processPathExe           = GetExecutablePathFromProcess(processApp);
                            string processPathExeLower      = processPathExe.ToLower();
                            string processPathExeImage      = processPathExe;
                            string processNameExe           = Path.GetFileName(processPathExe);
                            string processNameExeLower      = processNameExe.ToLower();
                            string processNameExeNoExt      = Path.GetFileNameWithoutExtension(processPathExe);
                            string processNameExeNoExtLower = processNameExeNoExt.ToLower();

                            //Get the process launch arguments
                            string processArgument = GetLaunchArgumentsFromProcess(processApp, processPathExe);

                            //Check if application name is blacklisted
                            if (vCtrlIgnoreProcessName.Any(x => x.String1.ToLower() == processNameExeNoExtLower))
                            {
                                continue;
                            }

                            //Check explorer process
                            if (processNameExeLower == "explorer.exe")
                            {
                                processTitle = "File Explorer";
                            }

                            //Add active process to the list
                            activeProcessesId.Add(processIdentifier);
                            activeProcessesWindow.Add(processWindowHandle);

                            //Check the process running time
                            int processRunningTime = ProcessRuntimeMinutes(processApp);

                            //Check if the process is suspended
                            Visibility processStatusRunning        = Visibility.Visible;
                            Visibility processStatusSuspended      = Visibility.Collapsed;
                            ProcessThreadCollection processThreads = processApp.Threads;
                            if (CheckProcessSuspended(processThreads))
                            {
                                processStatusRunning   = Visibility.Collapsed;
                                processStatusSuspended = Visibility.Visible;
                            }

                            //Set the application search filters
                            Func <DataBindApp, bool> filterCombinedApp = x => (!string.IsNullOrWhiteSpace(x.PathExe) && Path.GetFileNameWithoutExtension(x.PathExe).ToLower() == processNameExeNoExtLower) || (!string.IsNullOrWhiteSpace(x.NameExe) && x.NameExe.ToLower() == processNameExeLower);
                            Func <DataBindApp, bool> filterProcessApp  = x => x.ProcessMulti.Any(z => z.WindowHandle == processWindowHandle);

                            //Check if process is a Win32Store app
                            string processAppUserModelId = GetAppUserModelIdFromProcess(processApp);
                            if (!string.IsNullOrWhiteSpace(processAppUserModelId))
                            {
                                processType         = ProcessType.Win32Store;
                                processPathExe      = processAppUserModelId;
                                processPathExeLower = processAppUserModelId.ToLower();
                                processStatusStore  = Visibility.Visible;
                                filterCombinedApp   = x => (!string.IsNullOrWhiteSpace(x.PathExe) && x.PathExe.ToLower() == processPathExeLower) || (!string.IsNullOrWhiteSpace(x.NameExe) && x.NameExe.ToLower() == processNameExeLower);

                                //Validate the window handle
                                if (!windowValidation)
                                {
                                    //Debug.WriteLine(processName + " is an invalid Win32Store application.");
                                    continue;
                                }
                                else
                                {
                                    //Debug.WriteLine(processName + " is a Win32Store application.");}
                                }
                            }

                            //Convert Process To ProcessMulti
                            ProcessMulti processMultiNew = new ProcessMulti();
                            processMultiNew.Type         = processType;
                            processMultiNew.Identifier   = processIdentifier;
                            processMultiNew.WindowHandle = processWindowHandle;
                            processMultiNew.Argument     = processArgument;

                            //Check all the lists for the application
                            IEnumerable <DataBindApp> existingCombinedApps = currentListApps.Where(filterCombinedApp);
                            IEnumerable <DataBindApp> existingProcessApps  = List_Processes.Where(filterProcessApp);
                            bool appUpdatedContinueLoop = false;

                            //Check if process is in combined list and update it
                            foreach (DataBindApp existingCombinedApp in existingCombinedApps)
                            {
                                //Update the process running time
                                existingCombinedApp.RunningTime = processRunningTime;

                                //Update the process running status
                                existingCombinedApp.StatusRunning = processStatusRunning;

                                //Update the process suspended status
                                existingCombinedApp.StatusSuspended = processStatusSuspended;

                                //Update the application last runtime
                                existingCombinedApp.RunningTimeLastUpdate = GetSystemTicksMs();

                                //Add the new process multi application
                                if (!existingCombinedApp.ProcessMulti.Any(x => x.WindowHandle == processWindowHandle))
                                {
                                    existingCombinedApp.ProcessMulti.Add(processMultiNew);
                                }

                                //Remove app from processes list
                                if (Convert.ToBoolean(Setting_Load(vConfigurationCtrlUI, "HideAppProcesses")))
                                {
                                    await ListBoxRemoveAll(lb_Processes, List_Processes, filterCombinedApp);

                                    appUpdatedContinueLoop = true;
                                }
                            }
                            if (appUpdatedContinueLoop)
                            {
                                continue;
                            }

                            //Check if process is in process list and update it
                            foreach (DataBindApp existingProcessApp in existingProcessApps)
                            {
                                //Update the process title
                                if (existingProcessApp.Name != processTitle)
                                {
                                    existingProcessApp.Name = processTitle;
                                }

                                //Update the process running time
                                existingProcessApp.RunningTime = processRunningTime;

                                //Update the process suspended status
                                existingProcessApp.StatusSuspended = processStatusSuspended;

                                //Update the process multi identifier
                                foreach (ProcessMulti processMulti in existingProcessApp.ProcessMulti.Where(x => x.Identifier <= 0))
                                {
                                    processMulti.Identifier = processIdentifier;
                                }

                                //Update the process multi window handle
                                foreach (ProcessMulti processMulti in existingProcessApp.ProcessMulti.Where(x => x.WindowHandle == IntPtr.Zero))
                                {
                                    processMulti.WindowHandle = processWindowHandle;
                                }

                                appUpdatedContinueLoop = true;
                            }
                            if (appUpdatedContinueLoop)
                            {
                                continue;
                            }

                            //Validate the window handle
                            if (!windowValidation)
                            {
                                continue;
                            }

                            //Load Windows store application images
                            string storeImageSquare = string.Empty;
                            string storeImageWide   = string.Empty;
                            if (processType == ProcessType.Win32Store)
                            {
                                Package     appPackage  = UwpGetAppPackageByAppUserModelId(processPathExe);
                                AppxDetails appxDetails = UwpGetAppxDetailsFromAppPackage(appPackage);
                                storeImageSquare = appxDetails.SquareLargestLogoPath;
                                storeImageWide   = appxDetails.WideLargestLogoPath;
                            }

                            //Load the application image
                            BitmapImage processImageBitmap = FileToBitmapImage(new string[] { processTitle, processNameExeNoExt, storeImageSquare, storeImageWide, processPathExeImage, processPathExe }, vImageSourceFolders, vImageBackupSource, processWindowHandle, 90, 0);

                            //Create new ProcessMulti list
                            List <ProcessMulti> listProcessMulti = new List <ProcessMulti>();
                            listProcessMulti.Add(processMultiNew);

                            //Add the process to the process list
                            DataBindApp dataBindApp = new DataBindApp()
                            {
                                Type = processType, Category = AppCategory.Process, ProcessMulti = listProcessMulti, ImageBitmap = processImageBitmap, Name = processTitle, NameExe = processNameExe, PathExe = processPathExe, StatusStore = processStatusStore, StatusSuspended = processStatusSuspended, RunningTime = processRunningTime
                            };
                            await ListBoxAddItem(lb_Processes, List_Processes, dataBindApp, false, false);

                            //Add the process to the search list
                            await AddSearchProcess(dataBindApp);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine("Failed adding Win32 or Win32Store application: " + ex.Message);
                        }
                    }
                }
            }
            catch { }
        }
Esempio n. 23
0
        //Close single process Win32 and Win32Store
        async Task <bool> CloseSingleProcessWin32AndWin32Store(DataBindApp dataBindApp, ProcessMulti processMulti, bool resetProcess, bool removeProcess)
        {
            try
            {
                await Notification_Send_Status("AppClose", "Closing " + dataBindApp.Name);

                Debug.WriteLine("Closing Win32 and Win32Store process: " + dataBindApp.Name);

                //Close the process by id or name
                bool closedProcess = false;
                if (processMulti.Identifier > 0)
                {
                    closedProcess = CloseProcessById(processMulti.Identifier);
                }
                else if (!string.IsNullOrWhiteSpace(dataBindApp.NameExe))
                {
                    closedProcess = CloseProcessesByNameOrTitle(Path.GetFileNameWithoutExtension(dataBindApp.NameExe), false);
                }
                else
                {
                    closedProcess = CloseProcessesByNameOrTitle(Path.GetFileNameWithoutExtension(dataBindApp.PathExe), false);
                }

                //Check if process closed
                if (closedProcess)
                {
                    await Notification_Send_Status("AppClose", "Closed " + dataBindApp.Name);

                    Debug.WriteLine("Closed Win32 and Win32Store process: " + dataBindApp.Name);

                    //Reset the process running status
                    if (resetProcess)
                    {
                        dataBindApp.StatusRunning         = Visibility.Collapsed;
                        dataBindApp.StatusSuspended       = Visibility.Collapsed;
                        dataBindApp.RunningProcessCount   = string.Empty;
                        dataBindApp.RunningTimeLastUpdate = 0;
                        dataBindApp.ProcessMulti.Clear();
                    }

                    //Remove the process from the list
                    if (removeProcess)
                    {
                        await RemoveAppFromList(dataBindApp, false, false, true);
                    }

                    return(true);
                }
                else
                {
                    await Notification_Send_Status("AppClose", "Failed to close the app");

                    Debug.WriteLine("Failed to close the application.");
                    return(false);
                }
            }
            catch { }
            return(false);
        }
Esempio n. 24
0
        async Task LoopMonitorProcess()
        {
            try
            {
                while (!vTask_MonitorProcess.TaskStopRequest)
                {
                    try
                    {
                        //Update the current time
                        UpdateCurrentTime();

                        //Get and check the focused process
                        ProcessMulti foregroundProcess = GetProcessMultiFromWindowHandle(GetForegroundWindow());
                        if (foregroundProcess == null)
                        {
                            Debug.WriteLine("No active or valid process found.");

                            //Reset the fps counter
                            ResetFpsCounter();

                            //Hide the application name and frames
                            HideApplicationNameFrames();

                            //Delay the loop task
                            await TaskDelayLoop(1000, vTask_MonitorProcess);

                            continue;
                        }

                        Debug.WriteLine("Checking process: (" + foregroundProcess.Identifier + ") " + foregroundProcess.Name);

                        //Check if the foreground window has changed
                        if (vTargetProcess.Identifier == foregroundProcess.Identifier)
                        {
                            Debug.WriteLine("Foreground window has not changed.");

                            //Update the current target process
                            vTargetProcess = foregroundProcess;

                            //Update the application name
                            UpdateApplicationName(foregroundProcess.Title);

                            //Delay the loop task
                            await TaskDelayLoop(1000, vTask_MonitorProcess);

                            continue;
                        }

                        Debug.WriteLine("New foreground window detected (" + foregroundProcess.Identifier + ") " + foregroundProcess.Name);

                        //Reset the fps counter
                        ResetFpsCounter();

                        //Update the fps overlayer position
                        UpdateFpsOverlayPosition(foregroundProcess.Name);

                        //Check if the foreground window is fps overlayer
                        if (vProcessCurrent.Id == foregroundProcess.Identifier)
                        {
                            Debug.WriteLine("Current process is fps overlayer.");

                            //Hide the application name and frames
                            HideApplicationNameFrames();

                            //Delay the loop task
                            await TaskDelayLoop(1000, vTask_MonitorProcess);

                            continue;
                        }

                        //Update the application name
                        UpdateApplicationName(foregroundProcess.Title);

                        //Update the current target process
                        vTargetProcess = foregroundProcess;
                    }
                    catch { }

                    //Delay the loop task
                    await TaskDelayLoop(1000, vTask_MonitorProcess);
                }
            }
            catch { }
        }
Esempio n. 25
0
        //Check if process has multiple windows
        async Task <IntPtr> CheckProcessWindowsWin32AndWin32Store(DataBindApp dataBindApp, ProcessMulti processMulti)
        {
            try
            {
                //Get threads from process
                ProcessThreadCollection processThreads = GetProcessThreads(processMulti);

                //Check threads from process
                int processThreadCount = processThreads.Count;
                if (processThreadCount > 1)
                {
                    Debug.WriteLine("Found window threads: " + processThreadCount);

                    List <DataBindString> multiAnswers   = new List <DataBindString>();
                    List <IntPtr>         multiVariables = new List <IntPtr>();
                    foreach (ProcessThread threadProcess in processThreads)
                    {
                        foreach (IntPtr threadWindowHandle in EnumThreadWindows(threadProcess.Id))
                        {
                            try
                            {
                                //Check if window handle is already added
                                string windowHandleString = threadWindowHandle.ToString();
                                if (multiAnswers.Any(x => x.Data1.ToString() == windowHandleString))
                                {
                                    //Debug.WriteLine("Duplicate window handle detected, skipping.");
                                    continue;
                                }

                                //Validate the window handle
                                if (threadWindowHandle == processMulti.WindowHandle || ValidateWindowHandle(threadWindowHandle))
                                {
                                    //Get the window state
                                    WindowPlacement processWindowState = new WindowPlacement();
                                    GetWindowPlacement(threadWindowHandle, ref processWindowState);

                                    //Get the window title
                                    string windowTitleString = GetWindowTitleFromWindowHandle(threadWindowHandle);
                                    string windowSubString   = windowHandleString;

                                    //Check window main
                                    if (threadWindowHandle == processMulti.WindowHandle)
                                    {
                                        windowSubString += " (Main)";
                                    }

                                    //Check window style
                                    WindowStylesEx windowStyle = (WindowStylesEx)GetWindowLongAuto(threadWindowHandle, (int)WindowLongFlags.GWL_EXSTYLE).ToInt64();
                                    if (windowStyle.HasFlag(WindowStylesEx.WS_EX_TOOLWINDOW) || windowStyle.HasFlag(WindowStylesEx.WS_EX_LAYERED))
                                    {
                                        windowSubString += " (Tool)";
                                    }
                                    else
                                    {
                                        windowSubString += " (Window)";
                                    }

                                    //Check window state
                                    if (processWindowState.windowShowCommand == WindowShowCommand.Minimized)
                                    {
                                        windowSubString += " (Minimized)";
                                    }

                                    //Check explorer window
                                    if (dataBindApp.NameExe.ToLower() == "explorer.exe")
                                    {
                                        if (windowTitleString == "Unknown" || windowStyle.HasFlag(WindowStylesEx.WS_EX_TOOLWINDOW) || windowStyle.HasFlag(WindowStylesEx.WS_EX_LAYERED))
                                        {
                                            continue;
                                        }
                                    }

                                    DataBindString Answer1 = new DataBindString();
                                    Answer1.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppMiniMaxi.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                                    Answer1.Name        = windowTitleString;
                                    Answer1.NameSub     = windowSubString;
                                    Answer1.Data1       = windowHandleString;

                                    //Add window to selection
                                    if (threadWindowHandle == processMulti.WindowHandle)
                                    {
                                        multiAnswers.Insert(0, Answer1);
                                        multiVariables.Insert(0, threadWindowHandle);
                                    }
                                    else
                                    {
                                        multiAnswers.Add(Answer1);
                                        multiVariables.Add(threadWindowHandle);
                                    }
                                }
                            }
                            catch
                            {
                                Debug.WriteLine("Failed checking window handle: " + threadWindowHandle);
                            }
                        }
                    }

                    //Check if there are multiple answers
                    if (multiVariables.Count == 1)
                    {
                        Debug.WriteLine("There is only one visible window, returning the default window.");
                        return(multiVariables.FirstOrDefault());
                    }
                    else if (multiVariables.Count == 0)
                    {
                        return(IntPtr.Zero);
                    }

                    DataBindString AnswerClose = new DataBindString();
                    AnswerClose.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppClose.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                    AnswerClose.Name        = "Close application";
                    multiAnswers.Add(AnswerClose);

                    DataBindString AnswerLaunch = new DataBindString();
                    AnswerLaunch.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppLaunch.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                    AnswerLaunch.Name        = "Launch new instance";
                    multiAnswers.Add(AnswerLaunch);

                    DataBindString AnswerRestartCurrent = new DataBindString();
                    if (!string.IsNullOrWhiteSpace(processMulti.Argument))
                    {
                        AnswerRestartCurrent.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppRestart.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                        AnswerRestartCurrent.Name        = "Restart application";
                        AnswerRestartCurrent.NameSub     = "(Current argument)";
                        multiAnswers.Add(AnswerRestartCurrent);
                    }

                    DataBindString AnswerRestartWithout = new DataBindString();
                    AnswerRestartWithout.ImageBitmap = FileToBitmapImage(new string[] { "Assets/Default/Icons/AppRestart.png" }, vImageSourceFolders, vImageBackupSource, IntPtr.Zero, -1, 0);
                    AnswerRestartWithout.Name        = "Restart application";
                    if (!string.IsNullOrWhiteSpace(dataBindApp.Argument) || dataBindApp.Category == AppCategory.Shortcut || dataBindApp.Category == AppCategory.Emulator || dataBindApp.LaunchFilePicker)
                    {
                        AnswerRestartWithout.NameSub = "(Default argument)";
                    }
                    else
                    {
                        AnswerRestartWithout.NameSub = "(Without argument)";
                    }
                    multiAnswers.Add(AnswerRestartWithout);

                    //Ask which window needs to be shown
                    DataBindString messageResult = await Popup_Show_MessageBox(dataBindApp.Name + " has multiple windows open", "", "Please select the window that you wish to be shown:", multiAnswers);

                    if (messageResult != null)
                    {
                        if (messageResult == AnswerLaunch)
                        {
                            return(new IntPtr(-50));
                        }
                        else if (messageResult == AnswerRestartCurrent)
                        {
                            return(new IntPtr(-75));
                        }
                        else if (messageResult == AnswerRestartWithout)
                        {
                            return(new IntPtr(-80));
                        }
                        else if (messageResult == AnswerClose)
                        {
                            return(new IntPtr(-100));
                        }
                        else
                        {
                            return(multiVariables[multiAnswers.IndexOf(messageResult)]);
                        }
                    }
                    else
                    {
                        //Cancel the selection
                        return(new IntPtr(-200));
                    }
                }
                else
                {
                    Debug.WriteLine("Single window thread process: " + processMulti.WindowHandle);
                    return(processMulti.WindowHandle);
                }
            }
            catch
            {
                return(IntPtr.Zero);
            }
        }