Search code examples
pythonshortcutwin32com

How to create a url shortcut by python


I want to create a shortcut by python pywin32, but the code doesnot work.

the following is my code , I donnot know why i cannot create a shortcut by it ! Please help me check it, thanks for your help~

#-*- coding:utf-8 -*-
import win32com.client

bmurl = unicode(r"http://www.pystack.org/","utf8")
bmpath = unicode(r"C:\Users\moose\Desktop\bm\blog.url","utf8")

ws = win32com.client.Dispatch("wscript.shell")
scut = ws.CreateShortcut(bmpath)
scut.TargetPath=bmurl  
scut.Save

Solution

  • The cause of the error is that Save is a method. You need to call it if you want to perform the corresponding action. Try to replace the last line by

    scut.Save()