Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem creating a shorcut

24 views
Skip to first unread message

Mike Driscoll

unread,
May 15, 2008, 11:13:56 AM5/15/08
to
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

Larry Bates

unread,
May 15, 2008, 3:03:22 PM5/15/08
to

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

Mike Driscoll

unread,
May 15, 2008, 4:11:24 PM5/15/08
to

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

Gabriel Genellina

unread,
May 15, 2008, 9:24:51 PM5/15/08
to pytho...@python.org
En Thu, 15 May 2008 12:13:56 -0300, Mike Driscoll <kyos...@gmail.com>
escribió:

> 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:

Try this different approach, using the IShellLink interface:
http://aspn.activestate.com/ASPN/docs/ActivePython/2.3/pywin32/win32com.shell_and_Windows_Shell_Links.html

--
Gabriel Genellina

Chris

unread,
May 16, 2008, 2:51:07 AM5/16/08
to

Don't set arguments in the path.

shortcut = shell.CreateShortCut(userDesktop + '\\MyShortcut.lnk')

shortcut.TargetPath = r'Program Files\Mozilla Firefox\firefox.exe'
shortcut.Arguments = r'https:\www.myCompanyWebsite.com\auth

Wolfgang Draxinger

unread,
May 16, 2008, 6:44:26 AM5/16/08
to
Mike Driscoll wrote:

I see four problems:

1) you should not hardcode the backslashes ('\'), instead use
os.sep for it.

2) In URIs there are no backslashes, only forward slashes. You
coded

https:\...

which is _WRONG_. URIs are <protocoll>://<host>/<resource>, where
for some protocolls <host> is empty (file protocoll e.g.).

3) You assume, that Firefox is always installed at C:\Program
Files\Mozilla Firefox\firefox.exe
However the path largely differs from system to system. On *nix
systems you normally have all programs in $PATH, so a non full
qualified path would be sufficient. On Windows this works, too,
_IF_ the installation directory of the to be used application
get's added to the PATH environment variable.

Wolfgang Draxinger
--
E-Mail address works, Jabber: hexa...@jabber.org, ICQ: 134682867

Tim Golden

unread,
May 16, 2008, 7:09:51 AM5/16/08
to pytho...@python.org
Wolfgang Draxinger wrote:
> 1) you should not hardcode the backslashes ('\'), instead use
> os.sep for it.

With respect, the OP is creating a Windows desktop shortcut.
Unless Microsoft suddenly decide to change their use of the
backslash, I suggest that this is a needless generalisation.

> 3) You assume, that Firefox is always installed at C:\Program
> Files\Mozilla Firefox\firefox.exe
> However the path largely differs from system to system.

This is broadly true. However, it's fairly clear from the
phrase "the user's desktop" that the OP is working in some
kind of corporate environment where he can be fairly sure
where Firefox is installed by policy. In addition, it's not so
easy to find its path if it's not in the default place since apps
very rarely add their location to the system PATH these days
(and Firefox certainly doesn't). You could scan the registry for
its App Paths entry in the registry but I don't know if any other
way if it's not the default browser (which it's clear from the
original post it may not be).

Sorry to sound a bit negative, but I felt that a couple of your points,
while valid, were not altogether helpful to the situation the OP was in.

TJG

Tim Golden

unread,
May 16, 2008, 7:06:25 AM5/16/08
to pytho...@python.org
Wolfgang Draxinger wrote:
> 1) you should not hardcode the backslashes ('\'), instead use
> os.sep for it.

With respect, the OP is creating a Windows desktop shortcut.


Unless Microsoft suddenly decide to change their use of the
backslash, I suggest that this is a needless generalisation.

> 3) You assume, that Firefox is always installed at C:\Program


> Files\Mozilla Firefox\firefox.exe
> However the path largely differs from system to system.

This is broadly true. However, it's fairly clear from the

Larry Bates

unread,
May 16, 2008, 9:09:13 AM5/16/08
to

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

Mike Driscoll

