@@ -211,20 +211,22 @@ function guessEditor() {
211211 }
212212 }
213213 else if ( process . platform === "win32" ) {
214- // Some processes need elevated rights to get its executable path.
215- // Just filter them out upfront. This also saves 10-20ms on the command.
216214 const output = child_process
217- . execSync (
218- "wmic process where \"executablepath is not null\" get executablepath" ,
219- { stdio : [ "pipe" , "pipe" , "ignore" ] } ,
220- )
215+ . execSync ( "powershell -Command \"Get-Process | Select-Object Path\"" , {
216+ stdio : [ "pipe" , "pipe" , "ignore" ] ,
217+ } )
221218 . toString ( )
222219 const runningProcesses = output . split ( "\r\n" )
223220 for ( let i = 0 ; i < runningProcesses . length ; i ++ ) {
224- const processPath = runningProcesses [ i ] . trim ( )
225- const processName = path . basename ( processPath )
226- if ( COMMON_EDITORS_WIN . indexOf ( processName ) !== - 1 )
227- return [ processPath ]
221+ // `Get-Process` sometimes returns empty lines
222+ if ( ! runningProcesses [ i ] )
223+ continue
224+
225+ const fullProcessPath = runningProcesses [ i ] . trim ( )
226+ const shortProcessName = path . basename ( fullProcessPath )
227+
228+ if ( COMMON_EDITORS_WIN . indexOf ( shortProcessName ) !== - 1 )
229+ return [ fullProcessPath ]
228230 }
229231 }
230232 else if ( process . platform === "linux" ) {
0 commit comments