Find computer uuid
-
I would like to find motherboard UUID. I almost did, but in Windows SU2014 I must use
...force_encoding("utf-16le")...
I don't know why and the worst, now one SU2014 Windows user is reporting:
Error: #<ArgumentError: unknown encoding name - utf-16le>
Someone have an idea about why sometimes not work in Windows, or have a best method to find UUID?
Code to find UUID:
MAC OS:
uuid = %x(ioreg -l | awk '/IOPlatformSerialNumber/ { print }')
WIN:
#RUBY_VERSION 1.8
cmd="wmic csproduct get uuid" uuid = %x(#{cmd})#RUBY_VERSION 2.0 (workaround to fix the backquotes bug included):
cmd="wmic csproduct get uuid" filename = ENV["TMP"].encode("utf-8") + "\\backquote.out" exec_string = "" + cmd + " > " + filename + "" exec_string.gsub! '\\', '/' eval("#{exec_string}") contents = File.read(filename) uuid= contents.force_encoding("utf-16le").encode('UTF-8') uuid.slice!(0) -
Thanks to Driven and Dan.
I will use new notation instead use force_encoding. I think now it should works...#UUID in RUBY 2.0 WINDOWS
` cmd="wmic csproduct get uuid"
filename = File.join(ENV["TMP"],"backquote.out")exec_string = "`" + cmd + " > " + filename + "`" exec_string.gsub! '\\', '/' eval("#{exec_string}") uuid="" open(filename, "r:BOM|utf-16le:UTF-8") do |io| uuid = io.read end`
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement