Added another workaround using ManagementClass to bypass showing In-Game on Steam

This commit is contained in:
Jaex 2022-09-24 21:49:41 +03:00
parent 50cfd920d0
commit fa2633ef05
2 changed files with 69 additions and 32 deletions

View file

@ -27,6 +27,7 @@
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)

View file

@ -47,6 +47,7 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Management" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>