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: shell32.py 343 2009-08-03 22:58:22Z QvasiModo $"
35
36 from defines import *
37 from kernel32 import LocalFree
38
39
40
41
42
43
44
46 _CommandLineToArgvW = windll.shell32.CommandLineToArgvW
47 _CommandLineToArgvW.argtypes = [LPVOID, POINTER(ctypes.c_int)]
48 _CommandLineToArgvW.restype = LPVOID
49
50 if not lpCmdLine:
51 lpCmdLine = None
52 argc = ctypes.c_int(0)
53 vptr = ctypes.windll.shell32.CommandLineToArgvW(lpCmdLine, ctypes.byref(argc))
54 if vptr == NULL:
55 raise ctypes.WinError()
56 argv = vptr
57 try:
58 argc = argc.value
59 if argc <= 0:
60 raise ctypes.WinError()
61 argv = ctypes.cast(argv, ctypes.POINTER(LPWSTR * argc) )
62 argv = [ argv.contents[i] for i in xrange(0, argc) ]
63 finally:
64 if vptr is not None:
65 LocalFree(vptr)
66 return argv
67
68 CommandLineToArgvA = MakeANSIVersion(CommandLineToArgvW)
69 CommandLineToArgv = CommandLineToArgvA
70
71
72
73
74
75
76
77
78
79 -def ShellExecuteA(hwnd = None, lpOperation = None, lpFile = None, lpParameters = None, lpDirectory = None, nShowCmd = None):
80 _ShellExecuteA = windll.shell32.ShellExecuteA
81 _ShellExecuteA.argtypes = [HWND, LPSTR, LPSTR, LPSTR, LPSTR, INT]
82 _ShellExecuteA.restype = HINSTANCE
83
84 if not nShowCmd:
85 nShowCmd = 0
86 success = _ShellExecuteA(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd)
87 success = ctypes.cast(success, c_int)
88 success = success.value
89 if not success > 32:
90 raise ctypes.WinError(success)
91
92 -def ShellExecuteW(hwnd = None, lpOperation = None, lpFile = None, lpParameters = None, lpDirectory = None, nShowCmd = None):
93 _ShellExecuteW = windll.shell32.ShellExecuteW
94 _ShellExecuteW.argtypes = [HWND, LPWSTR, LPWSTR, LPWSTR, LPWSTR, INT]
95 _ShellExecuteW.restype = HINSTANCE
96
97 if not nShowCmd:
98 nShowCmd = 0
99 success = _ShellExecuteW(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd)
100 success = ctypes.cast(success, c_int)
101 success = success.value
102 if not success > 32:
103 raise ctypes.WinError(success)
104
105 ShellExecute = GuessStringType(ShellExecuteA, ShellExecuteW)
106