[python-win32] Problem creating a shortcut

Tim Roberts timr at probo.com
Thu May 15 23:22:54 CEST 2008


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.

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 )

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list