Skip to content

Commit

Permalink
Fix elevate desktop app.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Apr 24, 2020
1 parent da80114 commit aedef74
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 19 deletions.
4 changes: 3 additions & 1 deletion Desktop.Win.Wrapper/Desktop.Win.Wrapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
8 changes: 4 additions & 4 deletions Desktop.Win/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ private void Application_Startup(object sender, StartupEventArgs e)
{
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);
Expand Down
6 changes: 3 additions & 3 deletions Desktop.Win/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
21 changes: 15 additions & 6 deletions Desktop.Win/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,16 @@ public ICommand ElevateToAdminCommand
{
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);
Expand All @@ -103,9 +108,13 @@ public ICommand ElevateToServiceCommand
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();
Expand Down
13 changes: 12 additions & 1 deletion Server/wwwroot/scripts/Sound.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Server/wwwroot/scripts/Sound.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions Server/wwwroot/scripts/Sound.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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) => {
Expand Down

0 comments on commit aedef74

Please sign in to comment.