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
|
from win32com.shell import shell
import win32api
import pythoncom
import os
import sys
def CreateShortCut(Path, Target,Arguments = "", StartIn = "", Icon = ("",0),
Description = ""):
# Get the shell interface.
sh = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, \
pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
# Get an IPersist interface
persist = sh.QueryInterface(pythoncom.IID_IPersistFile)
# Set the data
sh.SetPath(Target)
sh.SetDescription(Description)
sh.SetArguments(Arguments)
sh.SetWorkingDirectory(StartIn)
sh.SetIconLocation(Icon[0],Icon[1])
# Save the link itself.
persist.Save(Path, 1)
if __name__ == "__main__":
TempDir = os.environ["TEMP"]
WinRoot = os.environ["windir"]
Path = WinRoot + "\\Profiles\\All Users\\Desktop\\New Link.lnk"
Target = Pythonroot + "pythonw.exe "
Arguments = TempDir + "\\test.py"
StartIn = TempDir
Icon = (Pythonroot + "\\py.ico", 0)
Description = "New Link"
CreateShortCut(Path,Target,Arguments,StartIn,Icon,Description) |
Partager