none
Opening up a website RRS feed

  • Question

  • In Small Basic I was wondering if there is a way that on a button click, it opens up your default browser and directs you to a website I specify. Is this possible if so do I need an extension for it?
    Monday, June 16, 2014 12:18 AM

Answers

  • ... and just like 'The last one turnes out the light' :-),

    i'll summarize the variants:

    ' Extension: LitDev for Variant 1, 2, 3, (4), 5 / SBExecCmd Variant 6

    URL = "http://smallbasic.com/" Variant1() ' select/edit Variant# here '' VARIANT# Subs '1.) starts your system default browser with URL, see LitDev's post above Sub Variant1 ' LDUtilities.ShowErrors = "" ' if ErrorMsg in TW LDProcess.Start(URL, "") EndSub ' 2.) starts any selectable browser (like firefox.exe, iron.exe, opera.exe etc) by full path or by AppName if key AppName.exe exists under 'App Paths' key. Sub Variant2 'LDProcess.Start("iexplore.exe", URL) ' w/o path, because here 'iexplore.exe' path is got from HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\(iexplore.exe) , same for eg. wmplayer.exe '' or LDProcess.Start("C:\Program Files\Internet Explorer\iexplore.exe", URL) ' uses full program path (here 32bit), NOT as %EnvVar% path like %ProgramFiles% EndSub Sub Variant3 ' in SB GW, see martman's post above Browser = LDControls.AddBrowser(GraphicsWindow.Width, GraphicsWindow.Height, URL) EndSub Sub Variant4 ' in TW, GW, (ML)TextBox or to file.txt etc. HTMLText = Network.GetWebPageContents(URL)

    ' pure html looks ugly, so better strip the html tags (and clean) HTMLText first, like ' HTMLText = LDUtilities.RegexReplace(HTMLText, "</?.+?>", " ", "False") ' some HTMLText cleaning like eg. remove empty lines, DoTabs etc. TextWindow.WriteLine(HTMLText) EndSub ' ---------------------------------------------------- ' via CMD.EXE Sub Variant5 ' pops up CmdPrompt Window DoQUSpc = Text.GetCharacter(34) + Text.GetCharacter(34) + " " LDProcess.Start("cmd.exe", "/d /c & START " + DoQUSpc + URL) EndSub ' same as 5.), but uses ExecCmd.ExecSync which already has 'cmd.exe /d /c' included and also hides CmdPrompt Window ' see execute-a-shellcommand-and-get-cmd-output Sub Variant6 DoQUSpc = Text.GetCharacter(34) + Text.GetCharacter(34) + " " ' ExecCmd.ExecCmdSync("START " + DoQUSpc + URL) EndSub


    ' Also other Extensions support http-access like IE4SmallBasic (see Nonki's post above), gungan37's "IO Extension", Fremy's Ext and Oskariok's Data Ext.



    Monday, June 16, 2014 6:33 PM
    Answerer

