├── App.config
├── Program.cs
├── Properties
└── AssemblyInfo.cs
├── RunHidden.csproj
├── RunHidden.ico
└── RunHidden.sln
/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using System.IO;
4 | using System.Text.RegularExpressions;
5 |
6 | namespace RunHidden
7 | {
8 | class Program
9 | {
10 | static void Main(string[] args)
11 | {
12 | if (args.Length < 1) { return; }
13 |
14 | string scriptPath = args[0];
15 |
16 | bool pwsh = scriptPath.Contains("*");
17 | scriptPath = scriptPath.Replace("*", "");
18 |
19 | if (!File.Exists(scriptPath)) { return; }
20 |
21 | string extension = Path.GetExtension(scriptPath).ToLower();
22 |
23 | string cmdArgs = Environment.CommandLine;
24 |
25 | //Replace all spaces, within quoted substrings, to xFF
26 | cmdArgs = Regex.Replace(cmdArgs, "\"([^\"]*)\"", m =>
27 | {
28 | return "\"" + m.Groups[1].Value.Replace(" ", "\u00FF") + "\"";
29 | });
30 |
31 | //Ensure there is only a single space between arguments
32 | cmdArgs = Regex.Replace(cmdArgs, "\\s+", " ");
33 |
34 | //Split off parameters to be passed through to the script
35 | string[] parts = cmdArgs.Split(new char[] { ' ' }, 3);
36 | cmdArgs = "";
37 | if (parts.Length > 2)
38 | {
39 | //Restore xFF to space
40 | cmdArgs = parts[2].Replace("\u00FF", " ");
41 | }
42 |
43 | ProcessStartInfo psi = new ProcessStartInfo();
44 |
45 | if (extension.Equals(".ps1"))
46 | {
47 | //Ensure quoted trailing backslashes are not escaped to quotes
48 | cmdArgs = cmdArgs.Replace("\\\"", "\\\\\"");
49 | cmdArgs = cmdArgs.Replace("\\\\\\\"", "\\\\\"");
50 |
51 | psi.FileName = "powershell.exe";
52 | if (pwsh) psi.FileName = "pwsh.exe";
53 | psi.Arguments = $"-NoProfile -ExecutionPolicy Bypass -File \"{scriptPath}\" {cmdArgs}";
54 | }
55 | else if (extension.Equals(".py"))
56 | {
57 | psi.FileName = "python.exe";
58 | psi.Arguments = $" \"{scriptPath}\" {cmdArgs}";
59 | }
60 | else if (extension.Equals(".exe"))
61 | {
62 | psi.FileName = scriptPath;
63 | psi.Arguments = $" {cmdArgs}";
64 | }
65 | else
66 | {
67 | psi.FileName = "cmd.exe";
68 | psi.Arguments = $"/c \"\"{scriptPath}\" {cmdArgs}\"";
69 | }
70 |
71 | psi.RedirectStandardOutput = false;
72 | psi.RedirectStandardError = false;
73 | psi.UseShellExecute = false;
74 | psi.CreateNoWindow = true;
75 |
76 | using (Process process = new Process())
77 | {
78 | process.StartInfo = psi;
79 | process.Start();
80 | }
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("RunHidden")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("RunHidden")]
13 | [assembly: AssemblyCopyright("LesFerch")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("feb834e5-3de6-4c18-96a5-45737cbac70e")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.2.0.0")]
36 | [assembly: AssemblyFileVersion("1.2.0.0")]
37 |
--------------------------------------------------------------------------------
/RunHidden.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {FEB834E5-3DE6-4C18-96A5-45737CBAC70E}
8 | WinExe
9 | RunHidden
10 | RunHidden
11 | v4.8
12 | 512
13 | true
14 | true
15 |
16 |
17 | AnyCPU
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | AnyCPU
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 | false
35 |
36 |
37 |
38 |
39 |
40 | RunHidden.ico
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/RunHidden.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LesFerch/RunHidden/c1214f6fce101665c898534134accf9fa744ef97/RunHidden.ico
--------------------------------------------------------------------------------
/RunHidden.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.6.33815.320
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RunHidden", "RunHidden.csproj", "{FEB834E5-3DE6-4C18-96A5-45737CBAC70E}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {FEB834E5-3DE6-4C18-96A5-45737CBAC70E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {FEB834E5-3DE6-4C18-96A5-45737CBAC70E}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {FEB834E5-3DE6-4C18-96A5-45737CBAC70E}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {FEB834E5-3DE6-4C18-96A5-45737CBAC70E}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {0FFBDBC1-57F0-466C-AA5C-EC77B472833B}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------