[dba-VB] VB6 Shell

MartyConnelly martyconnelly at shaw.ca
Thu Nov 18 14:32:16 CST 2004


How about using the shell.application object, I only came across these 
methods recently
See  url below for more examples under methods vbscript samples

'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/objects/shell/browseforfolder.asp

' Some caveats you may get odd results if opening to printers or network 
neighbourhoods
'trying to pick an individual file on winxp using 
objShell.BrowseForFolder method will gpf , known bug
'but works under win 2000

Here are some examples

  Function fnShellExploreJ()
'opens windows explorer at  a specific directory in this example c:\
     Dim objShell as object
       
        Set objShell = CreateObject("Shell.Application")
        objShell.Explore ("C:\")

        Set objShell = Nothing
    End Function

Sub testshell()
'open various control panel windows
Dim shl As Object
Set shl = CreateObject("Shell.Application")
'shl.ControlPanelItem CStr("desk.cpl")

'opens Analog clock and date selection panel
shl.ControlPanelItem CStr("TIMEDATE.CPL")

'shl.ControlPanelItem CStr("INETCPL.CPL")
'--CPL files and their respective Control Panel windows:

'--DESK.CPL - Display Properties
'--INETCPL.CPL - Internet Properties
'--MMSYS.CPL - Multimedia Properties
'--MODEM.CPL - Modems Properties
'--NETCPL.CPL - Network
'--PASSWORD.CPL - Passwords
'--POWERCFG.CPL - Power Management Properties
'--APPWIZ.CPL - Add/Remove Programs
'--MAIN.CPL - Main - defaults to mouse properties.
'--SYSDM.CPL - System Properties
'--TELEPHON.CPL - Telephony
'--TIMEDATE.CPL - TimeDate
'--STICPL.CPL - Scanners and Cameras
'--
Set shl = Nothing
End Sub

Function fnShellFindFilesVB()
'opens find or search file window
        Dim objShell
       
        Set objShell = CreateObject("Shell.Application")
        objShell.FindFiles

        Set objShell = Nothing
    End Function

   Function fnShellOpenVB()
        Dim objShell
       
        Set objShell = CreateObject("Shell.Application")
        objShell.Open ("C:\")

        Set objShell = Nothing
    End Function

    Function fnShellExploreJ()
'opens windows explorer at  a specific directory in this example c:\temp
     Dim objShell
       
        Set objShell = CreateObject("Shell.Application")
        objShell.Explore ("C:\temp")

        Set objShell = Nothing
    End Function

 Function fnShellExploreVB()
'opens win explorer at os Windows directory
        Dim objShell
        Dim ssfWINDOWS
        ssfWINDOWS = 36

        Set objShell = CreateObject("Shell.Application")
        objShell.Explore (ssfWINDOWS)

        Set objShell = Nothing
    End Function

 Function fnFolderTitleVB()
'browse for folder then display folder title chosen
        Dim objShell
       
        Set objShell = CreateObject("Shell.Application")
        If (Not objShell Is Nothing) Then
            Dim objFolder
            Dim ssfPROGRAMS
           
            ssfPROGRAMS = 2
            Set objFolder = objShell.NameSpace(ssfPROGRAMS)
            If (Not objFolder Is Nothing) Then
                MsgBox objFolder.Title
            End If
            Set objFolder = Nothing
        End If
        Set objShell = Nothing
    End Function

 Function fnFolderObjectItemsVB()
'count or display items in a folder
        Dim objShell
        Dim objFolder
        'Dim objFolderItems
        Set objShell = CreateObject("Shell.Application")
        Set objFolder = objShell.NameSpace("C:\Temp2")

        If (Not objFolder Is Nothing) Then
            Dim objFolderItems

            Set objFolderItems = objFolder.Items
          'you can list all items in folder here
            If (Not objFolderItems Is Nothing) Then
                MsgBox objFolderItems.Count
            End If

            Set objFolderItems = Nothing
        End If

        Set objFolder = Nothing
        Set objShell = Nothing
    End Function



bkollodge at parkindustries.com wrote:

>Do any VB6 programmers know how to use the shell to run a systems app
>such as explorer?  The "target" was copied from my desktop shortcut but
>doesn't work - I must be missing some syntax???
>
>Private Sub Command1_Click()
>   RetVal = Shell("%SystemRoot%\explorer.exe", vbMaximizedFocus)
>End Sub
>
>Thanks,
>Bill Kollodge
>Electrical Engineering / CNC Products
>Park Industries
>St. Cloud, MN  56303
>bkollodge at parkindustries.com
>
>_______________________________________________
>dba-VB mailing list
>dba-VB at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/dba-vb
>http://www.databaseadvisors.com
>
>
>  
>

-- 
Marty Connelly
Victoria, B.C.
Canada






More information about the dba-VB mailing list