1

I'm attempting to write a script that can be deployed and remotely run on a number of target computers with the end result of having an existing shortcut replaced by one that runs the exact same program, but at high priority. Here is my script:

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()

I'm running into an Attribute error, as follows:

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

For reference, here is where I got most of my code.

I attempted to search out an answer, and I came across this thread. However, following the accepted suggestion yields:

ImportError: cannot import name IWshRuntimeLibrary

My confusion comes from why I'm not able to set the TargetPath property to begin with. As happens so often, it seems as if the OP from the linked thread and I are the only two people reporting this problem. Does anyone know why that might be happening and what I can do to fix it?

Community
  • 1
  • 1
Inagnikai
  • 281
  • 1
  • 15

0 Answers0