Shell Function and paths 
Author Message
 Shell Function and paths

I have the following code embedded in a VB app. It launches an Access
reports module from VB.

Dim varRM As Variant
varRM = Shell("c:\program files\microsoft office\office\MSACCESS.EXE " & _
    App.Path & "\MCCTNL_Reports.mdb", vbNormalFocus)

QUESTION:  How do I get it to open MSACCESS.EXE if I am unsure of its
location? Can I use some type of wildcard, or do I need to search for the
exe and save its path to a string, then plug it in?

Any suggestions appreciated.

--
Mike Barrett
mikebarr at bellatlantic dot net

"Son, let this be a lesson to you. Never do tequila shooters
within a country mile of a marriage chapel."

...Al Bundy



Thu, 31 Jul 2003 04:57:12 GMT  
 Shell Function and paths


Quote:
>I have the following code embedded in a VB app. It launches an Access
>reports module from VB.

>Dim varRM As Variant
>varRM = Shell("c:\program files\microsoft office\office\MSACCESS.EXE " & _
>    App.Path & "\MCCTNL_Reports.mdb", vbNormalFocus)

>QUESTION:  How do I get it to open MSACCESS.EXE if I am unsure of its
>location? Can I use some type of wildcard, or do I need to search for the
>exe and save its path to a string, then plug it in?

>Any suggestions appreciated.

>--
>Mike Barrett
>mikebarr at bellatlantic dot net

>"Son, let this be a lesson to you. Never do tequila shooters
>within a country mile of a marriage chapel."

>...Al Bundy

Look at the ShellExecute API instead.

--
Tom Porterfield



Thu, 31 Jul 2003 06:00:00 GMT  
 Shell Function and paths

Quote:

>I have the following code embedded in a VB app. It launches an Access
>reports module from VB.

>Dim varRM As Variant
>varRM = Shell("c:\program files\microsoft office\office\MSACCESS.EXE " & _
>    App.Path & "\MCCTNL_Reports.mdb", vbNormalFocus)

>QUESTION:  How do I get it to open MSACCESS.EXE if I am unsure of its
>location? Can I use some type of wildcard, or do I need to search for the
>exe and save its path to a string, then plug it in?

>Any suggestions appreciated.

>--
>Mike Barrett
>mikebarr at bellatlantic dot net

>"Son, let this be a lesson to you. Never do tequila shooters
>within a country mile of a marriage chapel."

>...Al Bundy

Try this code:

' Windows API/Global Declarations
#If Win32 Then
    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
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
#Else
    Declare Function ShellExecute Lib "SHELL" (ByVal hwnd%, ByVal
lpszOp$, ByVal lpszFile$, ByVal lpszParams$, ByVal lpszDir$, ByVal
fsShowCmd%) As Integer
    Declare Function GetDesktopWindow Lib "USER" () As Integer
#End If

Private Const SW_SHOWNORMAL = 1

' Launch file and associated program
' eg.  r = StartDoc("C:\MyDocs\nswtab2\990519.csv")
Function StartDoc(DocName As String) As Long
      Dim Scr_hDC As Long
      Scr_hDC = GetDesktopWindow()
      StartDoc = ShellExecute(Scr_hDC, "Open", DocName, "", "C:\",
SW_SHOWNORMAL)
End Function

To use:

        Call StartDoc("c:\data\report.mdb")

Regards

Graham

--------------
Progressive Data Solutions
http://www.pdsolutions.com.au
Home of VB Code Cutter - VB/VBA Code Library, Dev Tool with Free code formatting/indenting



Thu, 31 Jul 2003 07:33:11 GMT  
 Shell Function and paths
As the others have told you, the ShellExecute or ShellExecuteEx API call
will probably solve your issues.

If you do need to find the path to a registered executable (i.e.: one that's
associated with a specific file extension), Randy Birch shows how to use the
FindExecutable API call at
http://www.mvps.org/vbnet/code/system/findexecutable.htm

HTH

--

