5
5
6
6
use async_trait:: async_trait;
7
7
use shell_escape:: windows:: escape as shell_escape;
8
+ use std:: os:: windows:: process:: CommandExt ;
8
9
use std:: {
9
10
path:: PathBuf ,
10
11
process:: { Command , Stdio } ,
11
12
} ;
13
+ use winapi:: um:: winbase:: { CREATE_NEW_PROCESS_GROUP , DETACHED_PROCESS } ;
12
14
use winreg:: { enums:: HKEY_CURRENT_USER , RegKey } ;
13
15
14
16
use crate :: {
@@ -21,6 +23,8 @@ use crate::{
21
23
22
24
use super :: service:: { tail_log_file, ServiceContainer , ServiceManager as CliServiceManager } ;
23
25
26
+ const DID_LAUNCH_AS_HIDDEN_PROCESS : & str = "VSCODE_CLI_DID_LAUNCH_AS_HIDDEN_PROCESS" ;
27
+
24
28
pub struct WindowsService {
25
29
log : log:: Logger ,
26
30
tunnel_lock : PathBuf ,
@@ -90,7 +94,24 @@ impl CliServiceManager for WindowsService {
90
94
launcher_paths : LauncherPaths ,
91
95
mut handle : impl ' static + ServiceContainer ,
92
96
) -> Result < ( ) , AnyError > {
93
- handle. run_service ( self . log , launcher_paths) . await
97
+ if std:: env:: var ( DID_LAUNCH_AS_HIDDEN_PROCESS ) . is_ok ( ) {
98
+ return handle. run_service ( self . log , launcher_paths) . await ;
99
+ }
100
+
101
+ // Start as a hidden subprocess to avoid showing cmd.exe on startup.
102
+ // Fixes https://github.com/microsoft/vscode/issues/184058
103
+ // I also tried the winapi ShowWindow, but that didn't yield fruit.
104
+ Command :: new ( std:: env:: current_exe ( ) . unwrap ( ) )
105
+ . args ( std:: env:: args ( ) . skip ( 1 ) )
106
+ . env ( DID_LAUNCH_AS_HIDDEN_PROCESS , "1" )
107
+ . stderr ( Stdio :: null ( ) )
108
+ . stdout ( Stdio :: null ( ) )
109
+ . stdin ( Stdio :: null ( ) )
110
+ . creation_flags ( CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS )
111
+ . spawn ( )
112
+ . map_err ( |e| wrap ( e, "error starting nested process" ) ) ?;
113
+
114
+ Ok ( ( ) )
94
115
}
95
116
96
117
async fn unregister ( & self ) -> Result < ( ) , AnyError > {
0 commit comments