windows-pr 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,15 @@
1
+ = 0.9.4 - 27-Sep-2008
2
+ * Added some macros from windef.h to the Windows::SystemInfo module.
3
+ * Added the windows_2000?, windows_xp?, windows_2003? and windows_vista?
4
+ helper methods to the Windows::SystemInfo module.
5
+ * Added the umask and umask_s functions to the Windows::MSVCRT::File module.
6
+ * Added SH_DENYNO and SHORT_LIVED constants to the Windows::MSVCRT::IO module.
7
+ * Fixed the prototype for open and wopen in the Windows::MSVCRT::IO module.
8
+ * Added SHGetFolderLocation to the Windows::Shell module.
9
+ * Added NT privilege constants to the Windows::Security module.
10
+ * The wide_to_multi helper function is now friendlier with regards to strings
11
+ that may be missing a trailing double null.
12
+
1
13
  = 0.9.3 - 12-Sep-2008
2
14
  * Added event logging functions for Windows Vista and later to the
3
15
  Windows::EventLog module.
data/lib/windows/file.rb CHANGED
@@ -117,6 +117,7 @@ module Windows
117
117
  FILE_SUPPORTS_ENCRYPTION = 0x20000
118
118
 
119
119
  # File flags
120
+
120
121
  FILE_FLAG_WRITE_THROUGH = 0x80000000
121
122
  FILE_FLAG_OVERLAPPED = 0x40000000
122
123
  FILE_FLAG_NO_BUFFERING = 0x20000000
@@ -130,6 +131,7 @@ module Windows
130
131
  FILE_FLAG_FIRST_PIPE_INSTANCE = 0x00080000
131
132
 
132
133
  # File creation disposition
134
+
133
135
  CREATE_NEW = 1
134
136
  CREATE_ALWAYS = 2
135
137
  OPEN_EXISTING = 3
@@ -151,12 +153,14 @@ module Windows
151
153
  SECTION_EXTEND_SIZE
152
154
 
153
155
  # Errors
156
+
154
157
  INVALID_FILE_ATTRIBUTES = -1
155
158
  INVALID_HANDLE_VALUE = -1
156
159
  INVALID_SET_FILE_POINTER = -1
157
160
  INVALID_FILE_SIZE = 0xFFFFFFFF
158
161
 
159
162
  # Misc
163
+
160
164
  LOCKFILE_EXCLUSIVE_LOCK = 0x00000001
161
165
  LOCKFILE_FAIL_IMMEDIATELY = 0x00000002
162
166
  MOVEFILE_REPLACE_EXISTING = 0x00000001
@@ -165,6 +169,7 @@ module Windows
165
169
  MOVEFILE_WRITE_THROUGH = 0x00000008
166
170
  MOVEFILE_CREATE_HARDLINK = 0x00000010
167
171
  MOVEFILE_FAIL_IF_NOT_TRACKABLE = 0x00000020
172
+ SYMBOLIC_LINK_FLAG_DIRECTORY = 0x1
168
173
 
169
174
  API.new('CopyFile', 'PPI', 'B')
170
175
  API.new('CopyFileEx', 'PPKPPL', 'B')
@@ -208,8 +213,16 @@ module Windows
208
213
  API.new('Wow64EnableWow64FsRedirection', 'I', 'I')
209
214
  API.new('Wow64RevertWow64FsRedirection', 'L', 'B')
210
215
  rescue Windows::API::Error
211
- # Do nothing - not supported on current platform. It's up to you to
212
- # check for the existence of the constant in your code.
216
+ # Do nothing - unsupported on your system
217
+ end
218
+
219
+ # Windows Vista
220
+ begin
221
+ API.new('CreateSymbolicLink', 'PPL', 'B')
222
+ API.new('CreateSymbolicLinkTransacted', 'PPLL', 'B')
223
+ API.new('GetFinalPathNameByHandle', 'LPLL', 'L')
224
+ rescue
225
+ # Do nothing - unsupported on your system
213
226
  end
214
227
  end
215
228
  end
