Skip to content

Commit

Permalink
Package updates. Check WindowsIdentity vs Session ID for AppLauncher.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Oct 24, 2020
1 parent 4f76208 commit 7eb11ea
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 51 deletions.
10 changes: 5 additions & 5 deletions Agent/Agent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.1.7" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.7" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.7" />
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="3.1.7" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="3.1.9" />
<PackageReference Include="Microsoft.Management.Infrastructure" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.7" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.9" />
<PackageReference Include="Microsoft.PowerShell.Commands.Diagnostics" Version="7.0.3" />
<PackageReference Include="Microsoft.PowerShell.Commands.Management" Version="7.0.3" />
<PackageReference Include="Microsoft.PowerShell.Commands.Utility" Version="7.0.3" />
Expand Down
10 changes: 9 additions & 1 deletion Agent/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Extensions.Logging;
using Remotely.Agent.Interfaces;
using Remotely.Agent.Services;
using Remotely.Shared.Enums;
using Remotely.Shared.Utilities;
using System;
using System.Diagnostics;
Expand Down Expand Up @@ -93,7 +94,14 @@ private static async Task Init()
{
_ = Task.Run(() =>
{
ServiceBase.Run(new WindowsService());
try
{
ServiceBase.Run(new WindowsService());
}
catch (Exception ex)
{
Logger.Write(ex, "Failed to start service.", EventType.Warning);
}
});
}

Expand Down
40 changes: 20 additions & 20 deletions Agent/Services/AppLauncherWin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Security.Principal;
using System.Threading.Tasks;

