Shell "cmd.Exe", vbNormalFocus


I would I have this open to an IP address?

Private Sub Command4_Click()
Shell "c:\program files\internet explorer\iexplore.exe", vbNormalFocus
End Sub
CMILLERAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

codeconquerorCommented:
Add the following to your declarations section:

<CODE SNIPPET>
Declare Function ShellExecute& Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
                                    ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long)
Const SW_NORMAL = 1
</CODE SNIPPET>

Then call it using this:

<CODE SNIPPET>
ShellExecute hWnd, "open", sIPAddress, vbNullString, vbNullString, SW_NORMAL
</CODE SNIPPET>
PaulHewsCommented:
You can also pass the address as a parameter to the IE application:

Shell """c:\program files\internet explorer\iexplore.exe"" 127.0.0.1", vbNormalFocus

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PaulHewsCommented:
You can also pass the address as a parameter to the IE application:

Shell """c:\program files\internet explorer\iexplore.exe"" 127.0.0.1", vbNormalFocus
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

PaulHewsCommented:
Sorry for the double double posting posting...
codeconquerorCommented:
Yes, but then you are counting on the end user having Explorer and/or wanting to use Explorer.  If you use ShellExecute it will open it with the user's default browser, whether it be IE, or Opera, or Netscape.  Just a thought to keep in mind.  :)
PaulHewsCommented:
Agreed.  Also not a great idea hard coding the location... My first thought was that shellexecute would fail when passed an IP address.  However, I found you can get around it by adding the http:// prefix:

Note to CMILLER, this is supporting the solution proposed by codeconqueror.

Option Explicit
Private Declare Function ShellExecute& Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
                                    ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long)

Private Sub Command1_Click()
    ShowIP "127.0.0.1"
End Sub

Private Sub ShowIP(ByVal strAddress As String)

    If LCase(Left$(strAddress, 7)) <> "http://" Then
        strAddress = "http://" & strAddress
    End If
   
    ShellExecute Me.hWnd, "open", strAddress, vbNullString, vbNullString, vbNormalFocus
   
End Sub
nffvrxqgrcfqvvcCommented:
Option Explicit
Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_SHOWNORMAL = 1

Function LaunchBrowser(Frm As Form, WebURL As String)
    Dim TName As String, DumbFile As String
    Dim BrowserExec As String * 255
    Dim RetVal As Long
    Dim FileN As Integer
    BrowserExec = Space(255)
    TName = "C:\temphtm.HTM"
    FileN = FreeFile
    Open TName For Output As #FileN ' Create temp HTML file
    Write #FileN, "<HTML>FIND MY GOSH DARN BROWSER!<\HTML>"
    Close #FileN
    RetVal = FindExecutable(TName, DumbFile, BrowserExec)
    BrowserExec = Trim(BrowserExec)
    If RetVal <= 32 Or IsEmpty(BrowserExec) Then ' Error
        MsgBox "Could Not find associated Browser", vbExclamation, _
        "Browser Not Found"
    Else
        RetVal = ShellExecute(Frm.hwnd, "open", BrowserExec, _
        WebURL, DumbFile, SW_SHOWNORMAL)
    End If
    Kill TName
End Function


Private Sub Form_Load()

Call LaunchBrowser(Form1, "127.0.0.1")

End Sub
CMILLERAuthor Commented:
To ALL,

I was looking to hard code, I am building a form to manage my network switches.

I would like to give all of you some points, they are all good solutions.

Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.