Skip to content

Commit bf3e158

Browse files
committed
Return status code from elevated command
1 parent 03f1a22 commit bf3e158

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

NodeSwap/Commands/UseCommand.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ public int Run()
6464
if (!IsAdministrator())
6565
{
6666
// Restart the application with elevated privileges
67-
ElevateApplication();
68-
return 1;
67+
return ElevateApplication();
6968
}
7069

7170
//
@@ -111,7 +110,7 @@ private static bool IsAdministrator()
111110
return principal.IsInRole(WindowsBuiltInRole.Administrator);
112111
}
113112

114-
private static void ElevateApplication()
113+
private static int ElevateApplication()
115114
{
116115
var currentProcessModule = Process.GetCurrentProcess().MainModule;
117116
if (currentProcessModule == null) throw new Exception("Unable to get the current process module");
@@ -130,10 +129,13 @@ private static void ElevateApplication()
130129
try
131130
{
132131
process.Start();
132+
process.WaitForExit();
133+
return process.ExitCode;
133134
}
134135
catch (Exception ex)
135136
{
136137
Console.Error.WriteLine("Could not restart as Administrator: " + ex.Message);
138+
return 1;
137139
}
138140
}
139141

NodeSwap/NodeSwap.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net8.0-windows</TargetFramework>
66
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
7-
<Version>1.4.1</Version>
7+
<Version>1.4.2</Version>
88
<!-- Single file app – https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file -->
99
<PublishSingleFile>true</PublishSingleFile>
1010
<RuntimeIdentifier>win-x64</RuntimeIdentifier>

0 commit comments

Comments
 (0)