回答編集履歴
1
コード追記
test
CHANGED
@@ -7,3 +7,81 @@
|
|
7
7
|
|
8
8
|
|
9
9
|
多分アタッチ対象のプロセスへの権限が足りなくてアタッチできない状況だと推測しますが、なかなかややこしい箇所で本を全部そらんじるほどの理解もないので、「本を読んでみてください」とだけお伝えします。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
# 追記
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
Python 3.6ですが、以下のコードで電卓のPIDへアタッチ/デタッチしてみましたが、特別なことをしなくてもエラーにならなかったので、やっぱり権限関連の問題だと思います。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
```python
|
22
|
+
|
23
|
+
'''
|
24
|
+
|
25
|
+
Created on 2017/12/15
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
@author: sakurai
|
30
|
+
|
31
|
+
'''
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
from ctypes import windll
|
36
|
+
|
37
|
+
from ctypes import WinError
|
38
|
+
|
39
|
+
from ctypes import wintypes
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
def assertTrue(result, _, args):
|
46
|
+
|
47
|
+
if not result:
|
48
|
+
|
49
|
+
raise WinError()
|
50
|
+
|
51
|
+
return args
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
DebugActiveProcess = windll.kernel32.DebugActiveProcess
|
58
|
+
|
59
|
+
DebugActiveProcess.restype = wintypes.BOOL
|
60
|
+
|
61
|
+
DebugActiveProcess.argtypes = (wintypes.DWORD, )
|
62
|
+
|
63
|
+
DebugActiveProcess.errcheck = assertTrue
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
DebugActiveProcessStop = windll.kernel32.DebugActiveProcessStop
|
68
|
+
|
69
|
+
DebugActiveProcessStop.restype = wintypes.BOOL
|
70
|
+
|
71
|
+
DebugActiveProcessStop.argtypes = (wintypes.DWORD, )
|
72
|
+
|
73
|
+
DebugActiveProcessStop.errcheck = assertTrue
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
if __name__ == "__main__":
|
80
|
+
|
81
|
+
pid = int(input("PID: "))
|
82
|
+
|
83
|
+
DebugActiveProcess(pid)
|
84
|
+
|
85
|
+
DebugActiveProcessStop(pid)
|
86
|
+
|
87
|
+
```
|