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

Conversation

Nerdsie
Copy link
Contributor

@Nerdsie Nerdsie commented Nov 9, 2021

WMIC is deprecated, and even removed on Windows 11 dev (not sure about beta/release)

@junlarsen junlarsen self-assigned this Nov 9, 2021
@junlarsen
Copy link
Owner

junlarsen commented Nov 10, 2021

Have you tested this locally yourself? I pulled it down myself, and none of the tests are passing out of the box on my machine.

E: My system complains that Get-CimInstance isn't a recognized cmdlet in path, which means it's not executing in PowerShell. Passing { shell: 'powershell' } as the second argument to exec solves this for users whose default shell is not PowerShell.

Copy link
Owner

@junlarsen junlarsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for the patch (and the heads up about WMIC)! It's greatly appreciated.

I've tested it locally, and I'll be happy to accept the patch with the following changes:

diff --git src/authentication.ts src/authentication.ts
index 72d83d2..99ef778 100644
--- src/authentication.ts
+++ src/authentication.ts
@@ -110,7 +110,7 @@ export async function authenticate(options?: AuthenticationOptions): Promise<Cre
         : `ps x -o args | grep '${name}'`
 
     try {
-      const { stdout } = await exec(command)
+      const { stdout } = await exec(command, { shell: 'powershell' })
       const [, port] = stdout.match(portRegex)!
       const [, password] = stdout.match(passwordRegex)!
       const [, pid] = stdout.match(pidRegex)!

@Nerdsie
Copy link
Contributor Author

Nerdsie commented Nov 11, 2021

My bad for not testing locally

Thank you so much for the patch (and the heads up about WMIC)! It's greatly appreciated.

I've tested it locally, and I'll be happy to accept the patch with the following changes:

diff --git src/authentication.ts src/authentication.ts
index 72d83d2..99ef778 100644
--- src/authentication.ts
+++ src/authentication.ts
@@ -110,7 +110,7 @@ export async function authenticate(options?: AuthenticationOptions): Promise<Cre
         : `ps x -o args | grep '${name}'`
 
     try {
-      const { stdout } = await exec(command)
+      const { stdout } = await exec(command, { shell: 'powershell' })
       const [, port] = stdout.match(portRegex)!
       const [, password] = stdout.match(passwordRegex)!
       const [, pid] = stdout.match(pidRegex)!

Is this going to cause issues with non windows systems? Maybe a better option would be something like

const args =
      process.platform === 'win32'
        ? [`Get-CimInstance -Query "SELECT * from Win32_Process WHERE name LIKE '${name}.exe'" | Select-Object CommandLine | fl`, { shell: 'powershell' }]
        : [`ps x -o args | grep '${name}'`]

...

const { stdout } = await exec(...args)

@junlarsen
Copy link
Owner

Is this going to cause issues with non windows systems? Maybe a better option would be something like

const args =
      process.platform === 'win32'
        ? [`Get-CimInstance -Query "SELECT * from Win32_Process WHERE name LIKE '${name}.exe'" | Select-Object CommandLine | fl`, { shell: 'powershell' }]
        : [`ps x -o args | grep '${name}'`]

...

const { stdout } = await exec(...args)

Oh you're right about that, I believe a solution like you've proposed here is better. Thanks!

@junlarsen
Copy link
Owner

junlarsen commented Nov 18, 2021

Hi, any updates on this? Looking forward to merging it!

WMIC is deprecated, and even removed on Windows 11 dev (not sure about beta/release)
@Nerdsie
Copy link
Contributor Author

Nerdsie commented Nov 21, 2021

Hi, any updates on this? Looking forward to merging it!

Sorry, was busy with work. Just pushed changes, not exactly what I had in my comment because type issues were wonky. Is there a better way to run tests than running jest manually from cli? Seems like there should be a "test" package.json script

@junlarsen
Copy link
Owner

junlarsen commented Nov 22, 2021

Sorry, was busy with work. Just pushed changes, not exactly what I had in my comment because type issues were wonky. Is there a better way to run tests than running jest manually from cli? Seems like there should be a "test" package.json script

Again, thank you so much for the changes. And yes, you're right, I should totally have a test package.json script for this, will add one.

E: Looks like I had a change for exactly that locally, pushed to master in a901c14

@junlarsen junlarsen merged commit bd5eb76 into junlarsen:master Nov 22, 2021
@junlarsen
Copy link
Owner

Thank you so much for your work, I've released 5.3.1 with your patch https://www.npmjs.com/package/league-connect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants