Class: MiqWin32::Services
- Inherits:
-
Object
- Object
- MiqWin32::Services
- Defined in:
- lib/metadata/util/win32/Win32Services.rb
Constant Summary collapse
- SERVICE_MAPPING =
[ 'Type', :svc_type, 'Start', :start, 'ImagePath', :image_path, 'DisplayName', :display_name, 'ObjectName', :object_name, 'Description', :description, 'Type', :type, 'DependOnService', :depend_on_service, 'DependOnGroup', :depend_on_group, ]
- SERVICE_VALUE_MAP =
[]
Instance Attribute Summary collapse
-
#services ⇒ Object
readonly
Returns the value of attribute services.
Instance Method Summary collapse
-
#initialize(_c, fs) ⇒ Services
constructor
A new instance of Services.
- #service_type_to_string(type) ⇒ Object
- #to_xml(doc = nil) ⇒ Object
Constructor Details
#initialize(_c, fs) ⇒ Services
Returns a new instance of Services.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/metadata/util/win32/Win32Services.rb', line 25 def initialize(_c, fs) @services = [] regHnd = RemoteRegistry.new(fs, true) reg_doc = regHnd.loadHive("system", [{:key => 'CurrentControlSet/Services', :depth => 0, :value => SERVICE_VALUE_MAP}]) regHnd.close reg_node = MIQRexml.findRegElement("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services", reg_doc.root) if reg_node reg_node.each_element do |e| next if e.name != :key # Remove child elements's that have children. This data is not being processed on the server # and adds a lot of extract size to the xml and time for tagging. e.each_element { |e1| e1.remove! if e1.name == :key } end reg_node.each_element_with_attribute(:keyname) do |e| attrs = XmlFind.decode(e, SERVICE_MAPPING) attrs[:name] = e.attributes[:keyname] attrs[:typename] = service_type_to_string(attrs.delete(:type)) attrs[:depend_on_service] = attrs[:depend_on_service].split(' ').collect { |d| {:name => d} } if attrs[:depend_on_service] attrs[:depend_on_group] = attrs[:depend_on_group].split(' ').collect { |d| {:name => d} } if attrs[:depend_on_group] @services << attrs end end # Force memory cleanup reg_doc = nil; GC.start end |
Instance Attribute Details
#services ⇒ Object (readonly)
Returns the value of attribute services.
8 9 10 |
# File 'lib/metadata/util/win32/Win32Services.rb', line 8 def services @services end |
Instance Method Details
#service_type_to_string(type) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/metadata/util/win32/Win32Services.rb', line 57 def service_type_to_string(type) type = type.nil? ? 1 : type.to_i if (type & 0x00000001) > 0 "kernel" elsif (type & 0x00000002) > 0 "filesystem" elsif ((type & 0x00000010) > 0) || ((type & 0x00000020) > 0) "win32_service" else "misc" end end |
#to_xml(doc = nil) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/metadata/util/win32/Win32Services.rb', line 70 def to_xml(doc = nil) doc = MiqXml.createDoc(nil) unless doc @services.each do |s| depends_service = s.delete(:depend_on_service) depends_group = s.delete(:depend_on_group) node = doc.add_element("service", XmlHelpers.stringify_keys(s)) depends_service.each { |d| node.add_element("depend_on_service", XmlHelpers.stringify_keys(d)) } if depends_service depends_group.each { |d| node.add_element("depend_on_group", XmlHelpers.stringify_keys(d)) } if depends_group end doc end |