diff --git a/ShareX.Steam/Launcher.cs b/ShareX.Steam/Launcher.cs index 7072a0f13..9f70969bb 100644 --- a/ShareX.Steam/Launcher.cs +++ b/ShareX.Steam/Launcher.cs @@ -27,6 +27,7 @@ You should have received a copy of the GNU General Public License using System; using System.Diagnostics; using System.IO; +using System.Management; using System.Threading; using System.Windows.Forms; @@ -222,26 +223,37 @@ private static void RunShareX(string arguments = "") { try { - if (ShowInApp) + if (!ShowInApp) { - using (Process process = new Process()) - { - ProcessStartInfo psi = new ProcessStartInfo() - { - FileName = ContentExecutablePath, - Arguments = arguments, - UseShellExecute = true - }; + // Workarounds to not show "In-Game" on Steam. - process.StartInfo = psi; - process.Start(); - } - } - else - { + // Workaround 1. + try + { + using (ManagementClass managementClass = new ManagementClass("Win32_Process")) + { + ManagementClass processInfo = new ManagementClass("Win32_ProcessStartup"); + processInfo.Properties["CreateFlags"].Value = 0x00000008; + + ManagementBaseObject inParameters = managementClass.GetMethodParameters("Create"); + inParameters["CommandLine"] = $"\"{ContentExecutablePath}\" {arguments}"; + inParameters["ProcessStartupInformation"] = processInfo; + + ManagementBaseObject result = managementClass.InvokeMethod("Create", inParameters, null); + // Returns a value of 0 (zero) if the process was successfully created, and any other number to indicate an error. + if (result != null && (uint)result.Properties["ReturnValue"].Value == 0) + { + return; + } + } + } + catch + { + } + + // Workaround 2. try { - // Workaround to don't show "In-app". uint result = Helpers.WinExec($"\"{ContentExecutablePath}\" {arguments}", 5); // If the function succeeds, the return value is greater than 31. @@ -254,27 +266,51 @@ private static void RunShareX(string arguments = "") { } - // Workaround 2. - string path = Path.Combine(Environment.SystemDirectory, "cmd.exe"); - - if (!File.Exists(path)) + // Workaround 3. + try { - path = "cmd.exe"; - } + string path = Path.Combine(Environment.SystemDirectory, "cmd.exe"); - using (Process process = new Process()) - { - ProcessStartInfo psi = new ProcessStartInfo() + if (!File.Exists(path)) { - FileName = path, - Arguments = $"/C start \"\" \"{ContentExecutablePath}\" {arguments}", - UseShellExecute = false, - CreateNoWindow = true - }; + path = "cmd.exe"; + } - process.StartInfo = psi; - process.Start(); + using (Process process = new Process()) + { + ProcessStartInfo psi = new ProcessStartInfo() + { + FileName = path, + Arguments = $"/C start \"\" \"{ContentExecutablePath}\" {arguments}", + UseShellExecute = false, + CreateNoWindow = true + }; + + process.StartInfo = psi; + bool result = process.Start(); + + if (result) + { + return; + } + } } + catch + { + } + } + + using (Process process = new Process()) + { + ProcessStartInfo psi = new ProcessStartInfo() + { + FileName = ContentExecutablePath, + Arguments = arguments, + UseShellExecute = true + }; + + process.StartInfo = psi; + process.Start(); } } catch (Exception e) diff --git a/ShareX.Steam/ShareX.Steam.csproj b/ShareX.Steam/ShareX.Steam.csproj index 5046368f6..34c9e892d 100644 --- a/ShareX.Steam/ShareX.Steam.csproj +++ b/ShareX.Steam/ShareX.Steam.csproj @@ -47,6 +47,7 @@ +