Skip to content

Commit be20e09

Browse files
committed
Add support for existing-chrome on Windows
1 parent d29fcee commit be20e09

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/util.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,36 @@ export async function listRunningProcesses(): Promise<Array<Proc>> {
134134

135135
return processes;
136136
} else {
137-
throw new Error("Windows not yet supported");
137+
const wmicOutput = await spawnToResult('wmic', [
138+
'Process', 'Get', 'processid,commandline'
139+
]);
140+
141+
if (wmicOutput.exitCode !== 0) {
142+
throw new Error(`WMIC exited with unexpected error code ${wmicOutput.exitCode}`);
143+
}
144+
145+
return getOutputLines(wmicOutput.stdout)
146+
.slice(1) // Skip the header line
147+
.filter((line) => line.includes(' ')) // Skip lines where the command line isn't available (just pids)
148+
.map((line) => {
149+
const pidIndex = line.lastIndexOf(' ') + 1;
150+
const pid = parseInt(line.substring(pidIndex), 10);
151+
152+
const command = line.substring(0, pidIndex).trim();
153+
const bin = command[0] === '"'
154+
? command.substring(1, command.substring(1).indexOf('"') + 1)
155+
: command.substring(0, command.indexOf(' '));
156+
const args = command[0] === '"'
157+
? command.substring(bin.length + 3)
158+
: command.substring(bin.length + 1);
159+
160+
return {
161+
pid,
162+
command,
163+
bin,
164+
args
165+
};
166+
});
138167
}
139168
}
140169

0 commit comments

Comments
 (0)