mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
Fixes for elevating WPF app.
This commit is contained in:
parent
e8947cabb9
commit
aff5598c95
@ -47,7 +47,7 @@ namespace Remotely.Desktop.Win
|
||||
{
|
||||
if (Environment.GetCommandLineArgs().Contains("-elevate"))
|
||||
{
|
||||
var commandLine = Win32Interop.GetCommandLine().Replace(" -elevate", "");
|
||||
var commandLine = Win32Interop.GetCommandLine().Replace(" -elevate", "").Replace("\"", "");
|
||||
|
||||
Logger.Write($"Elevating process {commandLine}.");
|
||||
var result = Win32Interop.OpenInteractiveProcess(
|
||||
|
||||
@ -132,7 +132,7 @@ namespace Remotely.Desktop.Win.ViewModels
|
||||
WindowStyle = ProcessWindowStyle.Hidden,
|
||||
CreateNoWindow = true
|
||||
};
|
||||
var commandLine = Win32Interop.GetCommandLine().Replace(" -elevate", "");
|
||||
var commandLine = Win32Interop.GetCommandLine().Replace(" -elevate", "").Replace("\"", "");
|
||||
Logger.Write($"Creating temporary service with command line {commandLine}.");
|
||||
psi.Arguments = $"/c sc create Remotely_Temp binPath=\"{commandLine} -elevate\"";
|
||||
Process.Start(psi).WaitForExit();
|
||||
@ -140,7 +140,7 @@ namespace Remotely.Desktop.Win.ViewModels
|
||||
Process.Start(psi).WaitForExit();
|
||||
psi.Arguments = "/c sc delete Remotely_Temp";
|
||||
Process.Start(psi).WaitForExit();
|
||||
Environment.Exit(0);
|
||||
App.Current.Shutdown();
|
||||
}
|
||||
catch { }
|
||||
}, (param) =>
|
||||
|
||||
@ -26,9 +26,8 @@ namespace Remotely.ScreenCast.Win.Services
|
||||
|
||||
public void SendKeyDown(string key, Viewer viewer)
|
||||
{
|
||||
SendOnStaThread(() =>
|
||||
TryOnInputDesktop(() =>
|
||||
{
|
||||
Win32Interop.SwitchToInputDesktop();
|
||||
var keyCode = ConvertJavaScriptKeyToVirtualKey(key);
|
||||
var union = new InputUnion()
|
||||
{
|
||||
@ -46,11 +45,12 @@ namespace Remotely.ScreenCast.Win.Services
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void SendKeyUp(string key, Viewer viewer)
|
||||
{
|
||||
SendOnStaThread(() =>
|
||||
TryOnInputDesktop(() =>
|
||||
{
|
||||
Win32Interop.SwitchToInputDesktop();
|
||||
var keyCode = ConvertJavaScriptKeyToVirtualKey(key);
|
||||
var union = new InputUnion()
|
||||
{
|
||||
@ -70,9 +70,8 @@ namespace Remotely.ScreenCast.Win.Services
|
||||
|
||||
public void SendLeftMouseDown(double percentX, double percentY, Viewer viewer)
|
||||
{
|
||||
SendOnStaThread(() =>
|
||||
TryOnInputDesktop(() =>
|
||||
{
|
||||
Win32Interop.SwitchToInputDesktop();
|
||||
var xyPercent = GetAbsolutePercentFromRelativePercent(percentX, percentY, viewer.Capturer);
|
||||
// Coordinates must be normalized. The bottom-right coordinate is mapped to 65535.
|
||||
var normalizedX = xyPercent.Item1 * 65535D;
|
||||
@ -85,9 +84,8 @@ namespace Remotely.ScreenCast.Win.Services
|
||||
|
||||
public void SendLeftMouseUp(double percentX, double percentY, Viewer viewer)
|
||||
{
|
||||
SendOnStaThread(() =>
|
||||
TryOnInputDesktop(() =>
|
||||
{
|
||||
Win32Interop.SwitchToInputDesktop();
|
||||
var xyPercent = GetAbsolutePercentFromRelativePercent(percentX, percentY, viewer.Capturer);
|
||||
// Coordinates must be normalized. The bottom-right coordinate is mapped to 65535.
|
||||
var normalizedX = xyPercent.Item1 * 65535D;
|
||||
@ -100,9 +98,8 @@ namespace Remotely.ScreenCast.Win.Services
|
||||
|
||||
public void SendMouseMove(double percentX, double percentY, Viewer viewer)
|
||||
{
|
||||
SendOnStaThread(() =>
|
||||
TryOnInputDesktop(() =>
|
||||
{
|
||||
Win32Interop.SwitchToInputDesktop();
|
||||
var xyPercent = GetAbsolutePercentFromRelativePercent(percentX, percentY, viewer.Capturer);
|
||||
// Coordinates must be normalized. The bottom-right coordinate is mapped to 65535.
|
||||
var normalizedX = xyPercent.Item1 * 65535D;
|
||||
@ -115,9 +112,8 @@ namespace Remotely.ScreenCast.Win.Services
|
||||
|
||||
public void SendMouseWheel(int deltaY, Viewer viewer)
|
||||
{
|
||||
SendOnStaThread(() =>
|
||||
TryOnInputDesktop(() =>
|
||||
{
|
||||
Win32Interop.SwitchToInputDesktop();
|
||||
if (deltaY < 0)
|
||||
{
|
||||
deltaY = -120;
|
||||
@ -134,9 +130,8 @@ namespace Remotely.ScreenCast.Win.Services
|
||||
|
||||
public void SendRightMouseDown(double percentX, double percentY, Viewer viewer)
|
||||
{
|
||||
SendOnStaThread(() =>
|
||||
TryOnInputDesktop(() =>
|
||||
{
|
||||
Win32Interop.SwitchToInputDesktop();
|
||||
var xyPercent = GetAbsolutePercentFromRelativePercent(percentX, percentY, viewer.Capturer);
|
||||
// Coordinates must be normalized. The bottom-right coordinate is mapped to 65535.
|
||||
var normalizedX = xyPercent.Item1 * 65535D;
|
||||
@ -149,9 +144,8 @@ namespace Remotely.ScreenCast.Win.Services
|
||||
|
||||
public void SendRightMouseUp(double percentX, double percentY, Viewer viewer)
|
||||
{
|
||||
SendOnStaThread(() =>
|
||||
TryOnInputDesktop(() =>
|
||||
{
|
||||
Win32Interop.SwitchToInputDesktop();
|
||||
var xyPercent = GetAbsolutePercentFromRelativePercent(percentX, percentY, viewer.Capturer);
|
||||
// Coordinates must be normalized. The bottom-right coordinate is mapped to 65535.
|
||||
var normalizedX = xyPercent.Item1 * 65535D;
|
||||
@ -164,7 +158,7 @@ namespace Remotely.ScreenCast.Win.Services
|
||||
|
||||
public void SendText(string transferText, Viewer viewer)
|
||||
{
|
||||
SendOnStaThread(() =>
|
||||
TryOnInputDesktop(() =>
|
||||
{
|
||||
SendKeys.SendWait(transferText);
|
||||
});
|
||||
@ -292,13 +286,22 @@ namespace Remotely.ScreenCast.Win.Services
|
||||
return keyCode;
|
||||
}
|
||||
|
||||
private void SendOnStaThread(Action sendAction)
|
||||
private void TryOnInputDesktop(Action inputAction)
|
||||
{
|
||||
var thread = new Thread(() => {
|
||||
sendAction();
|
||||
});
|
||||
thread.SetApartmentState(ApartmentState.STA);
|
||||
thread.Start();
|
||||
if (!Win32Interop.SwitchToInputDesktop())
|
||||
{
|
||||
var thread = new Thread(() =>
|
||||
{
|
||||
Win32Interop.SwitchToInputDesktop();
|
||||
inputAction();
|
||||
});
|
||||
thread.SetApartmentState(ApartmentState.STA);
|
||||
thread.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
inputAction();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user