mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
60 lines
2.1 KiB
C#
60 lines
2.1 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using Remotely.Desktop.Win.Services;
|
|
using Remotely.Desktop.Win.ViewModels;
|
|
using Remotely.ScreenCast.Core;
|
|
using Remotely.ScreenCast.Core.Services;
|
|
using Remotely.Shared.Win32;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace Remotely.Desktop.Win
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for App.xaml
|
|
/// </summary>
|
|
public partial class App : Application
|
|
{
|
|
private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
|
|
{
|
|
Logger.Write(e.Exception);
|
|
MessageBox.Show("There was an unhandled exception.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
e.Handled = true;
|
|
}
|
|
|
|
private void Application_Startup(object sender, StartupEventArgs e)
|
|
{
|
|
if (Environment.GetCommandLineArgs().Contains("-elevate"))
|
|
{
|
|
var commandLine = Win32Interop.GetCommandLine().Replace(" -elevate", "").Replace("\"", "");
|
|
|
|
Logger.Write($"Elevating process {commandLine}.");
|
|
var result = Win32Interop.OpenInteractiveProcess(
|
|
commandLine,
|
|
"default",
|
|
false,
|
|
out var procInfo);
|
|
Logger.Write($"Elevate result: {result}. Process ID: {procInfo.dwProcessId}.");
|
|
Environment.Exit(0);
|
|
}
|
|
}
|
|
|
|
private void Application_Exit(object sender, ExitEventArgs e)
|
|
{
|
|
var conductor = ServiceContainer.Instance.GetService<Conductor>();
|
|
foreach (var viewer in conductor.Viewers.Values)
|
|
{
|
|
viewer.DisconnectRequested = true;
|
|
conductor.InvokeViewerRemoved(viewer.ViewerConnectionID);
|
|
}
|
|
System.Windows.Forms.Application.Exit();
|
|
Environment.Exit(0);
|
|
}
|
|
}
|
|
}
|