Skip to content
This repository has been archived by the owner on Jan 9, 2019. It is now read-only.

Commit

Permalink
Fix daemon startup spam
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Sampson committed Jan 10, 2017
1 parent be21028 commit 0a7dc89
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 43 deletions.
3 changes: 1 addition & 2 deletions RemoteTaskServer/Api/Network/UlteriusAgentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ private void KeepAlive()
Thread.Sleep(10000);
while (true)
{


Tools.RestartDaemon();
var alive = ChannelActive();
if (!alive)
{
Expand Down
29 changes: 29 additions & 0 deletions RemoteTaskServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Reflection;
using System.Runtime;
using System.Runtime.InteropServices;
using Topshelf;
using UlteriusServer.Forms.Utilities;
using UlteriusServer.Utilities;
Expand All @@ -18,11 +19,39 @@ namespace UlteriusServer
internal class Program
{
//Evan will have to support me and my cat once this gets released into the public.
/// <summary>
/// Hide the console window from the user
/// </summary>
private static void HideWindow()
{
var handle = GetConsoleWindow();
ShowWindow(handle, Hide);
}

#region win32

private const int Hide = 0;

[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

[DllImport("kernel32.dll")]
private static extern IntPtr GetConsoleWindow();


[DllImport("user32.dll")]
private static extern bool SetProcessDPIAware();
#endregion

private static void Main(string[] args)

{
//Fix screensize issues for Screen Share
if (Environment.OSVersion.Version.Major >= 6)
{
SetProcessDPIAware();
}
HideWindow();
try
{
if (
Expand Down
43 changes: 2 additions & 41 deletions RemoteTaskServer/Ulterius.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ public void Start(bool serviceMode = false)
ExceptionHandler.AddGlobalHandlers();
Console.WriteLine("Exception Handlers Attached");
}

//Fix screensize issues for Screen Share
if (Tools.RunningPlatform() == Tools.Platform.Windows && Environment.OSVersion.Version.Major >= 6)
{
SetProcessDPIAware();
}

Setup();
}

Expand All @@ -59,17 +54,7 @@ public void Start(bool serviceMode = false)
/// </summary>
private void Setup()
{
if (Tools.RunningPlatform() == Tools.Platform.Windows)
{
try
{
HideWindow();
}
catch
{
//Failed to hide window, probably in service mode.
}
}



Console.WriteLine("Creating settings");
Expand Down Expand Up @@ -124,29 +109,5 @@ private void Setup()
}


/// <summary>
/// Hide the console window from the user
/// </summary>
private void HideWindow()
{
var handle = GetConsoleWindow();
ShowWindow(handle, Hide);
}

#region win32

private const int Hide = 0;

[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

[DllImport("kernel32.dll")]
private static extern IntPtr GetConsoleWindow();


[DllImport("user32.dll")]
private static extern bool SetProcessDPIAware();

#endregion
}
}
21 changes: 21 additions & 0 deletions RemoteTaskServer/Utilities/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,29 @@ public static bool HasInternetConnection
}
}

public static void RestartDaemon()
{

try
{
if (Process.GetProcessesByName("DaemonManager").Length != 0) return;
ProcessStarter.PROCESS_INFORMATION managerInfo;
var managerPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"DaemonManager.exe");
ProcessStarter.StartProcessAndBypassUAC(managerPath,
out managerInfo);
managerProcess = Process.GetProcessById((int)managerInfo.dwProcessId);
}
catch (Exception)
{


}
}

public static void RestartAgent()
{

_LastSession = Desktop.WTSGetActiveConsoleSessionId();
_CurrentSession = _LastSession;
try
Expand Down

0 comments on commit 0a7dc89

Please sign in to comment.