Skip to content

Remove use of wmic#1981

Open
bwitt wants to merge 1 commit into
voxpupuli:masterfrom
bwitt:deprecate-wmic
Open

Remove use of wmic#1981
bwitt wants to merge 1 commit into
voxpupuli:masterfrom
bwitt:deprecate-wmic

Conversation

@bwitt

@bwitt bwitt commented Jan 4, 2026

Copy link
Copy Markdown
Contributor

Remove use of wmic for Windows since it's deprecated or removed on newer versions.

Fixes #1959

ips = execute("wmic nicconfig where ipenabled=true GET IPAddress /format:list")

ip = ''
ips.each_line do |line|

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thoughts about:

def get_ip
  ips = execute('...')
  ips.lines.map(&:strip).find { |line| Resolv::IPv4::Regex.match?(line) } || ''
end

Comment on lines 6 to 12
groups = []
result.stdout.each_line do |line|
groups << (line.match(/^Name=(.+)$/) or next)[1]
group = line.strip
next if group.empty?

groups << group
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about:

groups = result.stdout.lines.map(&:strip).reject(&:empty?)

This is also a repeated pattern in other files we can use to simplify the parsing.

# IPAddress=
# IPAddress={"129.168.0.1"}
# IPAddress={"192.168.0.1","2001:db8:aaaa:bbbb:cccc:dddd:eeee:0001"}
ips = execute('powershell.exe -NoProfile -NonInteractive -Command "(Get-CimInstance Win32_NetworkAdapterConfiguration -Filter \'IPEnabled=True\' | ForEach-Object { $_.IPAddress })"')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My understanding of the exec implementation is that it's the non-PowerShell implementation so can we really count on powershell.exe being present? If we can, is there any reason the user should even use this implementation or can we deprecate it altogether?

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.

WMIC is deprecated

2 participants