Create shortcut files in Windows 7 using Python

前端 未结 5 1123
天命终不由人
天命终不由人 2021-02-08 18:07

Is there a simple way to create shortcuts in Windows 7 on Python? I looked it up online but they did not seem that simple.

I have tried using this simple method:

<
5条回答
  •  执念已碎
    2021-02-08 18:41

    @Casey answer put me on the right track, but I wasted a lot of time before figuring out that you also need to set the working directory (called 'start in' in windows properties). If you do not, your shortcut will work but your application will not find the files it may need from the same folder.

    This resolved all my issues:

                path_input = ''
                path_output = ''
                path_cwd = ''
                path_icon = ''
    
                shell = win32com.client.Dispatch("WScript.Shell")
                shortcut = shell.CreateShortCut(path_output)
                shortcut.Targetpath = path_input
                # shortcut.IconLocation = icon
                shortcut.Workingdirectory = path_cwd
                shortcut.WindowStyle = 1  # 7 - Minimized, 3 - Maximized, 1 - Normal
                shortcut.save()
    

提交回复
热议问题