@@ -22,6 +22,10 @@ module Windows
22
22
  API.new('_mktemp', 'P', 'P', MSVCRT_DLL)
23
23
  API.new('_stat', 'PP', 'I', 'msvcrt')
24
24
  API.new('_stat64', 'PP', 'I', MSVCRT_DLL)
25
+ API.new('_umask', 'I', 'I', MSVCRT_DLL)
26
+
27
+ # Wide character variants
28
+
25
29
  API.new('_wchmod', 'PI', 'I', MSVCRT_DLL)
26
30
  API.new('_wmktemp', 'P', 'P', MSVCRT_DLL)
27
31
  API.new('_wstat', 'PP', 'I', 'msvcrt')
@@ -31,6 +35,7 @@ module Windows
31
35
  begin
32
36
  API.new('_chsize_s', 'IL', 'I', MSVCRT_DLL)
33
37
  API.new('_mktemp_s', 'PL', 'L', MSVCRT_DLL)
38
+ API.new('_umask_s', 'IP', 'L', MSVCRT_DLL)
34
39
  API.new('_wmktemp_s', 'PL', 'L', MSVCRT_DLL)
35
40
  rescue Windows::API::Error
36
41
  # Ignore - you must check for it via 'defined?'
@@ -17,6 +17,9 @@ module Windows
17
17
  S_IREAD = 0000400 # read permission, owner
18
18
  S_IWRITE = 0000200 # write permission, owner
19
19
  S_IEXEC = 0000100 # execute/search permission, owner
20
+
21
+ SH_DENYNO = 0x40 # deny none mode
22
+ SHORT_LIVED = 0x1000 # temporary file storage
20
23
 
21
24
  API.new('clearerr', 'I', 'V', MSVCRT_DLL)
22
25
  API.new('_close', 'I', 'V', MSVCRT_DLL)
@@ -38,21 +41,28 @@ module Windows
38
41
  API.new('fputws', 'PL', 'I', MSVCRT_DLL)
39
42
  API.new('getc', 'L', 'I', MSVCRT_DLL)
40
43
  API.new('getwc', 'L', 'L', MSVCRT_DLL)
41
- API.new('_open', 'PPI', 'I', MSVCRT_DLL)
44
+ API.new('_open', 'PII', 'I', MSVCRT_DLL)
42
45
  API.new('_rmtmp', 'V', 'I', MSVCRT_DLL)
43
46
  API.new('_setmode', 'II', 'I', MSVCRT_DLL)
47
+ API.new('_sopen', 'PIII', 'I', MSVCRT_DLL)
44
48
  API.new('_tempnam', 'PP', 'P', MSVCRT_DLL)
45
49
  API.new('tmpfile', 'V', 'L', MSVCRT_DLL)
46
50
  API.new('tmpnam', 'P', 'P', MSVCRT_DLL)
47
- API.new('_wopen', 'PPI', 'I', MSVCRT_DLL)
51
+
52
+ # Wide character versions
53
+
54
+ API.new('_wopen', 'PII', 'I', MSVCRT_DLL)
48
55
  API.new('_wfdopen', 'IP', 'I', MSVCRT_DLL)
49
56
  API.new('_wfopen', 'PPI', 'I', MSVCRT_DLL)
57
+ API.new('_wsopen', 'PIII', 'I', MSVCRT_DLL)
50
58
  API.new('_wtempnam', 'PP', 'P', MSVCRT_DLL)
51
59
  API.new('_wtmpnam', 'P', 'P', MSVCRT_DLL)
52
60
 
53
61
  # VC++ 8.0 or later
54
62
  begin
63
+ API.new('_sopen_s', 'PPIII', 'L', MSVCRT_DLL)
55
64
  API.new('_tmpfile_s', 'P', 'L', MSVCRT_DLL)
65
+ API.new('_wsopen_s', 'PPIII', 'L', MSVCRT_DLL)
56
66
  rescue Windows::API::Error
57
67
  # Ignore - you must check for it via 'defined?'
58
68
  end
