安装后脚本将在本机 Windows 安装例程中运行。
get_special_folder_path
函数,和不是pythonic :例如directory_created
,它们不能被称为关键字-参数对 - 只能在位置上。这些函数在https://github.com/python/cpython/blob/master/PC/bdist_wininst/install.c中定义directory_created
create_shortcut
用于创建快捷方式的例程充当系统接口IShellLink
(shell32.dll 中的“lives”)的包装器,并从第 504 行开始:
static PyObject *CreateShortcut(PyObject *self, PyObject *args)
{...
然后在第 643 行链接:
PyMethodDef meth[] = {
{"create_shortcut", CreateShortcut, METH_VARARGS, NULL},
{"get_special_folder_path", GetSpecialFolderPath, METH_VARARGS, NULL},
...
};
在您的本地安装中,上述 C 代码已经在可执行文件中编译:
C:\Python26\Lib\distutils\command\wininst-6.0.exe
C:\Python26\Lib\distutils\command\wininst-7.1.exe
C:\Python26\Lib\distutils\command\wininst-8.0.exe
C:\Python26\Lib\distutils\command\wininst-9.0.exe
C:\Python26\Lib\distutils\command\wininst-9.0-amd64.exe
所以,回答:没有 python 库来导入函数 create_shortcut(),它只能在 Windows 安装后脚本中按原样使用。
如果您想同时支持自动和手动安装后方案,请查看 pywin32 解决方法:
https://github.com/mhammond/pywin32/blob/master/pywin32_postinstall.py第80行
try:
create_shortcut
except NameError:
# Create a function with the same signature as create_shortcut provided
# by bdist_wininst
def create_shortcut(path, description, filename,
arguments="", workdir="", iconpath="", iconindex=0):
import pythoncom
from win32com.shell import shell, shellcon
ilink = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None,
pythoncom.CLSCTX_INPROC_SERVER,
shell.IID_IShellLink)
ilink.SetPath(path)
ilink.SetDescription(description)
if arguments:
ilink.SetArguments(arguments)
if workdir:
ilink.SetWorkingDirectory(workdir)
if iconpath or iconindex:
ilink.SetIconLocation(iconpath, iconindex)
# now save it.
ipf = ilink.QueryInterface(pythoncom.IID_IPersistFile)
ipf.Save(filename, 0)