473,785 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem creating a shorcut

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('WScr ipt.Shell')
userDesktop = winshell.deskto p()

shortcut = shell.CreateSho rtCut(userDeskt op + '\\MyShortcut.l nk')
shortcut.Target path = r'"C:\Program Files\Mozilla Firefox\firefox .exe"
https:\www.myCo mpanyWebsite.co m\auth\preauth. php'
shortcut.Workin gDirectory = r'C:\Program Files\Mozilla
Firefox'
shortcut.save()

</code>

This creates the following target path (which doesn't work):

"C:\"C:\Pro gram Files\Mozilla Firefox\firefox .exe" https:
\www.myCompanyW ebsite.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
Jun 27 '08
15 2514
Mike Driscoll wrote:
On May 15, 2:03 pm, Larry Bates <larry.ba...@we bsafe.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('WScr ipt.Shell')
userDesktop = winshell.deskto p()
shortcut = shell.CreateSho rtCut(userDeskt op + '\\MyShortcut.l nk')
shortcut.Targ etpath = r'"C:\Program Files\Mozilla Firefox\firefox .exe"
https:\www.my CompanyWebsite. com\auth\preaut h.php'
shortcut.Work ingDirectory = r'C:\Program Files\Mozilla
Firefox'
shortcut.save ()
</code>
This creates the following target path (which doesn't work):
"C:\"C:\Progr am Files\Mozilla Firefox\firefox .exe" https:
\www.myCompan yWebsite.com\au th\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:\Progra m Files...

Note the C:\ is specified twice in the string. I think it should read:
> "C:\Program Files\Mozilla Firefox\firefox .exe" https:
\www.myCompanyW ebsite.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
Jun 27 '08 #11
On May 16, 5:44*am, Wolfgang Draxinger <wdraxin...@dar kstargames.de>
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('WScr ipt.Shell')
userDesktop = winshell.deskto p()
shortcut = shell.CreateSho rtCut(userDeskt op +
'\\MyShortcut.l nk') shortcut.Target path = r'"C:\Program
Files\Mozilla Firefox\firefox .exe"
https:\www.myCo mpanyWebsite.co m\auth\preauth. php'
shortcut.Workin gDirectory = r'C:\Program Files\Mozilla Firefox'
shortcut.save()
</code>
This creates the following target path (which doesn't work):
"C:\"C:\Pro gram Files\Mozilla Firefox\firefox .exe" https:
\www.myCompanyW ebsite.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.

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 <hostis empty (file protocoll e.g.).

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
Jun 27 '08 #12
On May 16, 1:51*am, Chris <cwi...@gmail.c omwrote:
On May 15, 5:13*pm, Mike Driscoll <kyoso...@gmail .comwrote:
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('WScr ipt.Shell')
userDesktop = winshell.deskto p()
shortcut = shell.CreateSho rtCut(userDeskt op + '\\MyShortcut.l nk')
shortcut.Target path = r'"C:\Program Files\Mozilla Firefox\firefox .exe"
https:\www.myCo mpanyWebsite.co m\auth\preauth. php'
shortcut.Workin gDirectory = r'C:\Program Files\Mozilla
Firefox'
shortcut.save()
</code>
This creates the following target path (which doesn't work):
"C:\"C:\Pro gram Files\Mozilla Firefox\firefox .exe" https:
\www.myCompanyW ebsite.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

Don't set arguments in the path.

shortcut = shell.CreateSho rtCut(userDeskt op + '\\MyShortcut.l nk')
shortcut.Target Path = r'Program Files\Mozilla Firefox\firefox .exe'
shortcut.Argume nts = r'https:\www.myCompanyWebsite.com\auth
\preauth.php'
shortcut.Workin gDirectory = r'C:\Program Files\Mozilla Firefox'
shortcut.save()
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
Jun 27 '08 #13
On May 15, 8:24*pm, "Gabriel Genellina" <gagsl-...@yahoo.com.a r>
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/doc...pywin32/win32c...

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

Mike
Jun 27 '08 #14
On May 16, 8:09*am, Larry Bates <larry.ba...@we bsafe.com`wrote :
Mike Driscoll wrote:
On May 15, 2:03 pm, Larry Bates <larry.ba...@we bsafe.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('WScr ipt.Shell')
userDesktop = winshell.deskto p()
shortcut = shell.CreateSho rtCut(userDeskt op + '\\MyShortcut.l nk')
shortcut.Targe tpath = r'"C:\Program Files\Mozilla Firefox\firefox .exe"
https:\www.myC ompanyWebsite.c om\auth\preauth .php'
shortcut.Worki ngDirectory = r'C:\Program Files\Mozilla
Firefox'
shortcut.save( )
</code>
This creates the following target path (which doesn't work):
"C:\"C:\Progra m Files\Mozilla Firefox\firefox .exe" https:
\www.myCompany Website.com\aut h\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:\Pro gram Files...
Note the C:\ is specified twice in the string. *I think it should read:
*"C:\Program Files\Mozilla Firefox\firefox .exe" https:
*\www.myCompany Website.com\aut h\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
Jun 27 '08 #15
Duncan Booth wrote:
It's not too hard to get the required command line from the registry:

import _winreg
print _winreg.QueryVa lue(_winreg.HKE Y_CLASSES_ROOT,
'FirefoxURL\she ll\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
Jun 27 '08 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
683
by: Club-B42 | last post by:
i've compiled my programm using command "python setup.py py2exe >1" python script works fine, but .exe version fails with ===================================================================== D:\\Scripts\B-4-2\la2luncher\dist>la2launcher.exe Traceback (most recent call last): File "la2launcher.py", line 9, in ? File "config.pyc", line 11, in ? File "config.pyc", line 8, in u LookupError: no codec search functions registered: can't find...
5
1277
by: יוני גולדברג | last post by:
Hi, While trying to create new directory i recieve the following error message: "System.IO.DirectoryNotFoundException: Could not find a part of the path "\\premfs16\sites". The path exists, even when i check the path with the code: Directory.Exists(...) the result is true. Here is the code: http://www.adeo.co.il/test.aspx
7
11714
by: jemmaq99 | last post by:
Using Visual Studio .NET 2003 I've tried to add a COM reference to a Windows Form project via the Add Reference dialog (specifically the Active DS Type Library) but always get the error message: "A reference to 'Active DS Type Library' could not be added. The type library wrapper tool 'tlbimp' cannot be found on this system. Please re-install Visual Studio." This occurs regardless of the actual tlb or dll selected and happens on...
1
2055
by: Medora Schauer | last post by:
I've installed 7.4.2 on a PowerPC system running linux 2.4.13. When I try to run initdb to create to create the database cluster I get the following: $ initdb -D $PGDATA The files belonging to this database system will be owned by user "thebox".
2
1937
by: tech tech | last post by:
Hello All, I installed postgresql 7.3.4 on HPUX PA in /usr/local/pgsql and put the libraries in /usr/local/pgsql/lib/LIB_new. During the initialization( initdb), it loads libraries (language) from /usr/local/pgsql/lib. In postgresql version 7.3.1, libraries are not loaded and no such problem during initdb. I had the following problem: $ initdb -D /var/pgsql The files belonging to this database system will be owned by user "postgres".
16
4929
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by Microsoft must be installed on their servers. Now german Umlaute (ä, ü, ö) and quotes are returned incorrectly in SOAP fault responses. This can be easily verified: Implement the following in a web service method (just raises a SOAPException with a...
1
1301
by: ABC | last post by:
How to add a underscore to indicate users what is the shorcut key of Button? Under Winform, our can add & symbol on label to indicate what is the shortkey of button, in ASP.NET, how should I to do that?
8
8941
by: Chizl | last post by:
I'm building a web server and having some issues with the TCPListener.Start(BackLog). It doesn't seem to do as expected. I'm using MS Web Stress Tool to test against my web server and when I see 200 connections at once to it, and I'm seeing 2/3 of the sockets as socket errors.. They never get into my code, so it has to be failing on the connection side.. Backlog is the only thing I can think could be the problem. ...
2
970
by: Gazi | last post by:
Hello! I have a program with writing by .Net it is a personal order program. there is a database with access and this program binds it. First it wants to username and password from user (All users have) Then The Program looks his Position and Department from table. if The Personal works in Ordering Department or His Position is Manager,he can see all orders and can accept or decline. But if he doesnt work there or isnt Manager,he can see...
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9489
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10162
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.