@@ -126,6 +126,39 @@ module Windows
126
126
  SE_PRIVILEGE_REMOVED = 0X00000004
127
127
  SE_PRIVILEGE_USED_FOR_ACCESS = 0x80000000
128
128
 
129
+ # Defined Privileges
130
+
131
+ SE_CREATE_TOKEN_NAME = "SeCreateTokenPrivilege"
132
+ SE_ASSIGNPRIMARYTOKEN_NAME = "SeAssignPrimaryTokenPrivilege"
133
+ SE_LOCK_MEMORY_NAME = "SeLockMemoryPrivilege"
134
+ SE_INCREASE_QUOTA_NAME = "SeIncreaseQuotaPrivilege"
135
+ SE_UNSOLICITED_INPUT_NAME = "SeUnsolicitedInputPrivilege"
136
+ SE_MACHINE_ACCOUNT_NAME = "SeMachineAccountPrivilege"
137
+ SE_TCB_NAME = "SeTcbPrivilege"
138
+ SE_SECURITY_NAME = "SeSecurityPrivilege"
139
+ SE_TAKE_OWNERSHIP_NAME = "SeTakeOwnershipPrivilege"
140
+ SE_LOAD_DRIVER_NAME = "SeLoadDriverPrivilege"
141
+ SE_SYSTEM_PROFILE_NAME = "SeSystemProfilePrivilege"
142
+ SE_SYSTEMTIME_NAME = "SeSystemtimePrivilege"
143
+ SE_PROF_SINGLE_PROCESS_NAME = "SeProfileSingleProcessPrivilege"
144
+ SE_INC_BASE_PRIORITY_NAME = "SeIncreaseBasePriorityPrivilege"
145
+ SE_CREATE_PAGEFILE_NAME = "SeCreatePagefilePrivilege"
146
+ SE_CREATE_PERMANENT_NAME = "SeCreatePermanentPrivilege"
147
+ SE_BACKUP_NAME = "SeBackupPrivilege"
148
+ SE_RESTORE_NAME = "SeRestorePrivilege"
149
+ SE_SHUTDOWN_NAME = "SeShutdownPrivilege"
150
+ SE_DEBUG_NAME = "SeDebugPrivilege"
151
+ SE_AUDIT_NAME = "SeAuditPrivilege"
152
+ SE_SYSTEM_ENVIRONMENT_NAME = "SeSystemEnvironmentPrivilege"
153
+ SE_CHANGE_NOTIFY_NAME = "SeChangeNotifyPrivilege"
154
+ SE_REMOTE_SHUTDOWN_NAME = "SeRemoteShutdownPrivilege"
155
+ SE_UNDOCK_NAME = "SeUndockPrivilege"
156
+ SE_SYNC_AGENT_NAME = "SeSyncAgentPrivilege"
157
+ SE_ENABLE_DELEGATION_NAME = "SeEnableDelegationPrivilege"
158
+ SE_MANAGE_VOLUME_NAME = "SeManageVolumePrivilege"
159
+ SE_IMPERSONATE_NAME = "SeImpersonatePrivilege"
160
+ SE_CREATE_GLOBAL_NAME = "SeCreateGlobalPrivilege"
161
+
129
162
  ACCESS_MIN_MS_ACE_TYPE = 0x0
130
163
  ACCESS_ALLOWED_ACE_TYPE = 0x0
131
164
  ACCESS_DENIED_ACE_TYPE = 0x1
@@ -161,6 +194,7 @@ module Windows
161
194
  FAILED_ACCESS_ACE_FLAG = 0x80
162
195
 
163
196
  # Standard Access Rights
197
+
164
198
  DELETE = 0x00010000
165
199
  READ_CONTROL = 0x20000
166
200
  WRITE_DAC = 0x40000
@@ -180,6 +214,7 @@ module Windows
180
214
  GENERIC_ALL = 0x10000000
181
215
 
182
216
  # Enum SidNameUse
217
+
183
218
  SidTypeUser = 1
184
219
  SidTypeGroup = 2
185
220
  SidTypeDomain = 3
