Problem creating a shorcut

Mike Driscoll kyosohma at gmail.com
Fri May 16 09:22:01 EDT 2008


On May 16, 8:09 am, Larry Bates <larry.ba... at websafe.com`> wrote:
> Mike Driscoll wrote:
> > On May 15, 2:03 pm, Larry Bates <larry.ba... at websafe.com`> wrote:
> >> Mike Driscoll wrote:
> >>> Hi,
> >>> I've had this niggling issue from time to time. I want to create a
> >>> shortcut on the user's desktop to a website that specifically loads
> >>> Firefox even if Firefox is not the default browser.
> >>> I usually use COM as it allows very specific settings of the shortcut,
> >>> such as the Working Directory and the Target Path. However, the
> >>> following will not work for some reason:
> >>> <code>
> >>> import win32com.client
> >>> import winshell
> >>> shell = win32com.client.Dispatch('WScript.Shell')
> >>> userDesktop = winshell.desktop()
> >>> shortcut = shell.CreateShortCut(userDesktop + '\\MyShortcut.lnk')
> >>> shortcut.Targetpath = r'"C:\Program Files\Mozilla Firefox\firefox.exe"
> >>> https:\www.myCompanyWebsite.com\auth\preauth.php'
> >>> shortcut.WorkingDirectory = r'C:\Program Files\Mozilla
> >>> Firefox'
> >>> shortcut.save()
> >>> </code>
> >>> This creates the following target path (which doesn't work):
> >>> "C:\"C:\Program Files\Mozilla Firefox\firefox.exe" https:
> >>> \www.myCompanyWebsite.com\auth\preauth.php"
> >>> If I leave the website off, it works. If I leave the path to Firefox
> >>> out, it works too. Is there another method I can use other than
> >>> creating the shortcut by hand and using the shutil module?
> >>> Thank you for any ideas.
> >>> Mike
> >> Either you copied wrong or the problem is:
>
> >> "C:\"C:\Program Files...
>
> >> Note the C:\ is specified twice in the string.  I think it should read:
>
> >>  > "C:\Program Files\Mozilla Firefox\firefox.exe" https:
> >>  > \www.myCompanyWebsite.com\auth\preauth.php"
>
> >> -Larry
>
> > Yeah, I know that it's in there twice and that that is the problem.
> > But I'm not causing that extra C:\. I run it exactly as above and that
> > is what I get for the output. I think it's the COM object. Maybe I
> > better just re-post this to the PyWin32 list...
>
> > Thanks,
>
> > Mike
>
> I use Inno Setup on most of my applications and use it to create my desktop,
> quicklaunch and Start shortcuts.  Would that be an option for you?
>
> -Larry

I use Inno too for my applications. However, in this case, I have to
create the shortcut as part of the login process based on what group
the user is in. Chris's solution worked for my needs and I think
Gabriel's will work too, if I figure it out.

Mike



More information about the Python-list mailing list