VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



THE_BEST SHELL_EXECUTE_EVER

by EM Dixson (6 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Mon 27th September 1999
Date Added: Mon 8th February 2021
Rating: (1 Votes)

THE_BEST SHELL_EXECUTE_EVER

API Declarations



I'm just gonna paste the whole poop in one scoop. I recommend you do the same.

To call it just:

Call Shell("Whatever.txt") ' or ANY filename for that matter. As long as there
'is an associated extension available on the box that the program resides it 'WILL CALL ANYTHING!

'Please be advised: Even though this Module will call a .HTML file it will only
'call it from the box that it's on. It does NOT Shell to the web. It will call
'an HTML file but only like this:
Call Shell("YourFile.html")
'or like:
Call Shell("C:\Whatever\The_Path_Is_To\YourFile.html")

Your friend,
EM Dixson
http://developer.ecorp.net




Rate THE_BEST SHELL_EXECUTE_EVER



'# This code was written by Emmett Dixson (c)1999. You may alter
'# this code, trade, steal, borrow, lend or give away this code.
'# However, this code has been regisered with the Library of
'# Congress as a literary acheivement and as such excludes it
'# from being known or proclaimed as "PUBLIC DOMAIN". 
'#---------------You may NOT remove this header---------------
'#------------------You may NOT SELL this work----------------
'#----YES! You MAY use this work for commercial purposes------
'#---This code MAY NOT be sold or redistributed for profit----
'#-------- I wish you every success in your projects ---------
'#------------------------ Visit me at -----------------------
'#------------------http://developer.ecorp.net ---------------
'#-----------------FREE Visual Basic Source Code -------------
#

'For best results paste everything into a NEW MODULE and be sure
'you SAVE the module to your project. I call the module...
'Surething.bas because it won't let you down.

'Works for Win3.x, Win95,Win98,WinNT and EVEN Win2000(don't ask!)

'Here it is and it is Soooo sweet! 
'I mean it will call any file man and auto-launch it's
'associated application in any Windows OS. 

'All you have to do is enter the path and the
'file-name and extension. It is totally awesome if I do say so
'my self.....LOL. 

'Don't change anything...just paste all this crap into ONE
'MODULE that you can add to a project.

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) As Long
            
Function Shell(Program As String, Optional ShowCmd As Long = vbNormalNoFocus, Optional ByVal WorkDir As Variant) As Long

    Dim FirstSpace As Integer, Slash As Integer


    If Left(Program, 1) = """" Then
        FirstSpace = InStr(2, Program, """")


        If FirstSpace <> 0 Then
            Program = Mid(Program, 2, FirstSpace - 2) & Mid(Program, FirstSpace + 1)
            FirstSpace = FirstSpace - 1
        End If

    Else
        FirstSpace = InStr(Program, " ")
    End If

    If FirstSpace = 0 Then FirstSpace = Len(Program) + 1


    If IsMissing(WorkDir) Then


        For Slash = FirstSpace - 1 To 1 Step -1
            If Mid(Program, Slash, 1) = "\" Then Exit For
        Next



        If Slash = 0 Then
            WorkDir = CurDir
        ElseIf Slash = 1 Or Mid(Program, Slash - 1, 1) = ":" Then
            WorkDir = Left(Program, Slash)
        Else
            WorkDir = Left(Program, Slash - 1)
        End If

    End If

    Shell = ShellExecute(0, vbNullString, _
    Left(Program, FirstSpace - 1), LTrim(Mid(Program, FirstSpace)), _
    WorkDir, ShowCmd)
    If Shell < 32 Then VBA.Shell Program, ShowCmd 'To raise Error
End Function



Download this snippet    Add to My Saved Code

THE_BEST SHELL_EXECUTE_EVER Comments

No comments have been posted about THE_BEST SHELL_EXECUTE_EVER. Why not be the first to post a comment about THE_BEST SHELL_EXECUTE_EVER.

Post your comment

Subject:
Message:
0/1000 characters