Sign in to follow this  
Followers 0
meamrussian

Question: Run FireFox Like IE

24 posts in this topic

Hello. I know that to open IE also to a specifit page (let's say google) I just have to put:

Run ("C:\Program Files\Internet Explorer\iexplore.exe http://google.com")

This will automatically make it run IE and start it on google.com. How do I make it do the same, but with firefox? I tried putting in the same command, except pointing to firefox, but that does not work. It doesn't have to be done in the same way; I just want ANYway to startup firefox and for it to go to a specific webpage. This will also teach me how to do the same in ANY browser.

Thanks a lot.

Share this post


Link to post
Share on other sites



Find the default browser:

Local $sType, $sCommand
$sType = RegRead('HKEY_Classes_Root\.html')
if $sType <> '' Then $sCommand = RegRead('HKCR\' & $sType & '\Shell\Open', '')
if $sCommand <> '' then Run(_StringReplace($sCommand, '%1', 'http://www.google.com'))

Share this post


Link to post
Share on other sites

LOL, like the avatar blindwig!


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

for the default brouwser; you can also use:

RunWait(@COMSPEC & ' /c Start www.google.nl')

OR if you have the BETA

$o_URL = ObjCreate("Shell.Application")
$o_URL.Open('www.google.nl')
Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Share this post


Link to post
Share on other sites

LOL, like the avatar blindwig!

<{POST_SNAPBACK}>

:evil:

It's a pic I took of me squeezing the crap out of the stress ball my girlfriend bought me last Christmas. You see, I'm one of the few programmers I know who doesn't smoke or drink coffee (or alcohol, for that matter) so I gotta take out my frustrations on SOMETHING! :)

Share this post


Link to post
Share on other sites

for the default brouwser; you can also use:

RunWait(@COMSPEC & ' /c Start www.google.nl')

Yes, if you don't mind the ugly DOS box popping up! :)

The routine I gave does basically the same thing as the START command - it looks in the registry for the command associated with a certain filetype (in this case, a URL) and launches the appropriate associated application.

OR if you have the BETA

$o_URL = ObjCreate("Shell.Application")

$o_URL.Open('www.google.nl')

You could also do this:

DllCall("shell32.dll", "long", "ShellExecute", "hwnd", $parent_hwnd, "string", $sVerb, "string", 'Http://www.google.com' "string", $sArg, "string", $sFolder, "long", $state)

Many paths to the same solution, eh?

Share this post


Link to post
Share on other sites

RunWait(@ComSpec & ' /c start www.google.nl', @ScriptDir, @SW_HIDE)

<{POST_SNAPBACK}>

Hey guys, thanks for your reply. I find this one to be the best lol, as it is the shortest. But, would you kindly explain this code to me step by step, as I am still kinda new to autoit? Thanks, w0uter

blindwig, I tested your code, and it had a bunch of errors in it :)

Thanks

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

blindwig, I tested your code, and it had a bunch of errors in it :)

Thanks

<{POST_SNAPBACK}>

Well it was more of pseudo-code to show you how to do it.

Here's actual working code:

