python 实现将网站添加到桌面快捷方式

class ToDeskHandler(BaseHandler):
    def get(self):
        content = '''[InternetShortcut] 
                        URL=http://idealclub.sinaapp.com 
                        IDList=
                        IconFile=http://idealclub.sinaapp.com/favicon.ico
                        [{000214A0-0000-0000-C000-000000000046}]
                        Prop3=19,2'''

        self.set_header("Content-Type","application/octet-stream")
        self.set_header("Content-Disposition","attachment; filename=饭否.url")
        self.write(content)
1.请将favicon.ico文件放置在网站根目录下。
2.用ie访问网站,将图标缓存至本地。
这样就可以在快捷方式上显示网站图标了。
好的,以下是用 Python 实现定时自动登录远程桌面的程序代码: ``` python import os import time import win32api, win32con def login(): username = "your_username" password = "your_password" os.system("cmd /c net use \\\\remote_computer\\ipc$ " + password + " /user:" + username) os.system("cmd /c mstsc /v:remote_computer /f /console") # 远程桌面连接命令 def set_autostart(): appdata = os.getenv("APPDATA") # 获取当前用户的 AppData 文件夹路径 filepath = appdata + "\\Microsoft\\Windows\\Start Menu\\Programs\\Startup" # StartUp 文件夹路径 shortcut_path = os.path.join(filepath, "auto_login.lnk") # 快捷方式路径 if os.path.exists(shortcut_path): # 如果快捷方式已经存在,删除旧文件 os.unlink(shortcut_path) target_path = os.path.abspath(__file__) # 获取本文件绝对路径,作为目标路径 win32api.ShellExecute( 0, "create", # 创建快捷方式 target_path, None, "", os.path.dirname(target_path), 0 ) print("已将程序添加到自启动项") if __name__ == "__main__": set_autostart() # 添加到自启动项 while True: now = time.localtime() if now.tm_hour == 8 and now.tm_min == 0: # 设置起床时间 login() time.sleep(60) # 一分钟检查一次 ``` 需要安装 `win32api` 和 `win32con` 这两个库才能调用 Windows 的 API 来创建快捷方式。你可以通过 `pip install pywin32` 命令来安装它们。如果不需要添加到自启动项,可以把 `set_autostart()` 函数和最后的 `while` 循环删掉,手动双击运行该脚本即可。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值