@@ -191,6 +226,7 @@ module Windows
191
226
  SidTypeComputer = 9
192
227
 
193
228
  # Enum TokenInformationClass
229
+
194
230
  TokenUser = 1
195
231
  TokenGroups = 2
196
232
  TokenPrivileges = 3
@@ -222,6 +258,7 @@ module Windows
222
258
  MaxTokenInfoClass = 29
223
259
 
224
260
  # Enum WellKnownSidType
261
+
225
262
  WinNullSid = 0
226
263
  WinWorldSid = 1
227
264
  WinLocalSid = 2
data/lib/windows/shell.rb CHANGED
@@ -151,10 +151,20 @@ module Windows
151
151
  API.new('ShellExecuteEx', 'P', 'B', 'shell32')
152
152
  API.new('SHFileOperation', 'P', 'I', 'shell32')
153
153
  API.new('SHGetFileInfo', 'PLPII', 'L', 'shell32')
154
+ API.new('SHGetFolderLocation', 'LILLP', 'L', 'shell32')
154
155
  API.new('SHGetFolderPath', 'LLLLP', 'L', 'shell32')
155
156
  API.new('SHGetNewLinkInfo', 'PPPPI', 'B', 'shell32')
156
157
  API.new('SHGetPathFromIDList', 'LL', 'B', 'shell32')
157
158
  API.new('SHGetSpecialFolderLocation', 'LIP', 'L', 'shell32')
158
159
  API.new('SHGetSpecialFolderPath', 'LPLL','L', 'shell32')
160
+
161
+ # Windows Vista
162
+ begin
163
+ API.new('SHGetKnownFolderPath', 'LLLP', 'L', 'shell32')
164
+ API.new('SHGetKnownFolderIDList', 'LLLP', 'L', 'shell32')
165
+ API.new('SHGetNameFromIDList', 'PLP', 'L', 'shell32')
166
+ rescue Windows::API::Error
167
+ # Not supported on your platform
168
+ end
159
169
  end
160
170
  end
@@ -8,13 +8,58 @@ module Windows
8
8
  API.auto_unicode = true
9
9
 
10
10
  # Obsolete processor info constants
11
+
11
12
  PROCESSOR_INTEL_386 = 386
12
13
  PROCESSOR_INTEL_486 = 486
13
14
  PROCESSOR_INTEL_PENTIUM = 586
14
15
  PROCESSOR_INTEL_IA64 = 2200
15
16
  PROCESSOR_AMD_X8664 = 8664
16
17
 
18
+ # Suite mask constants
19
+
20
+ VER_SERVER_NT = 0x80000000
21
+ VER_WORKSTATION_NT = 0x40000000
22
+ VER_SUITE_SMALLBUSINESS = 0x00000001
23
+ VER_SUITE_ENTERPRISE = 0x00000002
24
+ VER_SUITE_BACKOFFICE = 0x00000004
25
+ VER_SUITE_COMMUNICATIONS = 0x00000008
26
+ VER_SUITE_TERMINAL = 0x00000010
27
+ VER_SUITE_SMALLBUSINESS_RESTRICTED = 0x00000020
28
+ VER_SUITE_EMBEDDEDNT = 0x00000040
29
+ VER_SUITE_DATACENTER = 0x00000080
30
+ VER_SUITE_SINGLEUSERTS = 0x00000100
31
+ VER_SUITE_PERSONAL = 0x00000200
32
+ VER_SUITE_BLADE = 0x00000400
33
+ VER_SUITE_EMBEDDED_RESTRICTED = 0x00000800
34
+ VER_SUITE_SECURITY_APPLIANCE = 0x00001000
35
+ VER_SUITE_STORAGE_SERVER = 0x00002000
36
+ VER_SUITE_COMPUTE_SERVER = 0x00004000
37
+
38
+ # Product mask constants
39
+
40
+ VER_NT_WORKSTATION = 0x0000001
41
+ VER_NT_DOMAIN_CONTROLLER = 0x0000002
42
+ VER_NT_SERVER = 0x0000003
43
+
44
+ # Platform definitions
45
+
46
+ VER_PLATFORM_WIN32s = 0
47
+ VER_PLATFORM_WIN32_WINDOWS = 1
48
+ VER_PLATFORM_WIN32_NT = 2
49
+
50
+ # Version info type constants
51
+
52
+ VER_MINORVERSION = 0x0000001
53
+ VER_MAJORVERSION = 0x0000002
54
+ VER_BUILDNUMBER = 0x0000004
55
+ VER_PLATFORMID = 0x0000008
56
+ VER_SERVICEPACKMINOR = 0x0000010
57
+ VER_SERVICEPACKMAJOR = 0x0000020
58
+ VER_SUITENAME = 0x0000040
59
+ VER_PRODUCT_TYPE = 0x0000080
60
+
17
61
  # Enum COMPUTER_NAME_FORMAT
