teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

コード追記

2017/12/15 09:40

投稿

YouheiSakurai
YouheiSakurai

スコア6151

answer CHANGED
@@ -2,4 +2,43 @@
2
2
 
3
3
  https://www.google.co.jp/amp/s/www.oreilly.co.jp//books/9784873114484/mobile.html
4
4
 
5
- 多分アタッチ対象のプロセスへの権限が足りなくてアタッチできない状況だと推測しますが、なかなかややこしい箇所で本を全部そらんじるほどの理解もないので、「本を読んでみてください」とだけお伝えします。
5
+ 多分アタッチ対象のプロセスへの権限が足りなくてアタッチできない状況だと推測しますが、なかなかややこしい箇所で本を全部そらんじるほどの理解もないので、「本を読んでみてください」とだけお伝えします。
6
+
7
+ # 追記
8
+
9
+ Python 3.6ですが、以下のコードで電卓のPIDへアタッチ/デタッチしてみましたが、特別なことをしなくてもエラーにならなかったので、やっぱり権限関連の問題だと思います。
10
+
11
+ ```python
12
+ '''
13
+ Created on 2017/12/15
14
+
15
+ @author: sakurai
16
+ '''
17
+
18
+ from ctypes import windll
19
+ from ctypes import WinError
20
+ from ctypes import wintypes
21
+
22
+
23
+ def assertTrue(result, _, args):
24
+ if not result:
25
+ raise WinError()
26
+ return args
27
+
28
+
29
+ DebugActiveProcess = windll.kernel32.DebugActiveProcess
30
+ DebugActiveProcess.restype = wintypes.BOOL
31
+ DebugActiveProcess.argtypes = (wintypes.DWORD, )
32
+ DebugActiveProcess.errcheck = assertTrue
33
+
34
+ DebugActiveProcessStop = windll.kernel32.DebugActiveProcessStop
35
+ DebugActiveProcessStop.restype = wintypes.BOOL
36
+ DebugActiveProcessStop.argtypes = (wintypes.DWORD, )
37
+ DebugActiveProcessStop.errcheck = assertTrue
38
+
39
+
40
+ if __name__ == "__main__":
41
+ pid = int(input("PID: "))
42
+ DebugActiveProcess(pid)
43
+ DebugActiveProcessStop(pid)
44
+ ```