Dim $sType, $sCommand
$sType = RegRead('HKEY_Classes_Root\.html', '')
if $sType <> '' Then $sCommand = RegRead('HKCR\' & $sType & '\Shell\Open\Command', '')
if $sCommand <> '' then Run(StringReplace($sCommand, '%1', 'http://www.google.com'))

And this is the more official way to do it:

DllCall("shell32.dll", "long", "ShellExecute", "hwnd", 0, "string", 'open', "string", 'Http://www.google.com', "string", '', "string", @ScriptDir, "long", @SW_SHOWNORMAL)
Edited by blindwig

Share this post


Link to post
Share on other sites

@meamrussian

RunWait( = runs a .exe/.com/.cmd/.etc and waits till its done.

@comspec = the default command interperter (9x, command.com; nt, cmd.exe)

/c = close after execution

Start = open's a file (for more info "start > run > cmd.exe > help start")

www.google.nl = the file to open.

@scriptdir = working dir.

@SW_HIDE = hide the dos box.


My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Share this post


Link to post
Share on other sites

@meamrussian

RunWait( = runs a .exe/.com/.cmd/.etc and waits till its done.

@comspec = the default command interperter (9x, command.com; nt, cmd.exe)

/c = close after execution

Start = open's a file (for more info "start > run > cmd.exe > help start")

www.google.nl = the file to open.

@scriptdir = working dir.

@SW_HIDE = hide the dos box.

<{POST_SNAPBACK}>

So, basically when you tell it to start www.google.nl, it knows to open it with the default browser? Also, what does @scriptdir do (working dir)?

blindwig, thanks for that fixed up, ready to use code :)

Share this post


Link to post
Share on other sites

So, basically when you tell it to start www.google.nl, it knows to open it with the default browser?

<{POST_SNAPBACK}>

short. yes.

Also, what does @scriptdir do (working dir)?

<{POST_SNAPBACK}>

im not sure. but i always thought:

For EX.

if you open a command promt (cmd.exe) its working dir is C:\

if you type cd .\WINDOWS\ then your working dir will be C:\WINDOWS\

but i can also be wrong and it can be @SystemDir.


My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Well it was more of pseudo-code to show you how to do it.

Here's actual working code:

Dim $sType, $sCommand
$sType = RegRead('HKEY_Classes_Root\.html', '')
if $sType <> '' Then $sCommand = RegRead('HKCR\' & $sType & '\Shell\Open\Command', '')
if $sCommand <> '' then Run(StringReplace($sCommand, '%1', 'http://www.google.com'))

And this is the more official way to do it:

DllCall("shell32.dll", "long", "ShellExecute", "hwnd", 0, "string", 'open', "string", 'Http://www.google.com', "string", '', "string", @ScriptDir, "long", @SW_SHOWNORMAL)

<{POST_SNAPBACK}>

Sorry for being so annoying, but just getting the code isn't enough for me; any chance you could explain the code, like w0uter did? (the "official" one)

Thanks a lot

Edited by meamrussian

Share this post


Link to post
Share on other sites

RunWait(@ComSpec & ' /c start www.google.nl', @ScriptDir, @SW_HIDE)

Also, the only reason I don't really like this is that it can't start all URLs. If I'm not going to a home page, there are some VERY long links that have the symbol & in them, and the link stops when it reaches the &... is there a way to fix this? I am trying to make it open the following:

RunWait(@ComSpec & ' /c start http://namepros.com/newthread.php?do=newthread&f=6', @ScriptDir, @SW_HIDE)

As you can see if you tried it, it tries to go to:

http://namepros.com/newthread.php?do=newthread

Any way to make it go to the whole url?

Share this post


Link to post
Share on other sites

Also, the only reason I don't really like this is that it can't start all URLs. If I'm not going to a home page, there are some VERY long links that have the symbol & in them, and the link stops when it reaches the &... is there a way to fix this? I am trying to make it open the following:

RunWait(@ComSpec & ' /c start http://namepros.com/newthread.php?do=newthread&f=6', @ScriptDir, @SW_HIDE)

As you can see if you tried it, it tries to go to:

http://namepros.com/newthread.php?do=newthread

Any way to make it go to the whole url?

<{POST_SNAPBACK}>

Yes, this is an issue with the method you're using. You're launching a command shell, then running a command inside that shell and passing your string to it. The promblem is that the command shell and the command can each potentially have special interpretations of special characters, so certain strings can get lost in the translation. That's why I don't recommend this method - yes, it is quick and easy, but it's a sloppy way to do thigs and bring the potential for problems.

The issue you're facing is that the command pre-processor uses the ampersand symbol as a command seperator. You can try to put your string in double quotes:

RunWait(@ComSpec & ' /c start "http://namepros.com/newthread.php?do=newthread&f=6"', @ScriptDir, @SW_HIDE)

That might work. But the real solution is to use a real solution.

The best official true solution would be to use the object method w0uter suggested, or the DLLCall solution I suggested. Both of these methods pass the URL link to the part of the OS that decides which program is set to handle that link and launches it accordingly. The registry solution I gave you is a roundabout way of doing the same thing, but it doesn't cover all situations.

Share this post


Link to post
Share on other sites

The best official true solution would be to use the object method w0uter suggested
What object method?

Share this post


Link to post
Share on other sites

Er, nevermind. I just tried the object solution on my machine and it doesn't do anything. I don't know whats wrong with it, because I've never done objects before.

So, just go with the DLL solution for now :)

Share this post


Link to post
Share on other sites

comspec: failed at all methods i tried.

object: worked for me.

dll: havent tried.

and this is the "object" method:

$o_URL = ObjCreate("Shell.Application")
$o_URL.Open('www.google.nl')

<{POST_SNAPBACK}>

Oh, that's for the beta version

Share this post


Link to post
Share on other sites

comspec: failed at all methods i tried.

object: worked for me.

dll: havent tried.

and this is the "object" method:

$o_URL = ObjCreate("Shell.Application")
$o_URL.Open('www.google.nl')

<{POST_SNAPBACK}>

For some reason, that doesn't work for me unless I put http:// in front of the address.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0