All replies

  • CodingLikeCrazy,

    Yes, it's possible using an extension. If you load the LitDev extension it gives the capability of loading a browser.

    Example:

    LDControls.AddBrowser(600,400,"www.google.com")

    You can try this from small basic. If you want a button just a button on the graphics window create a sub routine with this in it. Push the button and the browser should open to whatever url you want.


    JR

    Monday, June 16, 2014 2:38 AM
    Answerer
  • Hello CodingLikeCrazy,

    import  CWS561 is it my browser with the LitDev extentions. It is a small brower.


    Best Regards Martin

    Monday, June 16, 2014 3:28 AM
  • Or how about using IE Library for Small Basic?


    Nonki Takahashi

    Monday, June 16, 2014 3:25 PM
    Moderator
  • Or even just:

    LDProcess.Start("http:\\www.google.com","")

    Monday, June 16, 2014 5:25 PM
    Moderator
  • ... and just like 'The last one turnes out the light' :-),

    i'll summarize the variants:

    ' Extension: LitDev for Variant 1, 2, 3, (4), 5 / SBExecCmd Variant 6

    URL = "http://smallbasic.com/" Variant1() ' select/edit Variant# here '' VARIANT# Subs '1.) starts your system default browser with URL, see LitDev's post above Sub Variant1 ' LDUtilities.ShowErrors = "" ' if ErrorMsg in TW LDProcess.Start(URL, "") EndSub ' 2.) starts any selectable browser (like firefox.exe, iron.exe, opera.exe etc) by full path or by AppName if key AppName.exe exists under 'App Paths' key. Sub Variant2 'LDProcess.Start("iexplore.exe", URL) ' w/o path, because here 'iexplore.exe' path is got from HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\(iexplore.exe) , same for eg. wmplayer.exe '' or LDProcess.Start("C:\Program Files\Internet Explorer\iexplore.exe", URL) ' uses full program path (here 32bit), NOT as %EnvVar% path like %ProgramFiles% EndSub Sub Variant3 ' in SB GW, see martman's post above Browser = LDControls.AddBrowser(GraphicsWindow.Width, GraphicsWindow.Height, URL) EndSub Sub Variant4 ' in TW, GW, (ML)TextBox or to file.txt etc. HTMLText = Network.GetWebPageContents(URL)

    ' pure html looks ugly, so better strip the html tags (and clean) HTMLText first, like ' HTMLText = LDUtilities.RegexReplace(HTMLText, "</?.+?>", " ", "False") ' some HTMLText cleaning like eg. remove empty lines, DoTabs etc. TextWindow.WriteLine(HTMLText) EndSub ' ---------------------------------------------------- ' via CMD.EXE Sub Variant5 ' pops up CmdPrompt Window DoQUSpc = Text.GetCharacter(34) + Text.GetCharacter(34) + " " LDProcess.Start("cmd.exe", "/d /c & START " + DoQUSpc + URL) EndSub ' same as 5.), but uses ExecCmd.ExecSync which already has 'cmd.exe /d /c' included and also hides CmdPrompt Window ' see execute-a-shellcommand-and-get-cmd-output Sub Variant6 DoQUSpc = Text.GetCharacter(34) + Text.GetCharacter(34) + " " ' ExecCmd.ExecCmdSync("START " + DoQUSpc + URL) EndSub


    ' Also other Extensions support http-access like IE4SmallBasic (see Nonki's post above), gungan37's "IO Extension", Fremy's Ext and Oskariok's Data Ext.



    Monday, June 16, 2014 6:33 PM
    Answerer

  • The 'if ErrorMsg in TW' is a good catch using variant 1 of Pappa's example.  An exception occurs when the Process that is started already exists and the ID is not found for return value.  For an exe this is unlikely, but a URL as process will be opened in your browser that may already be open - fixed for next release.
    Wednesday, June 18, 2014 6:22 PM
    Moderator
  • So that was the reason.

    Indeed i had opened my default browser when running the command and ErrorMsg appeared, while site opened in a new instance or tab. Could'nt ordner this first. Good to know.

    And just tested: same ErrorMsg, when browser is NOT opened before and also on:

    LDProcess.Start("Drv:\Path\To\SmallBasic.url", "")

    Wednesday, June 18, 2014 7:52 PM
    Answerer
  • Pappa Lapub,

    Can you explain what variant 5 and 6 are supposed to do? I see the DoQUSpc is two double quotes and a space.  Variant 6 only has DoQU, but in the commented out ExecCmd.ExecCmdSync it shows DoQUSpc. Anyhow I don't understand what they're doing.

    Thanks,


    JR

    Thursday, June 19, 2014 12:32 AM
    Answerer
  • Oh, sorry and thanks JR. Overseen this and fixed in above post.

    In SB, we also could simply break down the command (eg. Variant5) from:

    DoQUSpc = Text.GetCharacter(34) + Text.GetCharacter(34) + " "
    LDProcess.Start("cmd.exe", "/d /c & START " + DoQUSpc + URL)

    to:

    LDProcess.Start("cmd.exe", "/d /c & START "" " + URL)

    (see in Nonki's 'SB Trivias' thread)

    You can compare the CMD-internal command 'START' with your RunBox (under StartButton-Run) or LDProcess.Start and test your 'command to run' in eg. cmd.exe(Console, CommandPrompt) or your RunBox first.

    They all can start/open an application, a file or folder and have access to your %Path%, a given filepath in the command or AppPaths (in registry).

    First open a CommandPrompt(cmd.exe) window anywhere and show the help for the internal START command with 'start /?' followed be Return key. As we are already in cmd.exe we can access 'START' directly from here (and can forget about 'cmd.exe .. & ' before). The DoQuSpc ("" ) is the "Title", you see in the 'start /?' help

    and you can try eg. following commands from an anywhere opened CMD.exe and/or your RunBox:

    1.) in CMD: start iexplore "http://smallbasic.com" (starts IE with URL)

         or in Start-RunBox: iexplore "http://smallbasic.com"
    2.) in CMD: start "http://smallbasic.com"  (not working in W7)

         but in Start-RunBox: http://smallbasic.com  (starts the default browser with URL)
    3.) in CMD: start "" "http://smallbasic.com" (starts the default browser with URL)

         or in Start-RunBox: "http://smallbasic.com"    w or w/o quotes

    See the diff?: under 2.) the simple 'start URL' does'nt work from the CmdLine - at least on my W7 - but 'start "" URL' does.

    PS: from RunBox or LDProcess.Start we omit the leading 'start '.


    Thursday, June 19, 2014 3:00 PM
    Answerer
  • Pappa Lapub,

    Ok, I understand part of it.

    What is this:

    ExecCmd.ExecCmdSync("START " + DoQUSpc + URL)

    I can't get this to work at all in anything.

    Also, why the use of /D in the cmd.exe. As I see it says to disable execution of Autorun commands from registry. Why? I understand the /C.


    JR

    Thursday, June 19, 2014 4:57 PM
    Answerer
  • Part of the help of cmd follows:

    cmd /?

    Starts a new instance of the Windows command interpreter

    CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF]
        [[/S] [/C | /K] string]

    /C      Carries out the command specified by string and then terminates
    /D      Disable execution of AutoRun commands from registry (see below)

    If /D was NOT specified on the command line, then when CMD.EXE starts, it
    looks for the following REG_SZ/REG_EXPAND_SZ registry variables, and if
    either or both are present, they are executed first.  <=======

         HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun

            and/or

        HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun



    Jan [ WhTurner ] The Netherlands


    Thursday, June 19, 2014 5:06 PM
    Answerer
  • About the /d switch: added this in the extension, to avoid irritation in the executed command from ev. loaded AutoRun commands. Just like WhTurner33 said.

    eg. when i open a new cmd.exe instance some DosKey macros are automatically loaded, which could then effect a here specified command. So with the /d switch we are more on the safe side and execution also is faster, when autorun commands are ignored.

    PS: about 'more on the safe side' - Always remember: The LDProcess.Start, ExecCmd.ExecCmdSync and generally all/some CMD commands are EXTREMELY POWERFULL commands and you should always know what you're doing. These commands or their improper usage and execution can make systemwide damage on your machine. So NEVER execute them on good luck and always think twice before. (eg. ask JJ, who ran an LDProcess.Start in a 'While "True"' loop (?? i think) and could'nt start his SBIDE any more. As a harmless sample!)

    Sample Variant6:

    URL = "http://smallbasic.com"
    DoQUSpc = Text.GetCharacter(34) + Text.GetCharacter(34) + " "
    ExecCmd.ExecCmdSync("start " + DoQUSpc + URL)

    ran w/o probs for me, as well as:

    URL = "http://smallbasic.com"
    QU = Text.GetCharacter(34)
    DoQUSpc = Text.GetCharacter(34) + Text.GetCharacter(34) + " "
    ExecCmd.ExecCmdSync("start " + DoQUSpc + QU + URL + QU)

    The setting of quotes is sometimes not so simple or easy for CmdLine commands.

    But for this case (open a browser with URL), i would at any rate recommend the LDProcess.Start Variant.

    How about you WhTurner? Does the ExecCmd.ExecCmdSync Variant run for you?

    Thursday, June 19, 2014 6:19 PM
    Answerer
  • PS: about 'more on the safe side' - Always remember: The LDProcess.Start, ExecCmd.ExecCmdSync and generally all/some CMD commands are EXTREMELY POWERFULL commands and you should always know what you're doing. These commands or their improper usage and execution can make systemwide damage on your machine. So NEVER execute them on good luck and always think twice before. (eg. ask JJ, who ran an LDProcess.Start in a 'While "True"' loop (?? i think) and could'nt start his SBIDE any more. As a harmless sample!)

    Sample Variant6:

    This is very important - you can make a really bad day for yourself - I check ALL of the code of EVERY Small Basic sample I download or run (NO EXCEPTIONS EVER) - with power comes responsibility!

    If unsure, run without extensions (I just rename lib as something else to see what extension methods are used) and if an extension is needed it should have been stated somewhere and check what it does.


    Thursday, June 19, 2014 6:32 PM
    Moderator
  • Pappa Lapub,

    If I open a cmd window and then type in: ExecCmd.ExecCmdSync it comes back and says that this is not recognized as an internal or external command. I even searched for this online and didn't get any hits. Where does this command come from? I'm running 8.1 so maybe it's not included in the command set.


    JR

    Thursday, June 19, 2014 7:02 PM
    Answerer
  • Of course Cmd.exe will not find an ExecCmd.ExecCmdSync !!

    ExecCmd.dll is an Extension and needs to be (with it's ExecCmd.xml) in your SB\lib folder (like every other SB extension) to be accessable via your SBCode.

    see here Extension to Execute a ShellCommand and get CMD output

    and DL link is ExecCmd-SBExt.zip

    Unpack the downloaded ExecCmd-SBExt.zip to any folder. Lets say C:\Temp\ExecCmd.

    If you wanna compile the included ExecCmd.cs by yourself, open a CommandPrompt window in that folder and type "CSComp.bat /?"  followed by Return key to show the help. (First check line 16 of CSComp.bat, if path to 'SmallBasicLibrary.dll' is correct - this is for 32bit systems - if you're on a 64bit system change it to C:\Program Files (x86)\Microsoft\Small Basic\SmallBasicLibrary.dll. Then you can run "CSComp.bat ExecCmd.cs" to compile new. Maybe edit the ExecCmd.xml to a better english too :-).

    Simply copy (after or without new compiling) the ExecCmd.dll and ExecCmd.xml to your SB\lib directory, restart SBIDE and ExecCmd.ExecCmdSync  will appear in your IntelliSense and you can test it with code like:

    TextWindow.WriteLine("* Example: running 'ipconfig.exe /all':")
    IPAll = ExecCmd.ExecCmdSync("ipconfig.exe /all")
    TextWindow.WriteLine(IPAll)
    
    ' Info: running "systeminfo.exe"  can take up to ~1min until all infos are gathered
    TextWindow.WriteLine("* Example: running 'systeminfo.exe /?':")
    SysInfoHlp = ExecCmd.ExecCmdSync("systeminfo.exe /?")
    TextWindow.WriteLine(SysInfoHlp)

    Sorry JR, there's a link in the codeblock above (my 1st post) under the line

    ' see execute-a-shellcommand-and-get-cmd-output

    but that's hard to see. The extension only contains this single method and was only thought as a demo because the similar method in Fremy's Ext did'nt work.

    Thursday, June 19, 2014 8:14 PM
    Answerer
  • Pappa Lapub,

    I had looked at the SB extensions and didn't see it. I tried the download and it said I had to be a member to do the download. That's OK. I have all of the other variants to use. Thanks for all of the info.


    JR

    Thursday, June 19, 2014 10:36 PM
    Answerer
  • That's strange anyhow, again same prob again for you. Don't know your country, but never heard about that prob or about membership there. Also i myself, i did never register there and it's completely free.

    Anyway, looking for 'free file upload', i upped it to Sendspace here as ExecCmd-SBExt.zip (4.84KB).

    Download worked for me and both files (from File-Upload and SendSpace) are MD5 identical (0d3e2f03cedc272f5509588ba5e68c0f)

    Maybe you have a script blocker (like NoScript or similar running) or DL from FileUpload is'nt possible from your country or continent.



    Thursday, June 19, 2014 11:01 PM
    Answerer
  • How about you WhTurner? Does the ExecCmd.ExecCmdSync Variant run for you?

    Hello pappa Lapub,

    I have no experiance with the ExecCmd extension. I have some experiance with programming in the cmd "window", so I only looked at the help for the CMD command.


    Jan [ WhTurner ] The Netherlands

    Friday, June 20, 2014 8:48 AM
    Answerer