windows-pr 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +444 -438
  3. data/MANIFEST +68 -65
  4. data/README +154 -153
  5. data/Rakefile +42 -37
  6. data/doc/conversion_guide.txt +37 -37
  7. data/lib/windows/clipboard.rb +61 -61
  8. data/lib/windows/com.rb +192 -192
  9. data/lib/windows/com/accessibility.rb +16 -16
  10. data/lib/windows/com/automation.rb +149 -149
  11. data/lib/windows/com/variant.rb +24 -24
  12. data/lib/windows/console.rb +114 -114
  13. data/lib/windows/debug.rb +35 -35
  14. data/lib/windows/device_io.rb +248 -248
  15. data/lib/windows/directory.rb +27 -27
  16. data/lib/windows/error.rb +504 -498
  17. data/lib/windows/eventlog.rb +80 -80
  18. data/lib/windows/file.rb +264 -264
  19. data/lib/windows/file_mapping.rb +25 -25
  20. data/lib/windows/filesystem.rb +15 -15
  21. data/lib/windows/gdi/bitmap.rb +65 -65
  22. data/lib/windows/gdi/device_context.rb +46 -46
  23. data/lib/windows/gdi/metafile.rb +40 -40
  24. data/lib/windows/gdi/painting_drawing.rb +115 -115
  25. data/lib/windows/handle.rb +23 -23
  26. data/lib/windows/library.rb +44 -44
  27. data/lib/windows/limits.rb +34 -34
  28. data/lib/windows/mailslot.rb +24 -24
  29. data/lib/windows/memory.rb +128 -128
  30. data/lib/windows/msvcrt/buffer.rb +75 -75
  31. data/lib/windows/msvcrt/directory.rb +31 -31
  32. data/lib/windows/msvcrt/file.rb +47 -47
  33. data/lib/windows/msvcrt/io.rb +73 -73
  34. data/lib/windows/msvcrt/string.rb +182 -182
  35. data/lib/windows/msvcrt/time.rb +169 -169
  36. data/lib/windows/national.rb +580 -580
  37. data/lib/windows/network/management.rb +525 -525
  38. data/lib/windows/network/snmp.rb +92 -92
  39. data/lib/windows/network/winsock.rb +128 -128
  40. data/lib/windows/nio.rb +50 -50
  41. data/lib/windows/ntfs/winternl.rb +117 -117
  42. data/lib/windows/path.rb +143 -143
  43. data/lib/windows/pipe.rb +42 -42
  44. data/lib/windows/process.rb +176 -176
  45. data/lib/windows/registry.rb +171 -171
  46. data/lib/windows/security.rb +479 -479
  47. data/lib/windows/security/authentication.rb +32 -32
  48. data/lib/windows/security/sspi.rb +153 -0
  49. data/lib/windows/service.rb +142 -142
  50. data/lib/windows/shell.rb +171 -171
  51. data/lib/windows/socket.rb +86 -86
  52. data/lib/windows/sound.rb +39 -39
  53. data/lib/windows/synchronize.rb +133 -133
  54. data/lib/windows/system_info.rb +229 -229
  55. data/lib/windows/thread.rb +64 -64
  56. data/lib/windows/time.rb +48 -48
  57. data/lib/windows/tool_helper.rb +36 -36
  58. data/lib/windows/unicode.rb +155 -155
  59. data/lib/windows/volume.rb +61 -61
  60. data/lib/windows/window.rb +81 -81
  61. data/lib/windows/window/classes.rb +59 -59
  62. data/lib/windows/window/dialog.rb +91 -91
  63. data/lib/windows/window/menu.rb +102 -102
  64. data/lib/windows/window/message.rb +297 -297
  65. data/lib/windows/window/properties.rb +20 -20
  66. data/lib/windows/window/timer.rb +19 -19
  67. data/lib/windows/wsa.rb +102 -102
  68. data/test/tc_clipboard.rb +41 -41
  69. data/test/tc_com.rb +32 -32
  70. data/test/tc_com_automation.rb +15 -15
  71. data/test/tc_console.rb +108 -108
  72. data/test/tc_debug.rb +48 -48
  73. data/test/tc_device_io.rb +29 -29
  74. data/test/tc_directory.rb +25 -25
  75. data/test/tc_error.rb +38 -38
  76. data/test/tc_eventlog.rb +58 -58
  77. data/test/tc_file.rb +67 -67
  78. data/test/tc_file_mapping.rb +38 -38
  79. data/test/tc_filesystem.rb +27 -27
  80. data/test/tc_gdi_bitmap.rb +25 -25
  81. data/test/tc_gdi_metafile.rb +23 -23
  82. data/test/tc_handle.rb +36 -36
  83. data/test/tc_library.rb +37 -37
  84. data/test/tc_limits.rb +34 -34
  85. data/test/tc_mailslot.rb +22 -22
  86. data/test/tc_memory.rb +44 -44
  87. data/test/tc_msvcrt_buffer.rb +63 -63
  88. data/test/tc_msvcrt_directory.rb +96 -96
  89. data/test/tc_msvcrt_file.rb +80 -80
  90. data/test/tc_msvcrt_io.rb +48 -48
  91. data/test/tc_msvcrt_string.rb +94 -94
  92. data/test/tc_msvcrt_time.rb +19 -19
  93. data/test/tc_national.rb +38 -38
  94. data/test/tc_network_management.rb +32 -32
  95. data/test/tc_network_snmp.rb +31 -31
  96. data/test/tc_network_winsock.rb +34 -34
  97. data/test/tc_nio.rb +32 -32
  98. data/test/tc_ntfs_winternl.rb +48 -48
  99. data/test/tc_path.rb +90 -90
  100. data/test/tc_pipe.rb +53 -53
  101. data/test/tc_process.rb +24 -24
  102. data/test/tc_registry.rb +29 -29
  103. data/test/tc_security.rb +104 -104
  104. data/test/tc_security_authentication.rb +34 -34
  105. data/test/tc_security_sspi.rb +23 -0
  106. data/test/tc_service.rb +57 -57
  107. data/test/tc_shell.rb +34 -34
  108. data/test/tc_socket.rb +20 -20
  109. data/test/tc_sound.rb +37 -37
  110. data/test/tc_synchronize.rb +75 -75
  111. data/test/tc_system_info.rb +33 -33
  112. data/test/tc_thread.rb +29 -29
  113. data/test/tc_time.rb +32 -32
  114. data/test/tc_tool_helper.rb +29 -29
  115. data/test/tc_unicode.rb +83 -83
  116. data/test/tc_volume.rb +47 -47
  117. data/test/tc_window.rb +45 -45
  118. data/test/tc_window_classes.rb +33 -33
  119. data/test/tc_window_dialog.rb +33 -33
  120. data/test/tc_window_menu.rb +29 -29
  121. data/test/tc_window_message.rb +33 -33
  122. data/test/tc_window_properties.rb +29 -29
  123. data/test/tc_window_timer.rb +29 -29
  124. data/test/tc_wsa.rb +19 -19
  125. data/windows-pr.gemspec +33 -34
  126. metadata +31 -32
