Module: Facter::Util::Windows::Dir

Extended by:
FFI::Library
Defined in:
lib/facter/util/windows/dir.rb

Constant Summary collapse

COMMON_APPDATA =
0x0023
S_OK =
0x0
MAX_PATH =
260

Class Method Summary collapse

Class Method Details

.get_common_appdataObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/facter/util/windows/dir.rb', line 11

def get_common_appdata
  common_appdata = ''

  # this pointer actually points to a :lpwstr (pointer) since we're letting Windows allocate for us
  FFI::MemoryPointer.new(:pointer, ((MAX_PATH + 1) * 2)) do |buffer_ptr|
    # hwndOwner, nFolder, hToken, dwFlags, pszPath
    if SHGetFolderPathW(0, COMMON_APPDATA, 0, 0, buffer_ptr) != S_OK
      raise Facter::Util::Windows::Error.new("Could not find COMMON_APPDATA path")
    end

    common_appdata = Facter::Util::Windows::FFI.read_arbitrary_wide_string_up_to(buffer_ptr, MAX_PATH + 1)
  end

  common_appdata
end