开机自连宽带

开机自动连接宽带以及启动随e行

连接宽带

可以在cmd中使用可以连接宽带

1
rasdial [宽带名称] [用户名] [密码]

获取随e行的句柄

使用Spy++获取软件的句柄

spy++

spy++2

之后用

1
hwnd=win32gui.FindWindow(None, FrameTitle)

参数1 是类

参数2 是标题

这边只用标题找就行(随e行的类会变)

任务计划程序

image-20230214175153874

编写一个bat程序

1
2
3
4
5
@echo off
if "%1" == "h" goto begin
mshta vbscript:createobject("wscript.shell").run("""%~0"" h",0)(window.close)&&exit
:begin
python "D:\py_test\automatic.py"

让其开机启动 注意要使用最高权限运行

完整代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from __future__ import print_function
import pyautogui
import win32con
import win32gui
import os
from pynput.mouse import Button, Controller
import ctypes, sys
import time
#宽带名称 宽带账号 密码
g_adsl_account={
"name":"ZJGSU",
"username":"2012190228",
"password":"123456"}

app_path=r"C:\Program Files (x86)\cmclient\bin\CMClient.exe"

class Adsl(object):
# 初始化
def __init__(self,object):
self.name=object["name"]
self.username=object["username"]
self.password=object["password"]
# 修改基本信息
def set_adsl(self, account):
self.name=account["name"]
self.username=account["username"]
self.password=account["password"]
# 连接
def connect(self):
cmd_str="rasdial %s %s %s"%(self.name,self.username,self.password)
os.system(cmd_str)
#
def disconnect(self):
cmd_str="rasdial %s /disconnect"%self.name
os.system(cmd_str)
def reconnect(self):
self.disconnect()
self.connect()
def open_app(app_dir):
os.startfile(app_dir)
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
if __name__ == '__main__':
auto=Adsl(g_adsl_account)
auto.connect()
#判断是否是管理员权限
if is_admin():
open_app(app_dir=app_path)
else:
if sys.version_info[0] == 3:
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)
else: # in python2.x
ctypes.windll.shell32.ShellExecuteW(None, u"runas", unicode(sys.executable), unicode(__file__), None, 1)
time.sleep(2)
#移动鼠标的位置
pyautogui.moveTo(1120, 508)
pyautogui.click(clicks=1)
FrameTitle="随e行"
hwnd=win32gui.FindWindow(None, FrameTitle)
win32gui.ShowWindow(hwnd, win32con.SW_HIDE)


开机自连宽带
http://example.com/2023/02/25/kai-ji-zi-lian-kuan-dai/
作者
CynicCat
发布于
2023年2月25日
许可协议