Fix elevate desktop app.

This commit is contained in:
Jared Goodwin 2020-04-24 08:12:20 -07:00
parent 76d13e124a
commit 4e443833ce
7 changed files with 51 additions and 19 deletions

View File

@ -154,7 +154,9 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>if $(ConfigurationName) == Debug (
echo &gt; $(ProjectDir)Remotely_Desktop.zip
if not exist "$(ProjectDir)Remotely_Desktop.zip" (
echo &gt; $(ProjectDir)Remotely_Desktop.zip
)
)</PreBuildEvent>
</PropertyGroup>
</Project>

View File

@ -25,15 +25,15 @@ namespace Remotely.Desktop.Win
{
if (Environment.GetCommandLineArgs().Contains("-elevate"))
{
var filePath = Process.GetCurrentProcess().MainModule.FileName;
var commandLine = Win32Interop.GetCommandLine().Replace(" -elevate", "");
Logger.Write($"Elevating process {filePath}.");
Logger.Write($"Elevating process {commandLine}.");
var result = Win32Interop.OpenInteractiveProcess(
filePath,
commandLine,
-1,
false,
"default",
false,
true,
out var procInfo);
Logger.Write($"Elevate result: {result}. Process ID: {procInfo.dwProcessId}.");
Environment.Exit(0);

View File

@ -97,9 +97,9 @@
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="Change Server" Command="{Binding Path=ChangeServerCommand, Source={x:Static ViewModels:MainWindowViewModel.Current}}"></MenuItem>
<!-- Might bring these back some day if I stop using the .NET Framework wrapper. -->
<!--<MenuItem Header="Elevate to Admin" Command="{Binding Path=ElevateToAdminCommand, Source={x:Static ViewModels:MainWindowViewModel.Current}}"></MenuItem>-->
<!--<MenuItem Header="Elevate to Service" Command="{Binding Path=ElevateToServiceCommand, Source={x:Static ViewModels:MainWindowViewModel.Current}}"></MenuItem>-->
<MenuItem Header="Elevate to Admin" Command="{Binding Path=ElevateToAdminCommand, Source={x:Static ViewModels:MainWindowViewModel.Current}}"></MenuItem>
<MenuItem Header="Elevate to Service" Command="{Binding Path=ElevateToServiceCommand, Source={x:Static ViewModels:MainWindowViewModel.Current}}"></MenuItem>
</ContextMenu>
</Button.ContextMenu>
<Rectangle Fill="{StaticResource GearBrush}"></Rectangle>

View File

@ -72,11 +72,16 @@ namespace Remotely.Desktop.Win.ViewModels
{
try
{
var filePath = Process.GetCurrentProcess().MainModule.FileName;
var psi = new ProcessStartInfo(filePath)
//var filePath = Process.GetCurrentProcess().MainModule.FileName;
var commandLine = Win32Interop.GetCommandLine().Replace(" -elevate", "");
var sections = commandLine.Split('"', StringSplitOptions.RemoveEmptyEntries);
var filePath = sections.First();
var arguments = string.Join('"', sections.Skip(1));
var psi = new ProcessStartInfo(filePath, arguments)
{
Verb = "RunAs",
UseShellExecute = true
UseShellExecute = true,
WindowStyle = ProcessWindowStyle.Hidden
};
Process.Start(psi);
Environment.Exit(0);
@ -103,9 +108,13 @@ namespace Remotely.Desktop.Win.ViewModels
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true
};
var filePath = Process.GetCurrentProcess().MainModule.FileName;
Logger.Write($"Creating temporary service with file path {filePath}.");
psi.Arguments = $"/c sc create Remotely_Temp binPath=\"{filePath} -elevate\"";
//var filePath = Process.GetCurrentProcess().MainModule.FileName;
var commandLine = Win32Interop.GetCommandLine().Replace(" -elevate", "");
var sections = commandLine.Split('"', StringSplitOptions.RemoveEmptyEntries);
var filePath = sections.First();
var arguments = string.Join('"', sections.Skip(1));
Logger.Write($"Creating temporary service with file path {filePath} and arguments {arguments}.");
psi.Arguments = $"/c sc create Remotely_Temp binPath=\"{filePath} {arguments} -elevate\"";
Process.Start(psi).WaitForExit();
psi.Arguments = "/c sc start Remotely_Temp";
Process.Start(psi).WaitForExit();

View File

@ -2,12 +2,23 @@ export const Sound = new class {
constructor() {
this.AudioElements = new Array();
this.SourceNodes = new Array();
this.Context = new AudioContext();
if (AudioContext) {
this.Context = new AudioContext();
}
else if (window["webkitAudioContext"]) {
this.Context = new window["webkitAudioContext"];
}
else {
return;
}
this.BackgroundAudio = new Audio();
this.BackgroundNode = this.Context.createMediaElementSource(this.BackgroundAudio);
this.BackgroundNode.connect(this.Context.destination);
}
Play(buffer) {
if (!this.Context) {
return;
}
var fr = new FileReader();
fr.onload = async (ev) => {
var audioBuffer = await this.Context.decodeAudioData(fr.result);

View File

@ -1 +1 @@
{"version":3,"file":"Sound.js","sourceRoot":"","sources":["Sound.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,KAAK,GAAG,IAAI;IACrB;QAOA,kBAAa,GAA4B,IAAI,KAAK,EAAoB,CAAC;QACvE,gBAAW,GAAuC,IAAI,KAAK,EAA+B,CAAC;QAPvF,IAAI,CAAC,OAAO,GAAG,IAAI,YAAY,EAAE,CAAC;QAClC,IAAI,CAAC,eAAe,GAAG,IAAI,KAAK,EAAE,CAAC;QACnC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,wBAAwB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAClF,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC1D,CAAC;IAQD,IAAI,CAAC,MAAkB;QAEnB,IAAI,EAAE,GAAG,IAAI,UAAU,EAAE,CAAC;QAC1B,EAAE,CAAC,MAAM,GAAG,KAAK,EAAE,EAAE,EAAE,EAAE;YACrB,IAAI,WAAW,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC,MAAqB,CAAC,CAAC;YAC/E,IAAI,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC;YACrD,YAAY,CAAC,MAAM,GAAG,WAAW,CAAC;YAClC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YAC/C,YAAY,CAAC,KAAK,EAAE,CAAC;QACzB,CAAC,CAAA;QAED,EAAE,CAAC,iBAAiB,CAAC,IAAI,IAAI,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC,CA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AAA;QAED,EAAE,CAAC,iBAAiB,CAAC,IAAI,IAAI,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;IACtE,CAAC;IAAA,CAAC;CACL,CAAA"}

View File

@ -1,8 +1,15 @@
import { RemoveFromArray } from "./Utilities.js";

export const Sound = new class {
constructor() {
this.Context = new AudioContext();
if (AudioContext) {
this.Context = new AudioContext();
}
else if (window["webkitAudioContext"]) {
this.Context = new window["webkitAudioContext"];
}
else {
return;
}
this.BackgroundAudio = new Audio();
this.BackgroundNode = this.Context.createMediaElementSource(this.BackgroundAudio);
this.BackgroundNode.connect(this.Context.destination);
@ -15,6 +22,9 @@ export const Sound = new class {
BackgroundNode: MediaElementAudioSourceNode;
Play(buffer: Uint8Array) {
if (!this.Context) {
return;
}
var fr = new FileReader();
fr.onload = async (ev) => {