<unknown> .TargetPath无法设置

时间:2016-08-15 20:07:24

标签: python-2.7 win32com comtypes

我正在尝试编写一个可以在多台目标计算机上部署和远程运行的脚本,最终结果是将现有快捷方式替换为运行完全相同程序但具有高优先级的快捷方式。这是我的剧本:

import os, winshell
from win32com.client import Dispatch
from comtypes.client import CreateObject
# from comtypes.gen import IWshRuntimeLibrary

desktop = winshell.desktop()
path = os.path.join(desktop, 'Test Short.lnk')

target = r'\%HOMEDRIVE%\\Apps\\Ellie Mae\\Encompass\\AppLauncher.exe'
wDir = r'\%HOMEDRIVE%\\Apps\\Ellie Mae\\Encompass'
icon = r'\%SystemRoot%\\Installer\\{3E9C4FBE-4E6C-4389-A4B3-4AE027D0BF2E}\\Icon3E9C4FBE2.ico'

shell = Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(path)
shortcut.TargetPath = target
shortcut.WorkingDirectory = wDir
shortcut.IconLocation = icon
shortcut.save()

我遇到了属性错误,如下所示:

AttributeError: Property '<unknown>.TargetPath' can not be set.

作为参考,here是我获得大部分代码的地方。

我试图搜索一个答案,然后遇到了this个帖子。但是,遵循公认的建议产生:

ImportError: cannot import name IWshRuntimeLibrary

我的困惑来自于为什么我无法将TargetPath属性设置为开头。正如经常发生的那样,似乎来自链接线程的OP和我是报告此问题的唯一两个人。有谁知道为什么会发生这种情况以及我可以做些什么来解决它?

0 个答案:

没有答案