Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace depricated WMIC with Get-CimInstance #54

Merged
merged 1 commit into from
Nov 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,20 @@ export async function authenticate(options?: AuthenticationOptions): Promise<Cre
const portRegex = /--app-port=([0-9]+)/
const passwordRegex = /--remoting-auth-token=([\w-_]+)/
const pidRegex = /--app-pid=([0-9]+)/
const isWindows = process.platform === 'win32';

const command =
process.platform === 'win32'
? `WMIC PROCESS WHERE name='${name}.exe' GET CommandLine`
isWindows
? `Get-CimInstance -Query "SELECT * from Win32_Process WHERE name LIKE '${name}.exe'" | Select-Object CommandLine | fl`
: `ps x -o args | grep '${name}'`

const execOptions =
isWindows
? { shell: 'powershell' }
: { }

try {
const { stdout } = await exec(command)
const { stdout } = await exec(command, execOptions)
const [, port] = stdout.match(portRegex)!
const [, password] = stdout.match(passwordRegex)!
const [, pid] = stdout.match(pidRegex)!
Expand Down