Repository navigation
wmic removal #1721 - #1722
Open
Alexander Gottwald (ago1024) wants to merge 2 commits into
Open
wmic removal #1721#1722Alexander Gottwald (ago1024) wants to merge 2 commits into
Alexander Gottwald (ago1024) wants to merge 2 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Author
|
@microsoft-github-policy-service agree |
| proc = spawn(wmic, [ 'process', 'get', 'CommandLine,CreationDate,ParentProcessId,ProcessId' ]); | ||
| const command = 'Get-CimInstance Win32_Process | ForEach-Object { "$($_.CommandLine) $($_.ParentProcessId) $($_.ProcessId)" }'; | ||
| const powershell = join(process.env['WINDIR'] || 'C:\\Windows', 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe'); | ||
| proc = spawn(powershell, [ '-Command', command ]); |
Contributor
There was a problem hiding this comment.
Please keep this background query independent of user profiles and prevent interactive prompts:
Suggested change
| proc = spawn(powershell, [ '-Command', command ]); | |
| proc = spawn(powershell, [ '-NoLogo', '-NoProfile', '-NonInteractive', '-Command', command ], { windowsHide: true }); |
|
|
||
| const wmic = join(process.env['WINDIR'] || 'C:\\Windows', 'System32', 'wbem', 'WMIC.exe'); | ||
| proc = spawn(wmic, [ 'process', 'get', 'CommandLine,CreationDate,ParentProcessId,ProcessId' ]); | ||
| const command = 'Get-CimInstance Win32_Process | ForEach-Object { "$($_.CommandLine) $($_.ParentProcessId) $($_.ProcessId)" }'; |
Contributor
There was a problem hiding this comment.
Please make stdout UTF-8 before decoding it as UTF-8. This keeps already-UTF-8 constrained sessions working and reports a port-attach workaround when policy prevents changing the encoding:
Suggested change
| const command = 'Get-CimInstance Win32_Process | ForEach-Object { "$($_.CommandLine) $($_.ParentProcessId) $($_.ProcessId)" }'; | |
| const command = ` | |
| $ErrorActionPreference = 'Stop' | |
| if ([Console]::OutputEncoding.CodePage -ne 65001) { | |
| if ($ExecutionContext.SessionState.LanguageMode -ne 'FullLanguage') { | |
| throw 'UTF-8 process discovery is restricted by policy. Attach using hostName and port instead.' | |
| } | |
| [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 | |
| } | |
| Get-CimInstance Win32_Process | ForEach-Object { "$($_.CommandLine) $($_.ParentProcessId) $($_.ProcessId)" } | |
| `; |
Contributor
|
Alexander Gottwald (@ago1024) Thanks for submitting the PR! I left two inline suggestions for the PowerShell invocation and output encoding. Please take a look when you have a chance. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The PR replaces the call to wmic.exe with a call to powershell Get-CimInstance Win32_process.
The output of the script is similar to the old wmic output. CreationDate was omited because it's not used anywhere and the old parsing logic to parse the date does not work with the input from the script.