今天,给大家带来一个自动识别U盘里的密钥运行程序的脚本。
成品:
import os,win32api,time
import easygui as g
Wait_times=0
while True:
Possword_file='H:/HHD/Files/Possword/HHD possword.txt'
Possword_file_result=os.path.exists(Possword_file)
if Possword_file_result==True:
f=open(Possword_file)
Possword_file_content=f.read()
if Possword_file_content=='h+201617':
print('<run>')
print('<wait times:'+str(Wait_times)+'>')
g.msgbox(msg='HHD,欢迎登录!',title='提示',ok_button='好的')
win32api.ShellExecute(0, 'open', r'D:\Program Files\Sublime Text 3 for Python\sublime_text.exe', '','',1)
break
else:
print('<wait>')
Wait_times+=1
time.sleep(0.1)
注:
Possword_file='H:/HHD/Files/Possword/HHD possword.txt'
绿色字体是密钥位置,依实际情况而定。
g.msgbox(msg='HHD,欢迎登录!',title='提示',ok_button='好的')
HHD是用户名称,依实际情况而定。
win32api.ShellExecute(0, 'open', r'D:\Program Files\Sublime Text 3 for Python\sublime_text.exe', '','',1)
'D:\Program Files\Sublime Text 3 for Python\sublime_text.exe'是程序位置,依实际情况而定。