Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Shell, ShellExecute, CreateProcess..blah blah blah

Posted on 2000-04-19
24
Medium Priority
?
550 Views
Last Modified: 2010-05-18
I have tried using

shell
shellexecute
createprocess

to run an shortcut which points to a folder.  If I have testdir.lnk that poins to c:\testdir none of these calls will open the directory.  how can i open the directory a shortcut poins to.  Cant alter the shortcut.  The assumption is that the user is stupid and just clicks on pretty pictures.
0
Comment
Question by:groone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 5
  • 5
  • +4
24 Comments
 
LVL 5

Expert Comment

by:KDivad
ID: 2733108
Simplest way:

x = Shell("Start " & LNKFileName)
0
 
LVL 3

Author Comment

by:groone
ID: 2733163
Sorry KDivad, shell doesnt work that way.  Thanks for the input though
0
 
LVL 3

Author Comment

by:groone
ID: 2733175
Let me rephrase that...it works that way, BUT it produces an error to open the directory folder and it does not support long names.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:Ruchi
ID: 2733291
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2733360
In support of KiDavid's comment.. it will support long file names if you just add a double quote before and after the LNKFileName. Eg.

Dim strFileNameLink as String
strFileNameLink = "c:\windows\desktop\Microsoft Word.lnk"

Shell("Start " & """" & strFileNameLink & """")

Where """" = 4 Double quotes in a row.

With that.. his solution works very nicely.. <smile>.



0
 
LVL 5

Expert Comment

by:KDivad
ID: 2733636
wsh2, Thanks for the defense.
0
 

Expert Comment

by:RuslanM
ID: 2733687
Just use :
Shell Explorer.exe & " " & DirectoryName

It should work.
0
 
LVL 3

Author Comment

by:groone
ID: 2734385
Shell("Start " & """" & strFileNameLink & """")

Works if the directory names are not long

If I had

strFileNameLink = "C:\my long named directory\and its long named subdirectory\shortcut to program.lnk"

Shell would not work, no matter what you did, AND with short names it still produces a dos error about incorrect parameter settings

0
 

Expert Comment

by:RuslanM
ID: 2734429
Try this :
Shell "Explorer.exe " " & LinkFileName
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2734976
RuslanM:
I think you mean the Directory/FileName contained in the shortcut, rather than the shorcut itself.. <smile>.

Shell "Explorer.exe """ & FileName & """"
0
 
LVL 5

Expert Comment

by:KDivad
ID: 2737043
Here's what I did:

1. Created a shortcut to the folder "C:\Program Files\Accessories" and named it "Access.lnk"
2. Put it in the folder "C:\Program Files"
3. Shell "Start " & Chr$(34) & "C:\Program Files\Access.lnk" & Chr$(34)

It worked fine.
0
 
LVL 3

Author Comment

by:groone
ID: 2737390
Yes it opens the directory for browsing, BUT it creates a dos incorrect parameter error.
0
 
LVL 5

Expert Comment

by:KDivad
ID: 2738572
That's odd, because it doesn't on my machine.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2738668
KDivad.. your code runs perfectly.. <smile>. But I just saw something in groone's comment.. that could cause the error.. DOS only supports Directory pathnames up to 68 characters long.. <sigh>.. and groone loaded an epic.. <sheesh>.

Its still ok though.. we can still get around it with code.. <smile>. Using Groone's example:

Dim strLinkPath as String
strLinkPath = "C:\my long named directory\and its long named subdirectory\"

Dim strLinkFile as String
strLinkFile = "shortcut to program.lnk"

' Change Directory
ChDir strLinkPath

' Shell directly to the Link
Shell("Start " & """" & strLinkFile & """")

' Restore Directory
ChDir App.Path



0
 
LVL 3

Author Comment

by:groone
ID: 2738707
hmm...interesting wsh2

I will try that as soon as I get home
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2738716
Well.. now that I have a little time.. let me show you another way to do what the questioner wants.. <smile>. In your project set a reference (VB Menu -> Project -> References) to the "Windows Scripting Host Object" (WSHOM.OCX).. change the wshShell.CreateShortcut parameter below to a legitimate Link.. and Voile.. you have a Link to Executable runtime.. with no 68 character limitation.. <smile>.

<----- Code Begin ----->

Dim wshShell As IWshShell_Class
Set wshShell = CreateObject("Wscript.Shell")

Dim wshShortCut As IWshShortcut_Class
Set wshShortCut = wshShell.CreateShortcut("c:\windows\desktop\winamp.lnk") ' <-- CHANGE

Shell (wshShortCut.TargetPath)

<----- Code End ----->
0
 
LVL 4

Expert Comment

by:dreamvb
ID: 2738868
Dim zFilename As String
 zFilename = "C:\MyFolder.lnk"
  Shell "start.exe " & zFilename, vbHide
 
0
 
LVL 5

Expert Comment

by:KDivad
ID: 2739411
<<DOS only supports Directory pathnames up to 68 characters long>>

Are you sure? I switched to DOS and played with this folder: "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\40\BIN" (which is 75 chars long) and had no trouble. Besides, if that was the case, should the folder have opened at all? groone says "Yes it opens the directory for browsing, BUT it creates a dos incorrect parameter error".

Groone, I have some code to extract the file/folder from a .lnk file. You could do this and use: Shell "explorer.exe " & Foldername as was previously mentioned. I haven't posted (or even mentioned) it because it took me a good while to figure it out and (in my opinion) is worth more than 50 points. The code itself is relatively simple, it just took me a while to decipher enough of the .lnk to get it. Returns either short or long path as desired.
0
 
LVL 3

Author Comment

by:groone
ID: 2739481
I'm working on trying to get the command line from the lnk.  There is a api call that does it, just doing some reading to figure out how it works.  If I get it, perhaps we can share code.  I's funny, because if I use the command line of the lnk insead of the actual shortcut the folder opens just fine.

As of right now, I sill get the dos box stating an incorrect parameter setting.

This is one of the wierdest things I have ever seen.  I believe there is more to it then jus saying
shell path, vbNormalShow
(the T on my keyboard is going out)

Unforunately I don have many more points so i will have o just hope for the bes...thanks anyway.
0
 
LVL 14

Accepted Solution

by:
wsh2 earned 360 total points
ID: 2739978
You don't need APIs.. as I indicated earlier.. use the "Windows Scripting Host" to get the Shortcut.. extract the executable name, and then run it.

--------------------------------------
In your project set a reference (VB Menu -> Project -> References) to the "Windows Scripting Host Object" (WSHOM.OCX)

<----- Code Begin ----->

Dim wshShell As IWshShell_Class
Set wshShell = CreateObject("Wscript.Shell")

Dim wshShortCut As IWshShortcut_Class
Set wshShortCut = wshShell.CreateShortcut("c:\windows\desktop\winamp.lnk")

Shell (wshShortCut.TargetPath)

<----- Code End ----->

It is 4 lines of code.. and then a Shell command to run it.

======================================
As to the Invalid Parameter message, I am curious as to how your COMSPEC environment variable reads.


 
0
 
LVL 3

Author Comment

by:groone
ID: 2740050
rofl..you sure did mention that.  how could I have over looked hat.
0
 
LVL 3

Author Comment

by:groone
ID: 2740069
Adjusted points from 50 to 90
0
 
LVL 3

Author Comment

by:groone
ID: 2740070
Wsh2, perfect thanks!
0
 
LVL 9

Expert Comment

by:Dalin
ID: 2769387
viewed
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question