@@ -597,26 +597,45 @@ export class DeepnoteServerStarter implements IDeepnoteServerStarter, IExtension
597597 const processService = await this . processServiceFactory . create ( undefined ) ;
598598
599599 if ( process . platform === 'win32' ) {
600- // Windows: use wmic to get command line
601- const result = await processService . exec (
602- 'wmic' ,
603- [ 'process' , 'where' , `ProcessId=${ pid } ` , 'get' , 'CommandLine' ] ,
604- { throwOnStdErr : false }
605- ) ;
606- if ( result . stdout ) {
607- const cmdLine = result . stdout . toLowerCase ( ) ;
608- // Check if it's running from our deepnote-venvs directory or is deepnote_toolkit
609- return cmdLine . includes ( 'deepnote-venvs' ) || cmdLine . includes ( 'deepnote_toolkit' ) ;
600+ // Windows: prefer PowerShell CIM, fallback to WMIC
601+ let cmdLine = '' ;
602+ try {
603+ const ps = await processService . exec (
604+ 'powershell.exe' ,
605+ [
606+ '-NoProfile' ,
607+ '-Command' ,
608+ `(Get-CimInstance Win32_Process -Filter "ProcessId=${ pid } ").CommandLine`
609+ ] ,
610+ { throwOnStdErr : false }
611+ ) ;
612+ cmdLine = ( ps . stdout || '' ) . toLowerCase ( ) ;
613+ } catch {
614+ // Ignore PowerShell errors, will fallback to WMIC
615+ }
616+ if ( ! cmdLine ) {
617+ const result = await processService . exec (
618+ 'wmic' ,
619+ [ 'process' , 'where' , `ProcessId=${ pid } ` , 'get' , 'CommandLine' ] ,
620+ { throwOnStdErr : false }
621+ ) ;
622+ cmdLine = ( result . stdout || '' ) . toLowerCase ( ) ;
623+ }
624+ if ( cmdLine ) {
625+ // Use regex to match path separators for more robust detection
626+ const inVenv = / [ \\ / ] ( d e e p n o t e - v e n v s ) [ \\ / ] / i. test ( cmdLine ) ;
627+ return inVenv || cmdLine . includes ( 'deepnote_toolkit' ) ;
610628 }
611629 } else {
612- // Unix-like: use ps to get command line
613- const result = await processService . exec ( 'ps' , [ '-p' , pid . toString ( ) , '-o' , 'command=' ] , {
630+ // Unix-like: use ps with -ww to avoid truncation of long command lines
631+ const result = await processService . exec ( 'ps' , [ '-ww' , '- p', pid . toString ( ) , '-o' , 'command=' ] , {
614632 throwOnStdErr : false
615633 } ) ;
616634 if ( result . stdout ) {
617635 const cmdLine = result . stdout . toLowerCase ( ) ;
618- // Check if it's running from our deepnote-venvs directory or is deepnote_toolkit
619- return cmdLine . includes ( 'deepnote-venvs' ) || cmdLine . includes ( 'deepnote_toolkit' ) ;
636+ // Use regex to match path separators for more robust detection
637+ const inVenv = / [ \\ / ] ( d e e p n o t e - v e n v s ) [ \\ / ] / i. test ( cmdLine ) ;
638+ return inVenv || cmdLine . includes ( 'deepnote_toolkit' ) ;
620639 }
621640 }
622641 } catch ( ex ) {
0 commit comments