62
+
18
63
  ComputerNameNetBIOS = 0
19
64
  ComputerNameDnsHostname = 1
20
65
  ComputerNameDnsDomain = 2
@@ -41,5 +86,128 @@ module Windows
41
86
  rescue Windows::API::Error
42
87
  # Do nothing. Users must check for function.
43
88
  end
89
+
90
+ # These macros are from windef.h, but I've put them here for now
91
+ # since they can be used in conjunction with some of the functions
92
+ # declared in this module.
93
+
94
+ def MAKEWORD(a, b)
95
+ ((a & 0xff) | (b & 0xff)) << 8
96
+ end
97
+
98
+ def MAKELONG(a, b)
99
+ ((a & 0xffff) | (b & 0xffff)) << 16
100
+ end
101
+
102
+ def LOWORD(l)
103
+ l & 0xffff
104
+ end
105
+
106
+ def HIWORD(l)
107
+ l >> 16
108
+ end
109
+
110
+ def LOBYTE(w)
111
+ w & 0xff
112
+ end
113
+
114
+ def HIBYTE(w)
115
+ w >> 8
116
+ end
117
+
118
+ # Custom methods that may come in handy
119
+
120
+ # Returns true if the current platform is Vista (any variant) or Windows
121
+ # Server 2008, i.e. major version 6, minor version 0.
122
+ #
123
+ def windows_2000?
124
+ version = GetVersion()
125
+ LOBYTE(LOWORD(version)) == 5 && HIBYTE(LOWORD(version)) == 0
126
+ end
127
+
128
+ # Returns true if the current platform is Windows XP or Windows XP
129
+ # Pro, i.e. major version 5, minor version 1 (or 2 in the case of a
130
+ # 64-bit Windows XP Pro).
131
+ #--
132
+ # Because of the exception for a 64-bit Windows XP Pro, we have to
133
+ # to do things the hard way. For version 2 we look for any of the
134
+ # suite masks that might be associated with Windows 2003. If we don't
135
+ # find any of them, assume it's Windows XP.
136
+ #
137
+ def windows_xp?
138
+ bool = false
139
+
140
+ buf = 0.chr * 156
141
+ buf[0,4] = [buf.size].pack("L") # Set dwOSVersionInfoSize
142
+
143
+ GetVersionEx(buf)
144
+
145
+ major = buf[4,4].unpack("L")[0]
146
+ minor = buf[8,4].unpack("L")[0]
147
+ suite = buf[152,2].unpack("S")[0]
148
+
149
+ # Make sure we detect a 64-bit Windows XP Pro
150
+ if major == 5
151
+ if minor == 1
152
+ bool = true
153
+ elsif minor == 2
154
+ if (suite & VER_SUITE_BLADE == 0) &&
155
+ (suite & VER_SUITE_COMPUTE_SERVER == 0) &&
156
+ (suite & VER_SUITE_DATACENTER == 0) &&
157
+ (suite & VER_SUITE_ENTERPRISE == 0) &&
158
+ (suite & VER_SUITE_STORAGE_SERVER == 0)
159
+ then
160
+ bool = true
161
+ end
162
+ else
163
+ # Do nothing - already false
164
+ end
165
+ end
166
+
167
+ bool
168
+ end
169
+
170
+ # Returns true if the current platform is Windows 2003 (any version).
171
+ # i.e. major version 5, minor version 2.
172
+ #--
173
+ # Because of the exception for a 64-bit Windows XP Pro, we have to
174
+ # to do things the hard way. For version 2 we look for any of the
175
+ # suite masks that might be associated with Windows 2003. If we find
176
+ # any of them, assume it's Windows 2003.
177
+ #
178
+ def windows_2003?
179
+ bool = false
180
+
181
+ buf = 0.chr * 156
182
+ buf[0,4] = [buf.size].pack("L") # Set dwOSVersionInfoSize
183
+
184
+ GetVersionEx(buf)
185
+
186
+ major = buf[4,4].unpack("L")[0]
187
+ minor = buf[8,4].unpack("L")[0]
188
+ suite = buf[152,2].unpack("S")[0]
189
+
190
+ # Make sure we exclude a 64-bit Windows XP Pro
191
+ if major == 5 && minor == 2
192
+ if (suite & VER_SUITE_BLADE > 0) ||
193
+ (suite & VER_SUITE_COMPUTE_SERVER > 0) ||
194
+ (suite & VER_SUITE_DATACENTER > 0) ||
195
+ (suite & VER_SUITE_ENTERPRISE > 0) ||
196
+ (suite & VER_SUITE_STORAGE_SERVER > 0)
197
+ then
198
+ bool = true
199
+ end
200
+ end
201
+
202
+ bool
203
+ end
204
+
205
+ # Returns true if the current platform is Windows Vista (any variant)
206
+ # or Windows Server 2008, i.e. major version 6, minor version 0.
207
+ #
208
+ def windows_vista?
209
+ version = GetVersion()
210
+ LOBYTE(LOWORD(version)) == 6 && HIBYTE(LOWORD(version)) == 0
211
+ end
44
212
  end
