"Programs/StartMenu" フォルダーに自分のアプリへのショートカット リンクを作成したいと考えています。だから私はこのコードを使用しました:
def create_shortcuts():
import pythoncom
from win32com.shell import shell, shellcon
shortcut = pythoncom.CoCreateInstance (
shell.CLSID_ShellLink,
None,
pythoncom.CLSCTX_INPROC_SERVER,
shell.IID_IShellLink
)
shortcut.SetPath ("path_to_my_app")
shortcut.SetDescription ("Description")
shortcut.SetIconLocation ("path_to_my_app_icon", 0)
prg_path = shell.SHGetFolderPath (0, shellcon.CSIDL_COMMON_PROGRAMS, 0, 0)
persist_file = shortcut.QueryInterface (pythoncom.IID_IPersistFile)
os.makedirs(prg_path + "\\myFolder")
persist_file.Save(os.path.join (prg_path + "\\myFolder", "myApp.lnk"), 0)
create_shortcuts()
os.makedirs
問題は、このコードを実行すると、「プログラム」フォルダーにフォルダーを作成する権限がないため、アクセス拒否エラーが発生することです。このコードはインストーラーのセットアップの一部であり、ユーザーは「管理者として実行」せずに実行する必要があります。
OS: Windows 8 Python: 2.7