Skip to content

Commit

Permalink
using dotnet 4.0 client fw, 60s timeout kill
Browse files Browse the repository at this point in the history
using different framework, so no config file is required to start with correct framework
  • Loading branch information
SeidChr committed Nov 17, 2018
1 parent 3e36635 commit c647157
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
8 changes: 4 additions & 4 deletions App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/></startup>
</configuration>
27 changes: 17 additions & 10 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace PowerShellWindowHost
{
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
Expand All @@ -14,10 +13,15 @@ public static int Main(string[] args)
var executingAssembly = Assembly.GetExecutingAssembly();

var fullName = Path.GetFileName(executingAssembly.Location);


SimpleLog.Prefix = $"{fullName}.";

SimpleLog.Info($"RunHiddenConsole Executing Assembly FullName: {fullName}");

var match = Regex.Match(fullName, @"(.+)w(\.\w{1,3})");
if (!match.Success)
{
SimpleLog.Error("Unable to find target executable name in own executable name.");
return -7001;
}

Expand All @@ -28,8 +32,8 @@ public static int Main(string[] args)

var startInfo = new ProcessStartInfo
{
CreateNoWindow = true,
UseShellExecute = false,
////CreateNoWindow = true,
////UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
WorkingDirectory = Directory.GetCurrentDirectory(),
Arguments = string.Join(" ", args),
Expand All @@ -41,20 +45,23 @@ public static int Main(string[] args)
var proc = Process.Start(startInfo);
if (proc == null)
{
SimpleLog.Error("Unable to start the target process.");
return -7002;
}

proc.WaitForExit();
if (!proc.WaitForExit(60000))
{
SimpleLog.Error("Process didn't close within 60s. Killing.");
proc.Kill();
}

return proc.ExitCode;
}
catch (Win32Exception)
catch (Exception ex)
{
SimpleLog.Error("Starting target process threw an unknown Exception: " + ex);
return -7003;
}
catch (SystemException)
{
return -7004;
}
}
}
}
3 changes: 2 additions & 1 deletion RunHiddenConsole.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
<OutputType>WinExe</OutputType>
<RootNamespace>PowerShellWindowHost</RootNamespace>
<AssemblyName>hiddenw</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup>
<StartupObject>PowerShellWindowHost.Program</StartupObject>
Expand Down

0 comments on commit c647157

Please sign in to comment.