unread,
May 16, 2008, 9:11:54 AM5/16/08
to
On May 16, 5:44 am, Wolfgang Draxinger <wdraxin...@darkstargames.de>
wrote:


That was an accident...my original code was correct, but I stupidly
decided to generalize my website's name and put the wrong slashes in.


>
> 3) You assume, that Firefox is always installed at C:\Program
> Files\Mozilla Firefox\firefox.exe
> However the path largely differs from system to system. On *nix
> systems you normally have all programs in $PATH, so a non full
> qualified path would be sufficient. On Windows this works, too,
> _IF_ the installation directory of the to be used application
> get's added to the PATH environment variable.
>


I don't assume it at all. At my place of business, that's where
Firefox is. If it's not installed there when the user logs in, one of
my scripts installs it automatically.


> Wolfgang Draxinger
> --
> E-Mail address works, Jabber: hexar...@jabber.org, ICQ: 134682867

Mike Driscoll

unread,
May 16, 2008, 9:15:41 AM5/16/08
to

Ah. I was unaware of the Arguments parameter. That works quite well.
Where does one find this information anyway? I think I found mine from
bits and pieces scattered in various tutorials.

Thanks a lot.

Mike

Mike Driscoll

unread,
May 16, 2008, 9:17:00 AM5/16/08
to
On May 15, 8:24 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
> En Thu, 15 May 2008 12:13:56 -0300, Mike Driscoll <kyoso...@gmail.com>  

> escribió:
>
> > 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:
>
> Try this different approach, using the IShellLink interface:http://aspn.activestate.com/ASPN/docs/ActivePython/2.3/pywin32/win32c...
>
> --
> Gabriel Genellina

Thanks Gabriel...it looks a little overwhelming, but I'll file it away
for future reference.

Mike

Mike Driscoll

unread,
May 16, 2008, 9:22:01 AM5/16/08
to

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

Tim Golden

unread,
May 16, 2008, 9:25:10 AM5/16/08
to pytho...@python.org
Mike Driscoll wrote:
> Ah. I was unaware of the Arguments parameter. That works quite well.
> Where does one find this information anyway? I think I found mine from
> bits and pieces scattered in various tutorials.

The canonical place would be:

http://msdn.microsoft.com/en-us/library/bb774950(VS.85).aspx

TJG

Duncan Booth

unread,
May 16, 2008, 9:34:42 AM5/16/08
to
Tim Golden <ma...@timgolden.me.uk> wrote:

>> 3) You assume, that Firefox is always installed at C:\Program
>> Files\Mozilla Firefox\firefox.exe
>> However the path largely differs from system to system.
>
> This is broadly true. However, it's fairly clear from the
> phrase "the user's desktop" that the OP is working in some
> kind of corporate environment where he can be fairly sure
> where Firefox is installed by policy. In addition, it's not so
> easy to find its path if it's not in the default place since apps
> very rarely add their location to the system PATH these days
> (and Firefox certainly doesn't). You could scan the registry for
> its App Paths entry in the registry but I don't know if any other
> way if it's not the default browser (which it's clear from the
> original post it may not be).
>

It's not too hard to get the required command line from the registry:

import _winreg
print _winreg.QueryValue(_winreg.HKEY_CLASSES_ROOT,
'FirefoxURL\shell\open\command')

and of course it throws an exception if firefox isn't installed.

Then just replace %1 with the url to get the actual command you need.

--
Duncan Booth http://kupuguy.blogspot.com

Tim Golden

unread,
May 16, 2008, 10:07:31 AM5/16/08
to pytho...@python.org
Duncan Booth wrote:
> It's not too hard to get the required command line from the registry:
>
> import _winreg
> print _winreg.QueryValue(_winreg.HKEY_CLASSES_ROOT,
> 'FirefoxURL\shell\open\command')
>
> and of course it throws an exception if firefox isn't installed.
>
> Then just replace %1 with the url to get the actual command you need.

That's neat. You learn something new...

TJG

0 new messages