你随便上网搜搜,都是让你做个bat(Windows)或者sh(Linux)放进自启动文件夹里。
我当时就想:不可以把这些步骤用python实现吗?
于是写了个pyautorun.py(上传不了Pypi😭,总报错):
import sys
class AutoRunError(Exception):
pass
class autorun:
def win7(batname,end='.bat',console='no console'):
try:
if batname==None:
print('batname=None')
elif console=='no console':
with open('C:/Users/Administrator/Appdata/Roaming/Microsoft/Windows/Start Menu/Programs/Startup/'+batname+end,'w') as win7:
path=str(sys.argv)
win7.write('start /B '+path[2:-2])
else:
with open('C:/Users/Administrator/Appdata/Roaming/Microsoft/Windows/Start Menu/Programs/Startup/'+batname+end,'w') as win7:
path=str(sys.argv)
win7.write('start '+path[2:-2])
except PermissionError:
raise AutoRunError('Make bat failed')
def win8(batname,end='.bat',console='no console'):
try:
if batname==None:
print('batname=None')
elif console=='no console':
with open('C:/ProgramData/Microsoft/Windows/Start Menu/Programs/StartUp/'+batname+end,'w') as win8:
path=str(sys.argv)
win8.write('start /B '+path[2:-2])
else:
with open('C:/ProgramData/Microsoft/Windows/Start Menu/Programs/StartUp/'+batname+end,'w') as win8:
path=str(sys.argv)
win7.write('start '+path[2:-2])
except PermissionError:
raise AutoRunError('Make bat failed')
def information():
print("""
This module can start the program after you login on you computer.
But if the computer show you a warning when you use it,please neglect the warning,else the module will show you an exception.
Please remember: Win7Autorun==Win10AutoRun:""")
print('''
If you cannot read english:
此模块可以在您登录计算机后启动程序。
但是,如果计算机在您使用它时显示警告,请忽略警告,否则模块将显示异常。
请记住: Win8自启动==Win10自启动:''')
保存一下。
示例:
from pyautorun import*
from turtle import*
from random import randrange as r
x,y=r(-200,200),r(-200,200)
goto(x,y)
autorun.win7('1')
缺点:
电脑会送你个警告窗口。
请你点是。
如果你不想让此文件启动时,可以删除bat文件,或在“启动应用”目录关闭1.bat。