我想在“Program/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
发布于 2014-09-01 17:03:38
程序应该被提升(使用py2exe):
setup(console=[{'script':"process.py",'uac_info': "requireAdministrator"}])https://stackoverflow.com/questions/19812968
复制相似问题