[python-win32] Problem creating a shortcut
Mike Driscoll
mdriscoll at co.marshall.ia.us
Fri May 16 15:48:52 CEST 2008
Tim,
> <div class="moz-text-flowed" style="font-family: -moz-fixed">Mike
> Driscoll wrote:
>>
>> 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.
>> ...
>> shortcut = shell.CreateShortCut(userDesktop + '\\MyShortcut.lnk')
>> shortcut.Targetpath = r'"C:\Program Files\Mozilla Firefox\firefox.exe"
>> https:\www.myCompanyWebsite.com\
>> <http://www.myCompanyWebsite.com%5C>auth\preauth.php'
>> shortcut.WorkingDirectory = r'C:\Program Files\Mozilla
>> Firefox'
>> shortcut.save()
>>
>> </code>
>
> Do you understand that it is not safe to assume that Firefox lives in
> "C:\Program Files\Mozilla Firefox"? I often override my application
> install directories to keep the paths short, so I put it in
> "C:\Apps\Firefox". Plus, the "Program Files" path name is localized
> on the international versions of Windows.
I guess I should have described my environment a little more. This is
for a logon script at a business. The user's have no control over where
Firefox resides and if they happen to uninstall it or do not have it in
the first place, one of my other scripts will install it for them in the
background.
The reason is quite simple. We use Zimbra which runs much better in
Firefox than any other browser we've tested. But you and the others are
correct. If this had been an application, then I wouldn't have done this
the way that I am.
>
> You'll need to dig in the registry, in
> HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox. Fetch the
> "CurrentVersion" string value, then look inside that key, in Main, and
> fetch the PathToExe string. Something like this:
>
> ffkey = _winreg.OpenKey( _winreg.HKEY_LOCAL_MACHINE,
> 'SOFTWARE\\Mozilla\\Mozilla Firefox')
> ffver = _winreg.QueryValueEx( ffkey, 'CurrentVersion' )[0]
> print ffver
> ffmainkey = _winreg.OpenKey( ffkey, sub + "\\Main" )
> ffpath = _winreg.QueryValueEx( ffmainkey, 'PathToExe' )[0]
> _winreg.CloseKey( ffkey )
> _winreg.CloseKey( ffmainkey )
>
Thanks for the advice,
Mike
More information about the python-win32
mailing list