Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...This is easily the most helpful website I've ever used, and this is the best forum with the quickest response time bar none...."

Geography

Where in the world do Tek-Tips members come from?

Can I use Shell to open just a folder or run a shortcut?

tedsmith (Programmer)
11 Jun 12 9:12
I have tried Shell in my app to do 2 things without success
1. Open just a folder eg Shell ("C:\Myfolder",vbNormalFocus)
2. Open a vnc shortcut to start VNC viewer to remote desktop to another computer eg Shell ("c:\VNCFolder\10.208.9.123.vnc",vbNormalFocus). "10.208.9.123.vnc" is a shortcut to opening the remote desktop on the required computer and appears to be an ini type file.

Both the statements within the ( ) do the desired thing when entered in the Windows Explorer address box.

What am I doing wrong?
HughLerwill (Programmer)
11 Jun 12 9:35
> do the desired thing when entered in the Windows Explorer address box

So try;

Shell "Explorer C:\MyFolder", vbNormalFocus

etc.
tedsmith (Programmer)
11 Jun 12 9:44
I found an old answer in thread222-749475: How to execute shortcuts using VB 6.0?
Sorry I should have looked first!
strongm (MIS)
11 Jun 12 9:47
The Shell command does not do what you think it does. Specifically, as per the documentation, it runs an executable program. In neither case are you passing it the name of an executable program. Here, have 3 short examp0les of variants that should work:

CODE


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

' These are actually examples of the original API versions of the VBAppWinStyle enumeration
Private Const SW_MAXIMIZE = 3 ' vbMaximizedFocus
Private Const SW_MINIMIZE = 6 ' vbMinimizedNoFocus
Private Const SW_SHOWNORMAL = 1 'vbNormalFocuc

Public Sub spoon()
ShellExecute 0&, "open", "C:\temp", vbNullString, vbNullString, SW_SHOWNORMAL
End Sub

Public Sub wombat()
Shell "rundll32.exe url.dll,FileProtocolHandler C:\temp", vbNormalFocus
End Sub


Public Sub mike()
CreateObject("Shell.application").ShellExecute "c:\temp", , , , SW_SHOWNORMAL
End Sub
tedsmith (Programmer)
11 Jun 12 9:57
Thanks/ I used the Shellexecute OK but the only problem is that if the shortcut is missing it doesn't show any file missing warning (like shell does with a file) - just nothing happens.
dilettante (MIS)
11 Jun 12 10:11

CODE

Const ssfDesktop = 0
Dim FolderItem As Object

With CreateObject("Shell.Application").NameSpace(ssfDesktop)
On Error Resume Next
FolderItem = .ParseName("c:\temp\fudd.dud")
If Err Then
MsgBox "No such file"
Else
FolderItem.InvokeVerb
End If
On Error GoTo 0
End With

Also works back to earlier Shell versions (Win98, Win95+Desktop Update, etc.).
tedsmith (Programmer)
11 Jun 12 20:25
Thanks
However I simply used the return value of Shellexecute
The remote desktop 'shortcut' is in the form of "MyIPAddress.vnc"

CODE

  w = ShellExecute(hwnd, "open", "c:\VNCInfo\" & MyIPAddress & ".vnc", vbNullString, vbNullString, SW_SHOWNORMAL)
    Select Case w
        Case 2
            MsgBox "VNC Shortcut for stop" & MyIPAddress & vbCr & "is not in the c:\VNCInfo\ folder.", vbCritical, "No File Found"
        Case Is > 31
            'OK
        Case Else
            'Other error
            MsgBox "VNC may not be installed or set up correctly" & vbCr & "Try direct VNC connection to the stop IP address.", vbCritical, "No VNC"
    End Select

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close