Doug Steele, Microsoft Access MVP
Beer, Wine and Database Programming. What could be better?
Visit "Doug Steele's Beer and Programming Emporium"
http://I.Am/DougSteele/


Quote:
> I have the following code embedded in a VB app. It launches an Access
> reports module from VB.

> Dim varRM As Variant
> varRM = Shell("c:\program files\microsoft office\office\MSACCESS.EXE " & _
>     App.Path & "\MCCTNL_Reports.mdb", vbNormalFocus)

> QUESTION:  How do I get it to open MSACCESS.EXE if I am unsure of its
> location? Can I use some type of wildcard, or do I need to search for the
> exe and save its path to a string, then plug it in?

> Any suggestions appreciated.

> --
> Mike Barrett
> mikebarr at bellatlantic dot net

> "Son, let this be a lesson to you. Never do tequila shooters
> within a country mile of a marriage chapel."

> ...Al Bundy



Thu, 31 Jul 2003 21:07:24 GMT  
 Shell Function and paths
Hi,

With WMI, it is just a simple SELECT statement (assuming that the
application is already open):

-------------
Public Sub GetAllProcesses()
Dim objs As WbemScripting.SWbemObjectSet
Dim obj As WbemScripting.SWbemObject

    Set objs = GetObject("winmgmts:").ExecQuery( _
        "SELECT * FROM Win32_Process WHERE Name='MSACCESS.EXE'")

    For Each obj In objs
        Debug.Print obj.Name & ", " & obj.ExecutablePath
    Next obj

End Sub
------------------

You can also get the same info from other W2000 PC  (using COM+ Moniker )
by changing the GetObject to:

        Set objs = GetObject("winmgmts://Elminster").ExecQuery( ...

(and then, you can know what is actually running on the PC Elminster  :-)
... if you have the right to access that PC,  that is.)

Hoping it may help,
Vanderghast, Access MVP


Quote:
> I have the following code embedded in a VB app. It launches an Access
> reports module from VB.

> Dim varRM As Variant
> varRM = Shell("c:\program files\microsoft office\office\MSACCESS.EXE " & _
>     App.Path & "\MCCTNL_Reports.mdb", vbNormalFocus)

> QUESTION:  How do I get it to open MSACCESS.EXE if I am unsure of its
> location? Can I use some type of wildcard, or do I need to search for the
> exe and save its path to a string, then plug it in?

> Any suggestions appreciated.

> --
> Mike Barrett
> mikebarr at bellatlantic dot net

> "Son, let this be a lesson to you. Never do tequila shooters
> within a country mile of a marriage chapel."

> ...Al Bundy



Fri, 01 Aug 2003 03:45:23 GMT  
 Shell Function and paths
For the example you have given, it looks like GetObject or CreateObject might
be a better choice than shell....
Quote:

> I have the following code embedded in a VB app. It launches an Access
> reports module from VB.

> Dim varRM As Variant
> varRM = Shell("c:\program files\microsoft office\office\MSACCESS.EXE " & _
>     App.Path & "\MCCTNL_Reports.mdb", vbNormalFocus)

> QUESTION:  How do I get it to open MSACCESS.EXE if I am unsure of its
> location? Can I use some type of wildcard, or do I need to search for the
> exe and save its path to a string, then plug it in?

> Any suggestions appreciated.

> --
> Mike Barrett
> mikebarr at bellatlantic dot net

> "Son, let this be a lesson to you. Never do tequila shooters
> within a country mile of a marriage chapel."

> ...Al Bundy



Fri, 01 Aug 2003 10:09:24 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Problem: DblClick event, Shell Function and Paths

2. Problem: DblClick event, Shell Function and Paths

3. Shell Function and paths

4. Passing a file path with spaces to Shell function

5. Shell Function not shelling under Windows NT.

6. Problems with the path in the SHELL command

7. find path to exec (SHELL)

8. Does SHELL always needs full path?

9. Shell giving invalid procedure call errors, with spaces in path

10. Variables in SHELL path?

11. SHELL INSTRUCTION AND PATH ERROR

12. Path/Shell(?) question -VB5

 

 
Powered by phpBB® Forum Software