module Hiera::Util::Win32

Constants

COMMON_APPDATA
MAX_PATH
S_OK

Public Class Methods

get_common_appdata() click to toggle source
# File lib/hiera/util/win32.rb, line 30
def self.get_common_appdata
  # null terminated MAX_PATH string in wchar (i.e. 2 bytes per char)
  buffer = 0.chr * ((MAX_PATH + 1) * 2)
  result = SHGetFolderPathW(0, COMMON_APPDATA, 0, 0, buffer)
  raise "Could not find COMMON_APPDATA path - HRESULT: #{result}" unless result == S_OK
  buffer.force_encoding(Encoding::UTF_16LE).encode(Encoding::UTF_8).strip
end