@@ -47,11 +47,11 @@ public void Application_Startup(object sender, StartupEventArgs e)
47
47
case 1 when args . Contains ( "--debug" ) :
48
48
{
49
49
if ( args . Contains ( "--debug" ) )
50
- IsDebug = true ;
50
+ IsDebug = true ;
51
51
if ( IsAdministrator ( ) == false )
52
52
{
53
53
ElevateAsAdmin ( ) ;
54
- Environment . Exit ( 0 ) ;
54
+ Environment . Exit ( 740 ) ;
55
55
return ;
56
56
}
57
57
@@ -71,15 +71,15 @@ public void Application_Startup(object sender, StartupEventArgs e)
71
71
if ( IsAdministrator ( ) == false )
72
72
{
73
73
ElevateAsAdmin ( string . Join ( " " , args ) ) ;
74
- Environment . Exit ( 0 ) ;
74
+ Environment . Exit ( 740 ) ;
75
75
return ;
76
76
}
77
77
78
78
// Check if user allowed opening the control panel
79
79
if ( RegistryConfig . GetKey ( "ControlPanelIsInstalled" ) != "True" )
80
80
{
81
81
Logging . Log ( "Control Panel is not allowed on this system, exiting ..." , Logging . LogLevel . ERROR ) ;
82
- Environment . Exit ( 0 ) ;
82
+ Environment . Exit ( 1 ) ;
83
83
return ;
84
84
}
85
85
@@ -111,6 +111,8 @@ public void Application_Startup(object sender, StartupEventArgs e)
111
111
112
112
if ( args . Contains ( "-s" ) ) // Silent Installation
113
113
{
114
+ Configuration . InitialEnvironment ( ) ;
115
+
114
116
foreach ( var arg in args )
115
117
{
116
118
if ( arg . StartsWith ( "-e:" ) )
@@ -146,22 +148,21 @@ public void Application_Startup(object sender, StartupEventArgs e)
146
148
147
149
if ( IsAdministrator ( ) == false )
148
150
{
149
- ElevateAsAdmin ( string . Join ( " " , args ) ) ;
150
- Environment . Exit ( 0 ) ;
151
+ var elevatedProcess = ElevateAndWait ( string . Join ( " " , args ) ) ;
152
+ Environment . Exit ( elevatedProcess ) ;
151
153
return ;
152
154
}
153
155
154
156
Configuration . InstallControlPanel = true ;
155
- Configuration . InitialEnvironment ( ) ;
156
157
var result = InstallRoutine . Install ( null ) ;
157
158
Environment . Exit ( result ) ;
158
159
}
159
160
if ( args . Contains ( "-u" ) )
160
161
{
161
162
if ( IsAdministrator ( ) == false )
162
163
{
163
- ElevateAsAdmin ( string . Join ( " " , args ) ) ;
164
- Environment . Exit ( 0 ) ;
164
+ var elevatedProcess = ElevateAndWait ( string . Join ( " " , args ) ) ;
165
+ Environment . Exit ( elevatedProcess ) ;
165
166
return ;
166
167
}
167
168
var result = InstallRoutine . Uninstall ( null ) ;
@@ -236,7 +237,10 @@ public void Application_Startup(object sender, StartupEventArgs e)
236
237
ifeoMessageUi . ShowDialog ( ) ;
237
238
238
239
if ( ifeoMessageUi . Summary == "Btn1" )
240
+ {
239
241
ElevateAsAdmin ( "--update" ) ;
242
+ Environment . Exit ( 740 ) ;
243
+ }
240
244
241
245
Environment . Exit ( 0 ) ;
242
246
}
@@ -269,6 +273,24 @@ private static void ElevateAsAdmin(string? arguments = null)
269
273
Process . Start ( startInfo ) ;
270
274
}
271
275
276
+ private static int ElevateAndWait ( string ? arguments = null )
277
+ {
278
+ // Restart program and run as admin
279
+ var exeName = Process . GetCurrentProcess ( ) . MainModule ? . FileName ;
280
+ if ( exeName == null ) return - 1 ;
281
+ var startInfo = new ProcessStartInfo ( exeName )
282
+ {
283
+ Verb = "runas" ,
284
+ UseShellExecute = true ,
285
+ Arguments = arguments
286
+ } ;
287
+ var p = new Process ( ) ;
288
+ p . StartInfo = startInfo ;
289
+ p . Start ( ) ;
290
+ p . WaitForExit ( ) ;
291
+ return p . ExitCode ;
292
+ }
293
+
272
294
private static string ? ParseCustomUrl ( string argument , int count )
273
295
{
274
296
var argParsed = argument . Remove ( 0 , count ) ;
0 commit comments