@@ -1,39 +1,39 @@
1
- require 'windows/api'
2
-
3
- module Windows
4
- module Sound
5
- API.auto_namespace = 'Windows::Sound'
6
- API.auto_constant = true
7
- API.auto_method = true
8
- API.auto_unicode = false
9
-
10
- private
11
-
12
- SND_SYNC = 0x0000 # play synchronously (default)
13
- SND_ASYNC = 0x0001 # play asynchronously
14
- SND_NODEFAULT = 0x0002 # silence (!default) if sound not found
15
- SND_MEMORY = 0x0004 # pszSound points to a memory file
16
- SND_LOOP = 0x0008 # loop the sound until next sndPlaySound
17
- SND_NOSTOP = 0x0010 # don't stop any currently playing sound
18
-
19
- SND_NOWAIT = 8192 # don't wait if the driver is busy
20
- SND_ALIAS = 65536 # name is a registry alias
21
- SND_ALIAS_ID = 1114112 # alias is a predefined ID
22
- SND_FILENAME = 131072 # name is file name
23
- SND_RESOURCE = 262148 # name is resource name or atom
24
-
25
- SND_PURGE = 0x0040 # purge non-static events for task
26
- SND_APPLICATION = 0x0080 # look for application specific association
27
-
28
- API.new('Beep', 'LL', 'B')
29
- API.new('PlaySound', 'PPL', 'B', 'winmm')
30
- API.new('waveOutSetVolume', 'PL', 'I', 'winmm')
31
- API.new('waveOutGetVolume', 'LP', 'I', 'winmm')
32
- API.new('waveOutGetNumDevs', 'V', 'I', 'winmm')
33
- API.new('waveInGetNumDevs', 'V', 'I', 'winmm')
34
- API.new('midiOutGetNumDevs', 'V', 'I', 'winmm')
35
- API.new('midiInGetNumDevs', 'V', 'I', 'winmm')
36
- API.new('auxGetNumDevs', 'V', 'I', 'winmm')
37
- API.new('mixerGetNumDevs', 'V', 'I', 'winmm')
38
- end
39
- end
1
+ require 'windows/api'
2
+
3
+ module Windows
4
+ module Sound
5
+ API.auto_namespace = 'Windows::Sound'
6
+ API.auto_constant = true
7
+ API.auto_method = true
8
+ API.auto_unicode = false
9
+
10
+ private
11
+
12
+ SND_SYNC = 0x0000 # play synchronously (default)
13
+ SND_ASYNC = 0x0001 # play asynchronously
14
+ SND_NODEFAULT = 0x0002 # silence (!default) if sound not found
15
+ SND_MEMORY = 0x0004 # pszSound points to a memory file
16
+ SND_LOOP = 0x0008 # loop the sound until next sndPlaySound
17
+ SND_NOSTOP = 0x0010 # don't stop any currently playing sound
18
+
19
+ SND_NOWAIT = 8192 # don't wait if the driver is busy
20
+ SND_ALIAS = 65536 # name is a registry alias
21
+ SND_ALIAS_ID = 1114112 # alias is a predefined ID
22
+ SND_FILENAME = 131072 # name is file name
23
+ SND_RESOURCE = 262148 # name is resource name or atom
24
+
25
+ SND_PURGE = 0x0040 # purge non-static events for task
26
+ SND_APPLICATION = 0x0080 # look for application specific association
27
+
28
+ API.new('Beep', 'LL', 'B')
29
+ API.new('PlaySound', 'PPL', 'B', 'winmm')
30
+ API.new('waveOutSetVolume', 'PL', 'I', 'winmm')
31
+ API.new('waveOutGetVolume', 'LP', 'I', 'winmm')
32
+ API.new('waveOutGetNumDevs', 'V', 'I', 'winmm')
33
+ API.new('waveInGetNumDevs', 'V', 'I', 'winmm')
34
+ API.new('midiOutGetNumDevs', 'V', 'I', 'winmm')
35
+ API.new('midiInGetNumDevs', 'V', 'I', 'winmm')
36
+ API.new('auxGetNumDevs', 'V', 'I', 'winmm')
37
+ API.new('mixerGetNumDevs', 'V', 'I', 'winmm')
38
+ end
39
+ end
@@ -1,133 +1,133 @@
1
- require 'windows/api'
2
-
3
- module Windows
4
- module Synchronize
5
- API.auto_namespace = 'Windows::Synchronize'
6
- API.auto_constant = true
7
- API.auto_method = true
8
- API.auto_unicode = true
9
-
10
- private
11
-
12
- INFINITE = 0xFFFFFFFF
13
- WAIT_OBJECT_0 = 0
14
- WAIT_TIMEOUT = 0x102
15
- WAIT_ABANDONED = 128
16
- WAIT_ABANDONED_0 = WAIT_ABANDONED
17
- WAIT_FAILED = 0xFFFFFFFF
18
-
19
- STATUS_WAIT_0 = 0
20
- STATUS_ABANDONED_WAIT_0 = 128
21
- STATUS_USER_APC = 192
22
- STATUS_TIMEOUT = 258
23
- STATUS_PENDING = 259
24
-
25
- # Wake mask constants
26
-
27
- QS_ALLEVENTS = 0x04BF
28
- QS_ALLINPUT = 0x04FF
29
- QS_ALLPOSTMESSAGE = 0x0100
30
- QS_HOTKEY = 0x0080
31
- QS_INPUT = 0x407
32
- QS_KEY = 0x0001
33
- QS_MOUSE = 0x0006
34
- QS_MOUSEBUTTON = 0x0004
35
- QS_MOUSEMOVE = 0x0002
36
- QS_PAINT = 0x0020
37
- QS_POSTMESSAGE = 0x0008
38
- QS_RAWINPUT = 0x0400
39
- QS_SENDMESSAGE = 0x0040
40
- QS_TIMER = 0x0010
41
-
42
- # Wait type constants
43
-
44
- MWMO_ALERTABLE = 0x0002
45
- MWMO_INPUTAVAILABLE = 0x0004
46
- MWMO_WAITALL = 0x0001
47
-
48
- # Access rights
49
-
50
- EVENT_ALL_ACCESS = 0x1F0003
51
- EVENT_MODIFY_STATE = 0x0002
52
- MUTEX_ALL_ACCESS = 0x1F0001
53
- MUTEX_MODIFY_STATE = 0x0001
54
- SEMAPHORE_ALL_ACCESS = 0x1F0003
55
- SEMAPHORE_MODIFY_STATE = 0x0002
56
-
57
- # Namespace flags
58
-
59
- PRIVATE_NAMESPACE_FLAG_DESTROY = 0x00000001
60
-
61
- # Functions
62
-
63
- API.new('CancelWaitableTimer', 'L', 'B')
64
- API.new('CreateEvent', 'PIIP', 'L')
65
- API.new('CreateMutex', 'PIP', 'L')
66
- API.new('CreateSemaphore', 'PLLP', 'L')
67
- API.new('CreateWaitableTimer', 'PIP', 'L')
68
- API.new('DeleteCriticalSection', 'P', 'V')
69
- API.new('EnterCriticalSection', 'P', 'V')
70
- API.new('GetOverlappedResult', 'LPPI', 'I')
71
- API.new('InitializeCriticalSection', 'P', 'V')
72
- API.new('InitializeCriticalSectionAndSpinCount', 'PL', 'B')
73
- API.new('LeaveCriticalSection', 'P', 'V')
74
- API.new('MsgWaitForMultipleObjects', 'LPILL', 'L', 'user32')
75
- API.new('MsgWaitForMultipleObjectsEx', 'LPLLL', 'L', 'user32')
76
- API.new('OpenEvent', 'LIP', 'L')
77
- API.new('OpenMutex', 'LIP', 'L')
78
- API.new('OpenSemaphore', 'LIP', 'L')
79
- API.new('OpenWaitableTimer', 'LIP', 'L')
80
- API.new('ReleaseMutex', 'L', 'B')
81
- API.new('ReleaseSemaphore', 'LLP', 'B')
82
- API.new('ResetEvent', 'L', 'B')
83
- API.new('SetCriticalSectionSpinCount', 'PL', 'V')
84
- API.new('SetWaitableTimer', 'LPLKPI', 'B')
85
- API.new('SetEvent', 'L', 'B')
86
- API.new('TryEnterCriticalSection', 'P', 'B')
87
- API.new('WaitForMultipleObjects', 'LPIL', 'L')
88
- API.new('WaitForMultipleObjectsEx', 'LPILI', 'L')
89
- API.new('WaitForSingleObject', 'LL', 'L')
90
- API.new('WaitForSingleObjectEx', 'LLI', 'L')
91
-
92
- # Macros
93
-
94
- def HasOverlappedIoCompleted(overlapped)
95
- overlapped[0,4].unpack('L')[0] != STATUS_PENDING
96
- end
97
-
98
- # This simulates the RUBY_CRITICAL macro from rubysig.h, although I've
99
- # added the begin/ensure wrapper to boot.
100
- #
101
- def RUBY_CRITICAL(&block)
102
- critical_section = [0].pack('L')
103
- begin
104
- InitializeCriticalSection(critical_section)
105
- EnterCriticalSection(critical_section)
106
- block.call
107
- ensure
108
- LeaveCriticalSection(critical_section)
109
- end
110
- end
111
-
112
- # Vista or later
113
-
114
- begin
115
- API.new('AddSIDToBoundaryDescriptor', 'PP', 'B')
116
- API.new('ClosePrivateNamespace', 'LL', 'B')
117
- API.new('CreateBoundaryDescriptor', 'SL', 'L')
118
- API.new('DeleteBoundaryDescriptor', 'L', 'V')
119
- API.new('CreatePrivateNamespace', 'PLS', 'L')
120
- API.new('OpenPrivateNamespace', 'PS', 'L')
121
- rescue Win32::API::LoadLibraryError
122
- # Windows Vista or later
123
- end
124
-
125
- # Windows 7 or later
126
-
127
- begin
128
- API.new('AddIntegrityLabelToBoundaryDescriptor', 'PP', 'B')
129
- rescue Win32::API::LoadLibraryError
130
- # Windows 7 or later
131
- end
132
- end
133
- end
1
+ require 'windows/api'
2
+
3
+ module Windows
4
+ module Synchronize
5
+ API.auto_namespace = 'Windows::Synchronize'
6
+ API.auto_constant = true
7
+ API.auto_method = true
8
+ API.auto_unicode = true
9
+
10
+ private
11
+
12
+ INFINITE = 0xFFFFFFFF
13
+ WAIT_OBJECT_0 = 0
14
+ WAIT_TIMEOUT = 0x102
15
+ WAIT_ABANDONED = 128
16
+ WAIT_ABANDONED_0 = WAIT_ABANDONED
17
+ WAIT_FAILED = 0xFFFFFFFF
18
+
19
+ STATUS_WAIT_0 = 0
20
+ STATUS_ABANDONED_WAIT_0 = 128
21
+ STATUS_USER_APC = 192
22
+ STATUS_TIMEOUT = 258
23
+ STATUS_PENDING = 259
24
+
25
+ # Wake mask constants
26
+
27
+ QS_ALLEVENTS = 0x04BF
28
+ QS_ALLINPUT = 0x04FF
29
+ QS_ALLPOSTMESSAGE = 0x0100
30
+ QS_HOTKEY = 0x0080
31
+ QS_INPUT = 0x407
32
+ QS_KEY = 0x0001
33
+ QS_MOUSE = 0x0006
34
+ QS_MOUSEBUTTON = 0x0004
35
+ QS_MOUSEMOVE = 0x0002
36
+ QS_PAINT = 0x0020
37
+ QS_POSTMESSAGE = 0x0008
38
+ QS_RAWINPUT = 0x0400
39
+ QS_SENDMESSAGE = 0x0040
40
+ QS_TIMER = 0x0010
41
+
42
+ # Wait type constants
43
+
44
+ MWMO_ALERTABLE = 0x0002
45
+ MWMO_INPUTAVAILABLE = 0x0004
46
+ MWMO_WAITALL = 0x0001
47
+
48
+ # Access rights
49
+
50
+ EVENT_ALL_ACCESS = 0x1F0003
51
+ EVENT_MODIFY_STATE = 0x0002
52
+ MUTEX_ALL_ACCESS = 0x1F0001
53
+ MUTEX_MODIFY_STATE = 0x0001
54
+ SEMAPHORE_ALL_ACCESS = 0x1F0003
55
+ SEMAPHORE_MODIFY_STATE = 0x0002
56
+
57
+ # Namespace flags
58
+
59
+ PRIVATE_NAMESPACE_FLAG_DESTROY = 0x00000001
60
+
61
+ # Functions
62
+
63
+ API.new('CancelWaitableTimer', 'L', 'B')
64
+ API.new('CreateEvent', 'PIIP', 'L')
65
+ API.new('CreateMutex', 'PIP', 'L')
66
+ API.new('CreateSemaphore', 'PLLP', 'L')
67
+ API.new('CreateWaitableTimer', 'PIP', 'L')
68
+ API.new('DeleteCriticalSection', 'P', 'V')
69
+ API.new('EnterCriticalSection', 'P', 'V')
70
+ API.new('GetOverlappedResult', 'LPPI', 'I')
71
+ API.new('InitializeCriticalSection', 'P', 'V')
72
+ API.new('InitializeCriticalSectionAndSpinCount', 'PL', 'B')
73
+ API.new('LeaveCriticalSection', 'P', 'V')
74
+ API.new('MsgWaitForMultipleObjects', 'LPILL', 'L', 'user32')
75
+ API.new('MsgWaitForMultipleObjectsEx', 'LPLLL', 'L', 'user32')
76
+ API.new('OpenEvent', 'LIP', 'L')
77
+ API.new('OpenMutex', 'LIP', 'L')
78
+ API.new('OpenSemaphore', 'LIP', 'L')
79
+ API.new('OpenWaitableTimer', 'LIP', 'L')
80
+ API.new('ReleaseMutex', 'L', 'B')
81
+ API.new('ReleaseSemaphore', 'LLP', 'B')
82
+ API.new('ResetEvent', 'L', 'B')
83
+ API.new('SetCriticalSectionSpinCount', 'PL', 'V')
84
+ API.new('SetWaitableTimer', 'LPLKPI', 'B')
85
+ API.new('SetEvent', 'L', 'B')
86
+ API.new('TryEnterCriticalSection', 'P', 'B')
87
+ API.new('WaitForMultipleObjects', 'LPIL', 'L')
88
+ API.new('WaitForMultipleObjectsEx', 'LPILI', 'L')
89
+ API.new('WaitForSingleObject', 'LL', 'L')
90
+ API.new('WaitForSingleObjectEx', 'LLI', 'L')
91
+
92
+ # Macros
93
+
94
+ def HasOverlappedIoCompleted(overlapped)
95
+ overlapped[0,4].unpack('L')[0] != STATUS_PENDING
96
+ end
97
+
98
+ # This simulates the RUBY_CRITICAL macro from rubysig.h, although I've
99
+ # added the begin/ensure wrapper to boot.
100
+ #
101
+ def RUBY_CRITICAL(&block)
102
+ critical_section = [0].pack('L')
103
+ begin
104
+ InitializeCriticalSection(critical_section)
105
+ EnterCriticalSection(critical_section)
106
+ block.call
107
+ ensure
108
+ LeaveCriticalSection(critical_section)
109
+ end
110
+ end
111
+
112
+ # Vista or later
113
+
114
+ begin
115
+ API.new('AddSIDToBoundaryDescriptor', 'PP', 'B')
116
+ API.new('ClosePrivateNamespace', 'LL', 'B')
117
+ API.new('CreateBoundaryDescriptor', 'SL', 'L')
118
+ API.new('DeleteBoundaryDescriptor', 'L', 'V')
119
+ API.new('CreatePrivateNamespace', 'PLS', 'L')
120
+ API.new('OpenPrivateNamespace', 'PS', 'L')
121
+ rescue Win32::API::LoadLibraryError
122
+ # Windows Vista or later
123
+ end
124
+
125
+ # Windows 7 or later
126
+
127
+ begin
128
+ API.new('AddIntegrityLabelToBoundaryDescriptor', 'PP', 'B')
129
+ rescue Win32::API::LoadLibraryError
130
+ # Windows 7 or later
131
+ end
132
+ end
133
+ end
@@ -1,229 +1,229 @@
1
- require 'windows/api'
2
-
3
- module Windows
4
- module SystemInfo
5
- API.auto_namespace = 'Windows::SystemInfo'
6
- API.auto_constant = true
7
- API.auto_method = true
8
- API.auto_unicode = true
9
-
10
- private
11
-
12
- # Obsolete processor info constants
13
-
14
- PROCESSOR_INTEL_386 = 386
15
- PROCESSOR_INTEL_486 = 486
16
- PROCESSOR_INTEL_PENTIUM = 586
17
- PROCESSOR_INTEL_IA64 = 2200
18
- PROCESSOR_AMD_X8664 = 8664
19
-
20
- # Suite mask constants
21
-
22
- VER_SERVER_NT = 0x80000000
23
- VER_WORKSTATION_NT = 0x40000000
24
- VER_SUITE_SMALLBUSINESS = 0x00000001
25
- VER_SUITE_ENTERPRISE = 0x00000002
26
- VER_SUITE_BACKOFFICE = 0x00000004
27
- VER_SUITE_COMMUNICATIONS = 0x00000008
28
- VER_SUITE_TERMINAL = 0x00000010
29
- VER_SUITE_SMALLBUSINESS_RESTRICTED = 0x00000020
30
- VER_SUITE_EMBEDDEDNT = 0x00000040
31
- VER_SUITE_DATACENTER = 0x00000080
32
- VER_SUITE_SINGLEUSERTS = 0x00000100
33
- VER_SUITE_PERSONAL = 0x00000200
34
- VER_SUITE_BLADE = 0x00000400
35
- VER_SUITE_EMBEDDED_RESTRICTED = 0x00000800
36
- VER_SUITE_SECURITY_APPLIANCE = 0x00001000
37
- VER_SUITE_STORAGE_SERVER = 0x00002000
38
- VER_SUITE_COMPUTE_SERVER = 0x00004000
39
-
40
- # Product mask constants
41
-
42
- VER_NT_WORKSTATION = 0x0000001
43
- VER_NT_DOMAIN_CONTROLLER = 0x0000002
44
- VER_NT_SERVER = 0x0000003
45
-
46
- # Platform definitions
47
-
48
- VER_PLATFORM_WIN32s = 0
49
- VER_PLATFORM_WIN32_WINDOWS = 1
50
- VER_PLATFORM_WIN32_NT = 2
51
-
52
- # Version info type constants
53
-
54
- VER_MINORVERSION = 0x0000001
55
- VER_MAJORVERSION = 0x0000002
56
- VER_BUILDNUMBER = 0x0000004
57
- VER_PLATFORMID = 0x0000008
58
- VER_SERVICEPACKMINOR = 0x0000010
59
- VER_SERVICEPACKMAJOR = 0x0000020
60
- VER_SUITENAME = 0x0000040
61
- VER_PRODUCT_TYPE = 0x0000080
62
-
63
- # Enum COMPUTER_NAME_FORMAT
64
-
65
- ComputerNameNetBIOS = 0
66
- ComputerNameDnsHostname = 1
67
- ComputerNameDnsDomain = 2
68
- ComputerNameDnsFullyQualified = 3
69
- ComputerNamePhysicalNetBIOS = 4
70
- ComputerNamePhysicalDnsHostname = 5
71
- ComputerNamePhysicalDnsDomain = 6
72
- ComputerNamePhysicalDnsFullyQualified = 7
73
- ComputerNameMax = 8
74
-
75
- API.new('ExpandEnvironmentStrings', 'PPL', 'L')
76
- API.new('GetComputerName', 'PP', 'B')
77
- API.new('GetComputerNameEx', 'PPP', 'B')
78
- API.new('GetSystemInfo', 'P', 'V')
79
- API.new('GetUserName', 'PP', 'B', 'advapi32')
80
- API.new('GetUserNameEx', 'LPP', 'B', 'secur32')
81
- API.new('GetVersion', 'V', 'L')
82
- API.new('GetVersionEx', 'P', 'B')
83
- API.new('GetWindowsDirectory', 'PI', 'I')
84
-
85
- begin
86
- API.new('GetSystemWow64Directory', 'PI', 'I')
87
- rescue Win32::API::LoadLibraryError
88
- # XP or later
89
- end
90
-
91
- # These macros are from windef.h, but I've put them here for now
92
- # since they can be used in conjunction with some of the functions
93
- # declared in this module.
94
-
95
- def MAKEWORD(a, b)
96
- ((a & 0xff) | ((b & 0xff) << 8))
97
- end
98
-
99
- def MAKELONG(a, b)
100
- ((a & 0xffff) | ((b & 0xffff) << 16))
101
- end
102
-
103
- def LOWORD(l)
104
- l & 0xffff
105
- end
106
-
107
- def HIWORD(l)
108
- l >> 16
109
- end
110
-
111
- def LOBYTE(w)
112
- w & 0xff
113
- end
114
-
115
- def HIBYTE(w)
116
- w >> 8
117
- end
118
-
119
- # Returns a float indicating the major and minor version of Windows,
120
- # e.g. 5.1, 6.0, etc.
121
- #
122
- def windows_version
123
- version = GetVersion()
124
- major = LOBYTE(LOWORD(version))
125
- minor = HIBYTE(LOWORD(version))
126
- eval("Float(#{major}.#{minor})")
127
- end
128
-
129
- # Custom methods that may come in handy
130
-
131
- # Returns true if the current platform is Vista (any variant) or Windows
132
- # Server 2008, i.e. major version 6, minor version 0.
133
- #
134
- def windows_2000?
135
- version = GetVersion()
136
- LOBYTE(LOWORD(version)) == 5 && HIBYTE(LOWORD(version)) == 0
137
- end
138
-
139
- # Returns true if the current platform is Windows XP or Windows XP
140
- # Pro, i.e. major version 5, minor version 1 (or 2 in the case of a
141
- # 64-bit Windows XP Pro).
142
- #--
143
- # Because of the exception for a 64-bit Windows XP Pro, we have to
144
- # do things the hard way. For version 2 we look for any of the suite
145
- # masks that might be associated with Windows 2003. If we don't find
146
- # any of them, assume it's Windows XP.
147
- #
148
- def windows_xp?
149
- bool = false
150
-
151
- buf = 0.chr * 156
152
- buf[0,4] = [buf.size].pack("L") # Set dwOSVersionInfoSize
153
-
154
- GetVersionEx(buf)
155
-
156
- major = buf[4,4].unpack("L")[0]
157
- minor = buf[8,4].unpack("L")[0]
158
- suite = buf[152,2].unpack("S")[0]
159
-
160
- # Make sure we detect a 64-bit Windows XP Pro
161
- if major == 5
162
- if minor == 1
163
- bool = true
164
- elsif minor == 2
165
- if (suite & VER_SUITE_BLADE == 0) &&
166
- (suite & VER_SUITE_COMPUTE_SERVER == 0) &&
167
- (suite & VER_SUITE_DATACENTER == 0) &&
168
- (suite & VER_SUITE_ENTERPRISE == 0) &&
169
- (suite & VER_SUITE_STORAGE_SERVER == 0)
170
- then
171
- bool = true
172
- end
173
- else
174
- # Do nothing - already false
175
- end
176
- end
177
-
178
- bool
179
- end
180
-
181
- # Returns true if the current platform is Windows 2003 (any version).
182
- # i.e. major version 5, minor version 2.
183
- #--
184
- # Because of the exception for a 64-bit Windows XP Pro, we have to
185
- # do things the hard way. For version 2 we look for any of the suite
186
- # masks that might be associated with Windows 2003. If we find any
187
- # of them, assume it's Windows 2003.
188
- #
189
- def windows_2003?
190
- bool = false
191
-
192
- buf = 0.chr * 156
193
- buf[0,4] = [buf.size].pack("L") # Set dwOSVersionInfoSize
194
-
195
- GetVersionEx(buf)
196
-
197
- major = buf[4,4].unpack("L")[0]
198
- minor = buf[8,4].unpack("L")[0]
199
- suite = buf[152,2].unpack("S")[0]
200
-
201
- # Make sure we exclude a 64-bit Windows XP Pro
202
- if major == 5 && minor == 2
203
- if (suite & VER_SUITE_BLADE > 0) ||
204
- (suite & VER_SUITE_COMPUTE_SERVER > 0) ||
205
- (suite & VER_SUITE_DATACENTER > 0) ||
206
- (suite & VER_SUITE_ENTERPRISE > 0) ||
207
- (suite & VER_SUITE_STORAGE_SERVER > 0)
208
- then
209
- bool = true
210
- end
211
- end
212
-
213
- bool
214
- end
215
-
216
- # Returns true if the current platform is Windows Vista (any variant)
217
- # or Windows Server 2008, i.e. major version 6, minor version 0.
218
- #
219
- def windows_vista?
220
- version = GetVersion()
221
- LOBYTE(LOWORD(version)) == 6 && HIBYTE(LOWORD(version)) == 0
222
- end
223
-
224
- def windows_7?
225
- version = GetVersion()
226
- LOBYTE(LOWORD(version)) == 6 && HIBYTE(LOWORD(version)) == 1
227
- end
228
- end
229
- end
1
+ require 'windows/api'
2
+
3
+ module Windows
4
+ module SystemInfo
5
+ API.auto_namespace = 'Windows::SystemInfo'
6
+ API.auto_constant = true
7
+ API.auto_method = true
8
+ API.auto_unicode = true
9
+
10
+ private
11
+
12
+ # Obsolete processor info constants
13
+
14
+ PROCESSOR_INTEL_386 = 386
15
+ PROCESSOR_INTEL_486 = 486
16
+ PROCESSOR_INTEL_PENTIUM = 586
17
+ PROCESSOR_INTEL_IA64 = 2200
18
+ PROCESSOR_AMD_X8664 = 8664
19
+
20
+ # Suite mask constants
21
+
22
+ VER_SERVER_NT = 0x80000000
23
+ VER_WORKSTATION_NT = 0x40000000
24
+ VER_SUITE_SMALLBUSINESS = 0x00000001
25
+ VER_SUITE_ENTERPRISE = 0x00000002
26
+ VER_SUITE_BACKOFFICE = 0x00000004
27
+ VER_SUITE_COMMUNICATIONS = 0x00000008
28
+ VER_SUITE_TERMINAL = 0x00000010
29
+ VER_SUITE_SMALLBUSINESS_RESTRICTED = 0x00000020
30
+ VER_SUITE_EMBEDDEDNT = 0x00000040
31
+ VER_SUITE_DATACENTER = 0x00000080
32
+ VER_SUITE_SINGLEUSERTS = 0x00000100
33
+ VER_SUITE_PERSONAL = 0x00000200
34
+ VER_SUITE_BLADE = 0x00000400
35
+ VER_SUITE_EMBEDDED_RESTRICTED = 0x00000800
36
+ VER_SUITE_SECURITY_APPLIANCE = 0x00001000
37
+ VER_SUITE_STORAGE_SERVER = 0x00002000
38
+ VER_SUITE_COMPUTE_SERVER = 0x00004000
39
+
40
+ # Product mask constants
41
+
42
+ VER_NT_WORKSTATION = 0x0000001
43
+ VER_NT_DOMAIN_CONTROLLER = 0x0000002
44
+ VER_NT_SERVER = 0x0000003
45
+
46
+ # Platform definitions
47
+
48
+ VER_PLATFORM_WIN32s = 0
49
+ VER_PLATFORM_WIN32_WINDOWS = 1
50
+ VER_PLATFORM_WIN32_NT = 2
51
+
52
+ # Version info type constants
53
+
54
+ VER_MINORVERSION = 0x0000001
55
+ VER_MAJORVERSION = 0x0000002
56
+ VER_BUILDNUMBER = 0x0000004
57
+ VER_PLATFORMID = 0x0000008
58
+ VER_SERVICEPACKMINOR = 0x0000010
59
+ VER_SERVICEPACKMAJOR = 0x0000020
60
+ VER_SUITENAME = 0x0000040
61
+ VER_PRODUCT_TYPE = 0x0000080
62
+
63
+ # Enum COMPUTER_NAME_FORMAT
64
+
65
+ ComputerNameNetBIOS = 0
66
+ ComputerNameDnsHostname = 1
67
+ ComputerNameDnsDomain = 2
68
+ ComputerNameDnsFullyQualified = 3
69
+ ComputerNamePhysicalNetBIOS = 4
70
+ ComputerNamePhysicalDnsHostname = 5
71
+ ComputerNamePhysicalDnsDomain = 6
72
+ ComputerNamePhysicalDnsFullyQualified = 7
73
+ ComputerNameMax = 8
74
+
75
+ API.new('ExpandEnvironmentStrings', 'PPL', 'L')
76
+ API.new('GetComputerName', 'PP', 'B')
77
+ API.new('GetComputerNameEx', 'PPP', 'B')
78
+ API.new('GetSystemInfo', 'P', 'V')
79
+ API.new('GetUserName', 'PP', 'B', 'advapi32')
80
+ API.new('GetUserNameEx', 'LPP', 'B', 'secur32')
81
+ API.new('GetVersion', 'V', 'L')
82
+ API.new('GetVersionEx', 'P', 'B')
83
+ API.new('GetWindowsDirectory', 'PI', 'I')
84
+
85
+ begin
86
+ API.new('GetSystemWow64Directory', 'PI', 'I')
87
+ rescue Win32::API::LoadLibraryError
88
+ # XP or later
89
+ end
90
+
91
+ # These macros are from windef.h, but I've put them here for now
92
+ # since they can be used in conjunction with some of the functions
93
+ # declared in this module.
94
+
95
+ def MAKEWORD(a, b)
96
+ ((a & 0xff) | ((b & 0xff) << 8))
97
+ end
98
+
99
+ def MAKELONG(a, b)
100
+ ((a & 0xffff) | ((b & 0xffff) << 16))
101
+ end
102
+
103
+ def LOWORD(l)
104
+ l & 0xffff
105
+ end
106
+
107
+ def HIWORD(l)
108
+ l >> 16
109
+ end
110
+
111
+ def LOBYTE(w)
112
+ w & 0xff
113
+ end
114
+
115
+ def HIBYTE(w)
116
+ w >> 8
117
+ end
118
+
119
+ # Returns a float indicating the major and minor version of Windows,
120
+ # e.g. 5.1, 6.0, etc.
121
+ #
122
+ def windows_version
123
+ version = GetVersion()
124
+ major = LOBYTE(LOWORD(version))
125
+ minor = HIBYTE(LOWORD(version))
126
+ "#{major}.#{minor}".to_f
127
+ end
128
+
129
+ # Custom methods that may come in handy
130
+
131
+ # Returns true if the current platform is Vista (any variant) or Windows
132
+ # Server 2008, i.e. major version 6, minor version 0.
133
+ #
134
+ def windows_2000?
135
+ version = GetVersion()
136
+ LOBYTE(LOWORD(version)) == 5 && HIBYTE(LOWORD(version)) == 0
137
+ end
138
+
139
+ # Returns true if the current platform is Windows XP or Windows XP
140
+ # Pro, i.e. major version 5, minor version 1 (or 2 in the case of a
141
+ # 64-bit Windows XP Pro).
142
+ #--
143
+ # Because of the exception for a 64-bit Windows XP Pro, we have to
144
+ # do things the hard way. For version 2 we look for any of the suite
145
+ # masks that might be associated with Windows 2003. If we don't find
146
+ # any of them, assume it's Windows XP.
147
+ #
148
+ def windows_xp?
149
+ bool = false
150
+
151
+ buf = 0.chr * 156
152
+ buf[0,4] = [buf.size].pack("L") # Set dwOSVersionInfoSize
153
+
154
+ GetVersionEx(buf)
155
+
156
+ major = buf[4,4].unpack("L")[0]
157
+ minor = buf[8,4].unpack("L")[0]
158
+ suite = buf[152,2].unpack("S")[0]
159
+
160
+ # Make sure we detect a 64-bit Windows XP Pro
161
+ if major == 5
162
+ if minor == 1
163
+ bool = true
164
+ elsif minor == 2
165
+ if (suite & VER_SUITE_BLADE == 0) &&
166
+ (suite & VER_SUITE_COMPUTE_SERVER == 0) &&
167
+ (suite & VER_SUITE_DATACENTER == 0) &&
168
+ (suite & VER_SUITE_ENTERPRISE == 0) &&
169
+ (suite & VER_SUITE_STORAGE_SERVER == 0)
170
+ then
171
+ bool = true
172
+ end
173
+ else
174
+ # Do nothing - already false
175
+ end
176
+ end
177
+
178
+ bool
179
+ end
180
+
181
+ # Returns true if the current platform is Windows 2003 (any version).
182
+ # i.e. major version 5, minor version 2.
183
+ #--
184
+ # Because of the exception for a 64-bit Windows XP Pro, we have to
185
+ # do things the hard way. For version 2 we look for any of the suite
186
+ # masks that might be associated with Windows 2003. If we find any
187
+ # of them, assume it's Windows 2003.
188
+ #
189
+ def windows_2003?
190
+ bool = false
191
+
192
+ buf = 0.chr * 156
193
+ buf[0,4] = [buf.size].pack("L") # Set dwOSVersionInfoSize
194
+
195
+ GetVersionEx(buf)
196
+
197
+ major = buf[4,4].unpack("L")[0]
198
+ minor = buf[8,4].unpack("L")[0]
199
+ suite = buf[152,2].unpack("S")[0]
200
+
201
+ # Make sure we exclude a 64-bit Windows XP Pro
202
+ if major == 5 && minor == 2
203
+ if (suite & VER_SUITE_BLADE > 0) ||
204
+ (suite & VER_SUITE_COMPUTE_SERVER > 0) ||
205
+ (suite & VER_SUITE_DATACENTER > 0) ||
206
+ (suite & VER_SUITE_ENTERPRISE > 0) ||
207
+ (suite & VER_SUITE_STORAGE_SERVER > 0)
208
+ then
209
+ bool = true
210
+ end
211
+ end
212
+
213
+ bool
214
+ end
215
+
216
+ # Returns true if the current platform is Windows Vista (any variant)
217
+ # or Windows Server 2008, i.e. major version 6, minor version 0.
218
+ #
219
+ def windows_vista?
220
+ version = GetVersion()
221
+ LOBYTE(LOWORD(version)) == 6 && HIBYTE(LOWORD(version)) == 0
222
+ end
223
+
224
+ def windows_7?
225
+ version = GetVersion()
226
+ LOBYTE(LOWORD(version)) == 6 && HIBYTE(LOWORD(version)) == 1
227
+ end
228
+ end
229
+ end