python文件自启动

你随便上网搜搜,都是让你做个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。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值