This wmic csproduct get uuid
command i’m writing in sketchup console it is not printing hardware uuid for windows.How can i find the hardware uuid of windows through the sketchup console.
Shell’ing out to commands has been problematic in recent SU versions. On Windows 10, the following seemed to work:
require 'win32/registry'
key = 'Software\Microsoft\Office\Common\ClientTelemetry'
uuid = ''
begin
Win32::Registry::HKEY_CURRENT_USER.open(key) { |reg| uuid = reg['MotherboardUUID'][/[^{}]+/] }
rescue
end
puts uuid
I’ve never installed an Office version, not sure if this registry key exists on all Windows systems…
It isn’t on my system. I have LibreOffice instead.
This is likely more generic …
def get_computer_system_uuid(testing = false)
require 'win32/registry'
key = 'SYSTEM\HardwareConfig'
uuid = ''
config = ''
hardware = nil
begin
hardware = Win32::Registry::HKEY_LOCAL_MACHINE.open(key)
return '' if hardware.nil?
config = hardware['LastConfig']
rescue => err
puts err.inspect
else
begin
keys = hardware.keys
puts keys.inspect if testing
uuid = config[/[^{}]+/] if keys.include?(config)
rescue => err
puts err.inspect
else
uuid
end
ensure
hardware.close unless hardware.nil?
end
end
Is there a Mac equivalent?
That code didn’t work on my system. I was looking for a value not a key, thanks for finding it. Updated code below:
require 'win32/registry'
hklm = Win32::Registry::HKEY_LOCAL_MACHINE
key = 'SYSTEM\HardwareConfig'
uuid = ''
begin
hklm.open(key) { |reg| uuid = reg['LastConfig'].tr '{}', '' }
rescue
end
puts uuid
On my machine it is both a value ("LastConfig"
of the "SYSTEM\HardwareConfig"
key,) and one of it’s subkeys.
(My machine is a MSI GP63 Leopard 8RE [Baseboard: MS-16P5]. So I imagine that keys and values might vary from OEM to OEM.)
I only have one other config subkey named “Current”, but it seems that there might be other GUID configs. So I added an extra test to be sure that the value (of "LastConfig"
) was there also as a subkey.
Your edition did just find the first GUID key name enclosed in “curlies”.
[You’ve updated to use the "LastConfig"
value, I see.]
... snip ... (no longer pertinent) ...
Can we rely upon that being the one to return ?
EDIT: If there is only one, well yes duh.
![]()
Ok. I’ve got to stop posting while ‘multi-tasking’. I ran
wmic csproduct get uuid
and thought I searched my registry, so I should have found the LastConfig
value, but I didn’t.
Anyway, it’s been a while, but I recall seeing info about a reg key that is a GUID for one’s hardware. Also recall that the key may change if one makes certain hardware changes. The system I’m on now, I’ve never touched, but a previous desktop I upgraded drives, RAM, etc. There was some software that wasn’t happy about that. So, assuming that the value changed, there may be more than one key uuid/GUID for a given system. I think. Hence, I changed the code above to use LastConfig
.
At present, I’m Windows only. Hope to add Ubuntu soon for Ruby work, macOS will maybe come later. Hence, I have no idea. Maybe @qwertyuiop knows?
I’d ask Steve (@slbaumgartner) or John (@john_drivenupthewall) for MacOS stuff.
Perhaps it’s saved into the "config.plist"
file ?
From this post we have the following shell command …
ioreg -ad2 -c IOPlatformExpertDevice | xmllint --xpath '//key[.="IOPlatformUUID"]/following-sibling::*[1]/text()' -
Formats the output from
ioreg
into XML, then parses the XML withxmllint
’s xpath feature.Sample Output:
08E4F05C-349D-4F23-8980-E2C3EA66DA2A
If it works, then the command can be wrapped in guid = %x{}
command string for calling from Ruby.
We could probably use Fiddle to get read only information:
-
Win32_ComputerSystemProduct
class
… which says it gets it’s UUID from … -
SMBIOS UUID field
…which say (interestingly) …The UUID field is not marketed to end users and is
considered the seventh-level indicator of this device.
* “SM” is an acronym for System Management and it’s based upon this standard.
- See: SMBIOS | DMTF
thank you…it’s working
thank you… now i’m able to get hardware uuid
You can run one of the commands given here.
Which I see is also what @DanRathbun cited.
OK here is the cross platform version.
def get_computer_system_uuid(testing = false)
if Sketchup.platform == :platform_osx
`ioreg -ad2 -c IOPlatformExpertDevice | xmllint --xpath '//key[.="IOPlatformUUID"]/following-sibling::*[1]/text()' -`
else
require 'win32/registry'
key = 'SYSTEM\HardwareConfig'
uuid = ''
config = ''
hardware = nil
begin
hardware = Win32::Registry::HKEY_LOCAL_MACHINE.open(key)
return '' if hardware.nil?
config = hardware['LastConfig']
rescue => err
puts err.inspect
else
begin
keys = hardware.keys
puts keys.inspect if testing
uuid = config[/[^{}]+/] if keys.include?(config)
rescue => err
puts err.inspect
else
uuid
end
ensure
hardware.close unless hardware.nil?
end
end
end
Here is a version to get the computer name.
def computer_name
Sketchup.platform == :platform_osx ? `hostname`.split('.')[0] : ENV["COMPUTERNAME"]
end
Oh I now see that there were 3 choices.
I only noticed the one that was elevated to the best “liked” answer.
Added support for windows 7
def computer_system_uuid(testing = false)
if Sketchup.platform == :platform_osx
`ioreg -ad2 -c IOPlatformExpertDevice | xmllint --xpath '//key[.="IOPlatformUUID"]/following-sibling::*[1]/text()' -`
else
require 'win32/registry'
key = 'SYSTEM\HardwareConfig'
uuid = ''
config = ''
hardware = nil
begin
begin
hardware = Win32::Registry::HKEY_LOCAL_MACHINE.open(key)
return '' if hardware.nil?
config = hardware['LastConfig']
rescue StandardError => _e
#windows 7
key = 'SOFTWARE\Microsoft\Cryptography'
hardware = Win32::Registry::HKEY_LOCAL_MACHINE.open(key)
return '' if hardware.nil?
return hardware['MachineGuid']
end
rescue StandardError => e
puts e.inspect
else
begin
keys = hardware.keys
puts keys.inspect if testing
uuid = config[/[^{}]+/] if keys.include?(config)
rescue StandardError => e
puts e.inspect
else
uuid
end
ensure
hardware.close unless hardware.nil?
end
uuid
end
end