1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 """
29 Debugging API wrappers in ctypes.
30
31 @see: U{http://apps.sourceforge.net/trac/winappdbg/wiki/Win32APIWrappers}
32 """
33
34 __revision__ = "$Id: shlwapi.py 440 2009-11-11 01:28:34Z QvasiModo $"
35
36 from defines import *
37
38 OS_WINDOWS = 0
39 OS_NT = 1
40 OS_WIN95ORGREATER = 2
41 OS_NT4ORGREATER = 3
42 OS_WIN98ORGREATER = 5
43 OS_WIN98_GOLD = 6
44 OS_WIN2000ORGREATER = 7
45 OS_WIN2000PRO = 8
46 OS_WIN2000SERVER = 9
47 OS_WIN2000ADVSERVER = 10
48 OS_WIN2000DATACENTER = 11
49 OS_WIN2000TERMINAL = 12
50 OS_EMBEDDED = 13
51 OS_TERMINALCLIENT = 14
52 OS_TERMINALREMOTEADMIN = 15
53 OS_WIN95_GOLD = 16
54 OS_MEORGREATER = 17
55 OS_XPORGREATER = 18
56 OS_HOME = 19
57 OS_PROFESSIONAL = 20
58 OS_DATACENTER = 21
59 OS_ADVSERVER = 22
60 OS_SERVER = 23
61 OS_TERMINALSERVER = 24
62 OS_PERSONALTERMINALSERVER = 25
63 OS_FASTUSERSWITCHING = 26
64 OS_WELCOMELOGONUI = 27
65 OS_DOMAINMEMBER = 28
66 OS_ANYSERVER = 29
67 OS_WOW6432 = 30
68 OS_WEBSERVER = 31
69 OS_SMALLBUSINESSSERVER = 32
70 OS_TABLETPC = 33
71 OS_SERVERADMINUI = 34
72 OS_MEDIACENTER = 35
73 OS_APPLIANCE = 36
74
75
76
77
78
79
95
96
97
98
100 _PathAddBackslashA = windll.shlwapi.PathAddBackslashA
101 _PathAddBackslashA.argtypes = [LPSTR]
102 _PathAddBackslashA.restype = LPSTR
103
104 lpszPath = ctypes.create_string_buffer(lpszPath, MAX_PATH)
105 retval = _PathAddBackslashA(lpszPath)
106 if retval == NULL:
107 raise ctypes.WinError()
108 return lpszPath.value
109
111 _PathAddBackslashW = windll.shlwapi.PathAddBackslashW
112 _PathAddBackslashW.argtypes = [LPWSTR]
113 _PathAddBackslashW.restype = LPWSTR
114
115 lpszPath = ctypes.create_unicode_buffer(lpszPath, MAX_PATH)
116 retval = _PathAddBackslashW(lpszPath)
117 if retval == NULL:
118 raise ctypes.WinError()
119 return lpszPath.value
120
121 PathAddBackslash = GuessStringType(PathAddBackslashA, PathAddBackslashW)
122
123
124
125
126
128 _PathAddExtensionA = windll.shlwapi.PathAddExtensionA
129 _PathAddExtensionA.argtypes = [LPSTR, LPSTR]
130 _PathAddExtensionA.restype = bool
131 _PathAddExtensionA.errcheck = RaiseIfZero
132
133 if not pszExtension:
134 pszExtension = None
135 lpszPath = ctypes.create_string_buffer(lpszPath, MAX_PATH)
136 _PathAddExtensionA(lpszPath, pszExtension)
137 return lpszPath.value
138
140 _PathAddExtensionW = windll.shlwapi.PathAddExtensionW
141 _PathAddExtensionW.argtypes = [LPWSTR, LPWSTR]
142 _PathAddExtensionW.restype = bool
143 _PathAddExtensionW.errcheck = RaiseIfZero
144
145 if not pszExtension:
146 pszExtension = None
147 lpszPath = ctypes.create_unicode_buffer(lpszPath, MAX_PATH)
148 _PathAddExtensionW(lpszPath, pszExtension)
149 return lpszPath.value
150
151 PathAddExtension = GuessStringType(PathAddExtensionA, PathAddExtensionW)
152
153
154
155
156
158 _PathAppendA = windll.shlwapi.PathAppendA
159 _PathAppendA.argtypes = [LPSTR, LPSTR]
160 _PathAppendA.restype = bool
161 _PathAppendA.errcheck = RaiseIfZero
162
163 if not pszMore:
164 pszMore = None
165 lpszPath = ctypes.create_string_buffer(lpszPath, MAX_PATH)
166 _PathAppendA(lpszPath, pszMore)
167 return lpszPath.value
168
170 _PathAppendW = windll.shlwapi.PathAppendW
171 _PathAppendW.argtypes = [LPWSTR, LPWSTR]
172 _PathAppendW.restype = bool
173 _PathAppendW.errcheck = RaiseIfZero
174
175 if not pszMore:
176 pszMore = None
177 lpszPath = ctypes.create_unicode_buffer(lpszPath, MAX_PATH)
178 _PathAppendW(lpszPath, pszMore)
179 return lpszPath.value
180
181 PathAppend = GuessStringType(PathAppendA, PathAppendW)
182
183
184
185
186
187
189 _PathCombineA = windll.shlwapi.PathCombineA
190 _PathCombineA.argtypes = [LPSTR, LPSTR, LPSTR]
191 _PathCombineA.restype = LPSTR
192
193 lpszDest = ctypes.create_string_buffer("", max(MAX_PATH, len(lpszDir) + len(lpszFile) + 1))
194 retval = _PathCombineA(lpszDest, lpszDir, lpszFile)
195 if retval == NULL:
196 return None
197 return lpszDest.value
198
200 _PathCombineW = windll.shlwapi.PathCombineW
201 _PathCombineW.argtypes = [LPWSTR, LPWSTR, LPWSTR]
202 _PathCombineW.restype = LPWSTR
203
204 lpszDest = ctypes.create_unicode_buffer(u"", max(MAX_PATH, len(lpszDir) + len(lpszFile) + 1))
205 retval = _PathCombineW(lpszDest, lpszDir, lpszFile)
206 if retval == NULL:
207 return None
208 return lpszDest.value
209
210 PathCombine = GuessStringType(PathCombineA, PathCombineW)
211
212
213
214
215
217 _PathCanonicalizeA = windll.shlwapi.PathCanonicalizeA
218 _PathCanonicalizeA.argtypes = [LPSTR, LPSTR]
219 _PathCanonicalizeA.restype = bool
220 _PathCanonicalizeA.errcheck = RaiseIfZero
221
222 lpszDst = ctypes.create_string_buffer("", MAX_PATH)
223 _PathCanonicalizeA(lpszDst, lpszSrc)
224 return lpszDst.value
225
227 _PathCanonicalizeW = windll.shlwapi.PathCanonicalizeW
228 _PathCanonicalizeW.argtypes = [LPWSTR, LPWSTR]
229 _PathCanonicalizeW.restype = bool
230 _PathCanonicalizeW.errcheck = RaiseIfZero
231
232 lpszDst = ctypes.create_unicode_buffer(u"", MAX_PATH)
233 _PathCanonicalizeW(lpszDst, lpszSrc)
234 return lpszDst.value
235
236 PathCanonicalize = GuessStringType(PathCanonicalizeA, PathCanonicalizeW)
237
238
239
240
242 _PathFileExistsA = windll.shlwapi.PathFileExistsA
243 _PathFileExistsA.argtypes = [LPSTR]
244 _PathFileExistsA.restype = bool
245 return _PathFileExistsA(pszPath)
246
248 _PathFileExistsW = windll.shlwapi.PathFileExistsW
249 _PathFileExistsW.argtypes = [LPWSTR]
250 _PathFileExistsW.restype = bool
251 return _PathFileExistsW(pszPath)
252
253 PathFileExists = GuessStringType(PathFileExistsA, PathFileExistsW)
254
255
256
257
259 _PathFindExtensionA = windll.shlwapi.PathFindExtensionA
260 _PathFindExtensionA.argtypes = [LPSTR]
261 _PathFindExtensionA.restype = LPSTR
262 pszPath = ctypes.create_string_buffer(pszPath)
263 return _PathFindExtensionA(pszPath)
264
266 _PathFindExtensionW = windll.shlwapi.PathFindExtensionW
267 _PathFindExtensionW.argtypes = [LPWSTR]
268 _PathFindExtensionW.restype = LPWSTR
269 pszPath = ctypes.create_unicode_buffer(pszPath)
270 return _PathFindExtensionW(pszPath)
271
272 PathFindExtension = GuessStringType(PathFindExtensionA, PathFindExtensionW)
273
274
275
276
278 _PathFindFileNameA = windll.shlwapi.PathFindFileNameA
279 _PathFindFileNameA.argtypes = [LPSTR]
280 _PathFindFileNameA.restype = LPSTR
281 pszPath = ctypes.create_string_buffer(pszPath)
282 return _PathFindFileNameA(pszPath)
283
285 _PathFindFileNameW = windll.shlwapi.PathFindFileNameW
286 _PathFindFileNameW.argtypes = [LPWSTR]
287 _PathFindFileNameW.restype = LPWSTR
288 pszPath = ctypes.create_unicode_buffer(pszPath)
289 return _PathFindFileNameW(pszPath)
290
291 PathFindFileName = GuessStringType(PathFindFileNameA, PathFindFileNameW)
292
293
294
295
297 _PathFindNextComponentA = windll.shlwapi.PathFindNextComponentA
298 _PathFindNextComponentA.argtypes = [LPSTR]
299 _PathFindNextComponentA.restype = LPSTR
300 pszPath = ctypes.create_string_buffer(pszPath)
301 return _PathFindNextComponentA(pszPath)
302
304 _PathFindNextComponentW = windll.shlwapi.PathFindNextComponentW
305 _PathFindNextComponentW.argtypes = [LPWSTR]
306 _PathFindNextComponentW.restype = LPWSTR
307 pszPath = ctypes.create_unicode_buffer(pszPath)
308 return _PathFindNextComponentW(pszPath)
309
310 PathFindNextComponent = GuessStringType(PathFindNextComponentA, PathFindNextComponentW)
311
312
313
314
315
317 _PathFindOnPathA = windll.shlwapi.PathFindOnPathA
318 _PathFindOnPathA.argtypes = [LPSTR, LPSTR]
319 _PathFindOnPathA.restype = bool
320
321 pszFile = ctypes.create_string_buffer(pszFile, MAX_PATH)
322 if not ppszOtherDirs:
323 ppszOtherDirs = None
324 else:
325 szArray = ""
326 for pszOtherDirs in ppszOtherDirs:
327 if pszOtherDirs:
328 szArray = "%s%s\0" % (szArray, pszOtherDirs)
329 szArray = szArray + "\0"
330 pszOtherDirs = ctypes.create_string_buffer(szArray)
331 ppszOtherDirs = ctypes.pointer(pszOtherDirs)
332 if _PathFindOnPathA(pszFile, ppszOtherDirs):
333 return pszFile.value
334 return None
335
337 _PathFindOnPathW = windll.shlwapi.PathFindOnPathA
338 _PathFindOnPathW.argtypes = [LPWSTR, LPWSTR]
339 _PathFindOnPathW.restype = bool
340
341 pszFile = ctypes.create_unicode_buffer(pszFile, MAX_PATH)
342 if not ppszOtherDirs:
343 ppszOtherDirs = None
344 else:
345 szArray = u""
346 for pszOtherDirs in ppszOtherDirs:
347 if pszOtherDirs:
348 szArray = u"%s%s\0" % (szArray, pszOtherDirs)
349 szArray = szArray + u"\0"
350 pszOtherDirs = ctypes.create_unicode_buffer(szArray)
351 ppszOtherDirs = ctypes.pointer(pszOtherDirs)
352 if _PathFindOnPathW(pszFile, ppszOtherDirs):
353 return pszFile.value
354 return None
355
356 PathFindOnPath = GuessStringType(PathFindOnPathA, PathFindOnPathW)
357
358
359
360
362 _PathGetArgsA = windll.shlwapi.PathGetArgsA
363 _PathGetArgsA.argtypes = [LPSTR]
364 _PathGetArgsA.restype = LPSTR
365 pszPath = ctypes.create_string_buffer(pszPath)
366 return _PathGetArgsA(pszPath)
367
369 _PathGetArgsW = windll.shlwapi.PathGetArgsW
370 _PathGetArgsW.argtypes = [LPWSTR]
371 _PathGetArgsW.restype = LPWSTR
372 pszPath = ctypes.create_unicode_buffer(pszPath)
373 return _PathGetArgsW(pszPath)
374
375 PathGetArgs = GuessStringType(PathGetArgsA, PathGetArgsW)
376
377
378
379
380
381 -def PathIsContentTypeA(pszPath, pszContentType):
382 _PathIsContentTypeA = windll.shlwapi.PathIsContentTypeA
383 _PathIsContentTypeA.argtypes = [LPSTR, LPSTR]
384 _PathIsContentTypeA.restype = bool
385 return _PathIsContentTypeA(pszPath, pszContentType)
386
387 -def PathIsContentTypeW(pszPath, pszContentType):
388 _PathIsContentTypeW = windll.shlwapi.PathIsContentTypeW
389 _PathIsContentTypeW.argtypes = [LPWSTR, LPWSTR]
390 _PathIsContentTypeW.restype = bool
391 return _PathIsContentTypeW(pszPath, pszContentType)
392
393 PathIsContentType = GuessStringType(PathIsContentTypeA, PathIsContentTypeW)
394
395
396
397
399 _PathIsDirectoryA = windll.shlwapi.PathIsDirectoryA
400 _PathIsDirectoryA.argtypes = [LPSTR]
401 _PathIsDirectoryA.restype = bool
402 return _PathIsDirectoryA(pszPath)
403
405 _PathIsDirectoryW = windll.shlwapi.PathIsDirectoryW
406 _PathIsDirectoryW.argtypes = [LPWSTR]
407 _PathIsDirectoryW.restype = bool
408 return _PathIsDirectoryW(pszPath)
409
410 PathIsDirectory = GuessStringType(PathIsDirectoryA, PathIsDirectoryW)
411
412
413
414
416 _PathIsDirectoryEmptyA = windll.shlwapi.PathIsDirectoryEmptyA
417 _PathIsDirectoryEmptyA.argtypes = [LPSTR]
418 _PathIsDirectoryEmptyA.restype = bool
419 return _PathIsDirectoryEmptyA(pszPath)
420
422 _PathIsDirectoryEmptyW = windll.shlwapi.PathIsDirectoryEmptyW
423 _PathIsDirectoryEmptyW.argtypes = [LPWSTR]
424 _PathIsDirectoryEmptyW.restype = bool
425 return _PathIsDirectoryEmptyW(pszPath)
426
427 PathIsDirectoryEmpty = GuessStringType(PathIsDirectoryEmptyA, PathIsDirectoryEmptyW)
428
429
430
431
433 _PathIsNetworkPathA = windll.shlwapi.PathIsNetworkPathA
434 _PathIsNetworkPathA.argtypes = [LPSTR]
435 _PathIsNetworkPathA.restype = bool
436 return _PathIsNetworkPathA(pszPath)
437
439 _PathIsNetworkPathW = windll.shlwapi.PathIsNetworkPathW
440 _PathIsNetworkPathW.argtypes = [LPWSTR]
441 _PathIsNetworkPathW.restype = bool
442 return _PathIsNetworkPathW(pszPath)
443
444 PathIsNetworkPath = GuessStringType(PathIsNetworkPathA, PathIsNetworkPathW)
445
446
447
448
450 _PathIsRelativeA = windll.shlwapi.PathIsRelativeA
451 _PathIsRelativeA.argtypes = [LPSTR]
452 _PathIsRelativeA.restype = bool
453 return _PathIsRelativeA(pszPath)
454
456 _PathIsRelativeW = windll.shlwapi.PathIsRelativeW
457 _PathIsRelativeW.argtypes = [LPWSTR]
458 _PathIsRelativeW.restype = bool
459 return _PathIsRelativeW(pszPath)
460
461 PathIsRelative = GuessStringType(PathIsRelativeA, PathIsRelativeW)
462
463
464
465
467 _PathIsRootA = windll.shlwapi.PathIsRootA
468 _PathIsRootA.argtypes = [LPSTR]
469 _PathIsRootA.restype = bool
470 return _PathIsRootA(pszPath)
471
473 _PathIsRootW = windll.shlwapi.PathIsRootW
474 _PathIsRootW.argtypes = [LPWSTR]
475 _PathIsRootW.restype = bool
476 return _PathIsRootW(pszPath)
477
478 PathIsRoot = GuessStringType(PathIsRootA, PathIsRootW)
479
480
481
482
483
485 _PathIsSameRootA = windll.shlwapi.PathIsSameRootA
486 _PathIsSameRootA.argtypes = [LPSTR, LPSTR]
487 _PathIsSameRootA.restype = bool
488 return _PathIsSameRootA(pszPath1, pszPath2)
489
491 _PathIsSameRootW = windll.shlwapi.PathIsSameRootW
492 _PathIsSameRootW.argtypes = [LPWSTR, LPWSTR]
493 _PathIsSameRootW.restype = bool
494 return _PathIsSameRootW(pszPath1, pszPath2)
495
496 PathIsSameRoot = GuessStringType(PathIsSameRootA, PathIsSameRootW)
497
498
499
500
502 _PathIsUNCA = windll.shlwapi.PathIsUNCA
503 _PathIsUNCA.argtypes = [LPSTR]
504 _PathIsUNCA.restype = bool
505 return _PathIsUNCA(pszPath)
506
508 _PathIsUNCW = windll.shlwapi.PathIsUNCW
509 _PathIsUNCW.argtypes = [LPWSTR]
510 _PathIsUNCW.restype = bool
511 return _PathIsUNCW(pszPath)
512
513 PathIsUNC = GuessStringType(PathIsUNCA, PathIsUNCW)
514
515
516
517
518
519
520
521
523 _PathMakePrettyA = windll.shlwapi.PathMakePrettyA
524 _PathMakePrettyA.argtypes = [LPSTR]
525 _PathMakePrettyA.restype = bool
526 _PathMakePrettyA.errcheck = RaiseIfZero
527
528 pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH)
529 _PathMakePrettyA(pszPath)
530 return pszPath.value
531
533 _PathMakePrettyW = windll.shlwapi.PathMakePrettyW
534 _PathMakePrettyW.argtypes = [LPWSTR]
535 _PathMakePrettyW.restype = bool
536 _PathMakePrettyW.errcheck = RaiseIfZero
537
538 pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH)
539 _PathMakePrettyW(pszPath)
540 return pszPath.value
541
542 PathMakePretty = GuessStringType(PathMakePrettyA, PathMakePrettyW)
543
544
545
546
548 _PathRemoveArgsA = windll.shlwapi.PathRemoveArgsA
549 _PathRemoveArgsA.argtypes = [LPSTR]
550
551 pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH)
552 _PathRemoveArgsA(pszPath)
553 return pszPath.value
554
556 _PathRemoveArgsW = windll.shlwapi.PathRemoveArgsW
557 _PathRemoveArgsW.argtypes = [LPWSTR]
558
559 pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH)
560 _PathRemoveArgsW(pszPath)
561 return pszPath.value
562
563 PathRemoveArgs = GuessStringType(PathRemoveArgsA, PathRemoveArgsW)
564
565
566
567
569 _PathRemoveBackslashA = windll.shlwapi.PathRemoveBackslashA
570 _PathRemoveBackslashA.argtypes = [LPSTR]
571
572 pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH)
573 _PathRemoveBackslashA(pszPath)
574 return pszPath.value
575
577 _PathRemoveBackslashW = windll.shlwapi.PathRemoveBackslashW
578 _PathRemoveBackslashW.argtypes = [LPWSTR]
579
580 pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH)
581 _PathRemoveBackslashW(pszPath)
582 return pszPath.value
583
584 PathRemoveBackslash = GuessStringType(PathRemoveBackslashA, PathRemoveBackslashW)
585
586
587
588
590 _PathRemoveExtensionA = windll.shlwapi.PathRemoveExtensionA
591 _PathRemoveExtensionA.argtypes = [LPSTR]
592
593 pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH)
594 _PathRemoveExtensionA(pszPath)
595 return pszPath.value
596
598 _PathRemoveExtensionW = windll.shlwapi.PathRemoveExtensionW
599 _PathRemoveExtensionW.argtypes = [LPWSTR]
600
601 pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH)
602 _PathRemoveExtensionW(pszPath)
603 return pszPath.value
604
605 PathRemoveExtension = GuessStringType(PathRemoveExtensionA, PathRemoveExtensionW)
606
607
608
609
611 _PathRemoveFileSpecA = windll.shlwapi.PathRemoveFileSpecA
612 _PathRemoveFileSpecA.argtypes = [LPSTR]
613
614 pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH)
615 _PathRemoveFileSpecA(pszPath)
616 return pszPath.value
617
619 _PathRemoveFileSpecW = windll.shlwapi.PathRemoveFileSpecW
620 _PathRemoveFileSpecW.argtypes = [LPWSTR]
621
622 pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH)
623 _PathRemoveFileSpecW(pszPath)
624 return pszPath.value
625
626 PathRemoveFileSpec = GuessStringType(PathRemoveFileSpecA, PathRemoveFileSpecW)
627
628
629
630
631
633 _PathRenameExtensionA = windll.shlwapi.PathRenameExtensionA
634 _PathRenameExtensionA.argtypes = [LPSTR, LPSTR]
635 _PathRenameExtensionA.restype = bool
636
637 pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH)
638 if _PathRenameExtensionA(pszPath, pszExt):
639 return pszPath.value
640 return None
641
643 _PathRenameExtensionW = windll.shlwapi.PathRenameExtensionW
644 _PathRenameExtensionW.argtypes = [LPWSTR, LPWSTR]
645 _PathRenameExtensionW.restype = bool
646
647 pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH)
648 if _PathRenameExtensionW(pszPath, pszExt):
649 return pszPath.value
650 return None
651
652 PathRenameExtension = GuessStringType(PathRenameExtensionA, PathRenameExtensionW)
653
654
655
656
657
658
660 _PathUnExpandEnvStringsA = windll.shlwapi.PathUnExpandEnvStringsA
661 _PathUnExpandEnvStringsA.argtypes = [LPSTR, LPSTR]
662 _PathUnExpandEnvStringsA.restype = bool
663 _PathUnExpandEnvStringsA.errcheck = RaiseIfZero
664
665 cchBuf = MAX_PATH
666 pszBuf = ctypes.create_string_buffer("", cchBuf)
667 _PathUnExpandEnvStringsA(pszPath, pszBuf, cchBuf)
668 return pszBuf.value
669
671 _PathUnExpandEnvStringsW = windll.shlwapi.PathUnExpandEnvStringsW
672 _PathUnExpandEnvStringsW.argtypes = [LPWSTR, LPWSTR]
673 _PathUnExpandEnvStringsW.restype = bool
674 _PathUnExpandEnvStringsW.errcheck = RaiseIfZero
675
676 cchBuf = MAX_PATH
677 pszBuf = ctypes.create_unicode_buffer(u"", cchBuf)
678 _PathUnExpandEnvStringsW(pszPath, pszBuf, cchBuf)
679 return pszBuf.value
680
681 PathUnExpandEnvStrings = GuessStringType(PathUnExpandEnvStringsA, PathUnExpandEnvStringsW)
682