namespace Remotely.Agent.Services
Expand Down Expand Up @@ -34,11 +35,7 @@ public async Task<int> LaunchChatService(string orgName, string requesterID, Hub

// Start Desktop app.
await hubConnection.SendAsync("DisplayMessage", $"Starting chat service...", "Starting chat service.", requesterID);
if (Process.GetCurrentProcess().SessionId > 0)
{
return Process.Start(rcBinaryPath, $"-mode Chat -requester \"{requesterID}\" -organization \"{orgName}\"").Id;
}
else
if (WindowsIdentity.GetCurrent().IsSystem)
{
var result = Win32Interop.OpenInteractiveProcess($"{rcBinaryPath} -mode Chat -requester \"{requesterID}\" -organization \"{orgName}\"",
targetSessionId: -1,
Expand All @@ -55,6 +52,10 @@ public async Task<int> LaunchChatService(string orgName, string requesterID, Hub
return procInfo.dwProcessId;
}
}
else
{
return Process.Start(rcBinaryPath, $"-mode Chat -requester \"{requesterID}\" -organization \"{orgName}\"").Id;
}
}
catch (Exception ex)
{
Expand All @@ -78,13 +79,7 @@ public async Task LaunchRemoteControl(int targetSessionId, string requesterID, s

// Start Desktop app.
await hubConnection.SendAsync("DisplayMessage", $"Starting remote control...", "Starting remote control.", requesterID);
if (Process.GetCurrentProcess().SessionId > 0)
{
// SignalR Connection IDs might start with a hyphen. We surround them
// with quotes so the command line will be parsed correctly.
Process.Start(rcBinaryPath, $"-mode Unattended -requester \"{requesterID}\" -serviceid \"{serviceID}\" -deviceid {ConnectionInfo.DeviceID} -host {ConnectionInfo.Host}");
}
else
if (WindowsIdentity.GetCurrent().IsSystem)
{
var result = Win32Interop.OpenInteractiveProcess(rcBinaryPath + $" -mode Unattended -requester \"{requesterID}\" -serviceid \"{serviceID}\" -deviceid {ConnectionInfo.DeviceID} -host {ConnectionInfo.Host}",
targetSessionId: targetSessionId,
Expand All @@ -97,6 +92,12 @@ public async Task LaunchRemoteControl(int targetSessionId, string requesterID, s
await hubConnection.SendAsync("DisplayMessage", "Remote control failed to start on target device.", "Failed to start remote control.", requesterID);
}
}
else
{
// SignalR Connection IDs might start with a hyphen. We surround them
// with quotes so the command line will be parsed correctly.
Process.Start(rcBinaryPath, $"-mode Unattended -requester \"{requesterID}\" -serviceid \"{serviceID}\" -deviceid {ConnectionInfo.DeviceID} -host {ConnectionInfo.Host}");
}
}
catch (Exception ex)
{
Expand All @@ -111,15 +112,8 @@ public async Task RestartScreenCaster(List<string> viewerIDs, string serviceID,
var rcBinaryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Desktop", EnvironmentHelper.DesktopExecutableFileName);
// Start Desktop app.
Logger.Write("Restarting screen caster.");
if (Process.GetCurrentProcess().SessionId > 0)
{
// SignalR Connection IDs might start with a hyphen. We surround them
// with quotes so the command line will be parsed correctly.
Process.Start(rcBinaryPath, $"-mode Unattended -requester \"{requesterID}\" -serviceid \"{serviceID}\" -deviceid {ConnectionInfo.DeviceID} -host {ConnectionInfo.Host} -relaunch true -viewers {String.Join(",", viewerIDs)}");
}
else
if (WindowsIdentity.GetCurrent().IsSystem)
{

// Give a little time for session changing, etc.
await Task.Delay(1000);

Expand All @@ -137,6 +131,12 @@ public async Task RestartScreenCaster(List<string> viewerIDs, string serviceID,
await hubConnection.SendAsync("DisplayMessage", "Remote control failed to start on target device.", "Failed to start remote control.", requesterID);
}
}
else
{
// SignalR Connection IDs might start with a hyphen. We surround them
// with quotes so the command line will be parsed correctly.
Process.Start(rcBinaryPath, $"-mode Unattended -requester \"{requesterID}\" -serviceid \"{serviceID}\" -deviceid {ConnectionInfo.DeviceID} -host {ConnectionInfo.Host} -relaunch true -viewers {String.Join(",", viewerIDs)}");
}
}
catch (Exception ex)
{
Expand Down
12 changes: 6 additions & 6 deletions Desktop.Core/Desktop.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.7" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.1.7" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.9" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.1.9" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.7" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.7" />
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="3.1.7" />
<PackageReference Include="Microsoft.MixedReality.WebRTC" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="3.1.9" />
<PackageReference Include="Microsoft.MixedReality.WebRTC" Version="2.0.2" />
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="4.7.0" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Desktop.Win/Desktop.Win.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.MixedReality.WebRTC" Version="2.0.0" />
<PackageReference Include="Microsoft.MixedReality.WebRTC" Version="2.0.2" />
<PackageReference Include="NAudio" Version="1.10.0" />
<PackageReference Include="SharpDX" Version="4.2.0" />
<PackageReference Include="SharpDX.Direct3D11" Version="4.2.0" />
Expand Down
17 changes: 13 additions & 4 deletions Desktop.Win/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Win32;
using Remotely.Desktop.Core;
using Remotely.Desktop.Core.Interfaces;
using Remotely.Desktop.Core.Services;
using Remotely.Desktop.Win.Services;
using Remotely.Desktop.Win.Views;
using Remotely.Shared.Helpers;
using Remotely.Shared.Models;
using Remotely.Shared.Utilities;
using Remotely.Shared.Win32;
Expand Down Expand Up @@ -46,6 +48,14 @@ public static async Task Main(string[] args)
CasterSocket = Services.GetRequiredService<CasterSocket>();
Conductor.ProcessArgs(args);

SystemEvents.SessionEnding += async (s, e) =>
{
if (e.Reason == SessionEndReasons.SystemShutdown)
{
await CasterSocket.DisconnectAllViewers();
}
};

if (Conductor.Mode == Core.Enums.AppMode.Chat)
{
StartUiThreads(null);
Expand All @@ -69,10 +79,9 @@ await Task.Run(async () =>
StartUiThreads(() => new MainWindow());
}

while (!App.Current.Dispatcher.HasShutdownFinished)
{
Thread.Sleep(1000);
}
TaskHelper.DelayUntil(() => App.Current.Dispatcher.HasShutdownStarted,
TimeSpan.MaxValue,
1000);
}
catch (Exception ex)
{
Expand Down
20 changes: 10 additions & 10 deletions Server/Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@


<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.7" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.7" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.7" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.1.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.7">
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.9" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.9" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.9" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.7" />
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="3.1.7" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="3.1.9" />
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="4.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" PrivateAssets="All" />
<PackageReference Include="NETStandard.Library" Version="2.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Shared/Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="3.1.7" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="3.1.9" />
<PackageReference Include="Microsoft.Management.Infrastructure" Version="2.0.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
<PackageReference Include="System.Text.Json" Version="4.7.2" />
Expand Down
2 changes: 1 addition & 1 deletion Tests.LoadTester/Tests.LoadTester.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.7" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.9" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.9" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
Expand Down

0 comments on commit 7eb11ea

Please sign in to comment.