起因
今日我用 Python 写了一个论坛自动签到脚本,并把它放在了电脑上,准备每天运行一次,这样就不用去论坛签到了。
但是很快我就发现不对了——既然我还需要每天打开电脑运行一次,为什么不直接在手机上打开浏览器访问论坛然后签到呢?这显得这个脚本很多余。
但是由于我是学生党,并不能天天玩到手机,因此把这个脚本挂在一台每天开启的电脑上就显得尤为重要了。
但是用 Python 写的程序并不能直接运行,而是需要在命令提示符里运行,那该怎么办呢?这就需要批处理文件(.bat)出马了
食用
创建文件
首先,我们在随便一个地方创建一个文件,把它的名字改为"xxx.bat",然后用记事本打开。

在里面我们输入以下代码(不要照抄,看着注释改):
D: % Python 脚本所在盘符 %
cd run % Python 脚本所在文件夹,我的文件在 D:\run 所以填 run %
python run.py %运行 Python 脚本,我的 Python 脚本叫run.py,所以填 run.py %

开机自启动
右击“计算机”选择“管理“

依次点击“系统工具”、“任务计划程序库”和“任务计划程序库”,然后再点击右边的“创建基本任务”

名称、描述随便填,填完点击“下一步”

“计算机启动时”和“当前任务登录时”都可以,选择完了之后点击“下一步”。

选择“启动程序”,然后点击“下一步”。

在“程序或脚本”下填写刚刚你创建的批处理文件的位置,然后点击“下一步”。

确认无误后,点击“完成”。

大功告成 :)
Comments 4 条评论
还在用win7的屑
@小萝卜 不是我的电脑()
要是早好几年看这个教程就好了
@小熊 好奇发生什么了