45
213
  end
@@ -123,6 +123,9 @@ module Windows
123
123
  encoding = ($KCODE == 'UTF8') ? CP_UTF8 : CP_ACP
124
124
  end
125
125
 
126
+ # Add a trailing double null if necessary
127
+ wstring << "\000\000" if wstring[-1].chr != "\000"
128
+
126
129
  int = WideCharToMultiByte(encoding, 0, wstring, -1, 0, 0, nil, nil)
127
130
 
128
131
  # Trailing nulls are stripped
@@ -29,6 +29,13 @@ class TC_Windows_SystemInfo < Test::Unit::TestCase
29
29
  assert_not_nil(SystemInfoFoo::GetComputerNameEx)
30
30
  assert_not_nil(SystemInfoFoo::GetSystemInfo)
31
31
  end
32
+
33
+ def test_custom_boolean_methods
34
+ assert_respond_to(@foo, :windows_2000?)
35
+ assert_respond_to(@foo, :windows_xp?)
36
+ assert_respond_to(@foo, :windows_2003?)
37
+ assert_respond_to(@foo, :windows_vista?)
38
+ end
32
39
 
33
40
  def teardown
34
41
  @foo = nil
data/windows-pr.gemspec CHANGED
@@ -2,7 +2,7 @@ require "rubygems"
2
2
 
3
3
  spec = Gem::Specification.new do |gem|
4
4
  gem.name = "windows-pr"
5
- gem.version = "0.9.3"
5
+ gem.version = "0.9.4"
6
6
  gem.authors = ["Daniel J. Berger", "Park Heesob"]
7
7
  gem.email = "djberg96@gmail.com"
8
8
  gem.homepage = "http://www.rubyforge.org/projects/win32utils"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: windows-pr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-09-12 00:00:00 -06:00
13
+ date: 2008-09-28 00:00:00 -06:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  requirements: []
168
168
 
169
169
  rubyforge_project: win32utils
170
- rubygems_version: 1.2.0
170
+ rubygems_version: 1.3.0
171
171
  signing_key:
172
172
  specification_version: 2
173
173
  summary: Windows functions and constants bundled via Win32::API