groone
asked on
Shell, ShellExecute, CreateProcess..blah blah blah
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.
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.
ASKER
Sorry KDivad, shell doesnt work that way. Thanks for the input though
ASKER
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.
Take a look at
http://www.mvps.org/vbnet/code/shell/shellexecute.htm
http://www.mvps.org/vbnet/code/shell/shellexecute.htm
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\Micros oft Word.lnk"
Shell("Start " & """" & strFileNameLink & """")
Where """" = 4 Double quotes in a row.
With that.. his solution works very nicely.. <smile>.
Dim strFileNameLink as String
strFileNameLink = "c:\windows\desktop\Micros
Shell("Start " & """" & strFileNameLink & """")
Where """" = 4 Double quotes in a row.
With that.. his solution works very nicely.. <smile>.
wsh2, Thanks for the defense.
Just use :
Shell Explorer.exe & " " & DirectoryName
It should work.
Shell Explorer.exe & " " & DirectoryName
It should work.
ASKER
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
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
Try this :
Shell "Explorer.exe " " & LinkFileName
Shell "Explorer.exe " " & LinkFileName
RuslanM:
I think you mean the Directory/FileName contained in the shortcut, rather than the shorcut itself.. <smile>.
Shell "Explorer.exe """ & FileName & """"
I think you mean the Directory/FileName contained in the shortcut, rather than the shorcut itself.. <smile>.
Shell "Explorer.exe """ & FileName & """"
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.
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.
ASKER
Yes it opens the directory for browsing, BUT it creates a dos incorrect parameter error.
That's odd, because it doesn't on my machine.
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
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
ASKER
hmm...interesting wsh2
I will try that as soon as I get home
I will try that as soon as I get home
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.Shel l")
Dim wshShortCut As IWshShortcut_Class
Set wshShortCut = wshShell.CreateShortcut("c :\windows\ desktop\wi namp.lnk") ' <-- CHANGE
Shell (wshShortCut.TargetPath)
<----- Code End ----->
<----- Code Begin ----->
Dim wshShell As IWshShell_Class
Set wshShell = CreateObject("Wscript.Shel
Dim wshShortCut As IWshShortcut_Class
Set wshShortCut = wshShell.CreateShortcut("c
Shell (wshShortCut.TargetPath)
<----- Code End ----->
Dim zFilename As String
zFilename = "C:\MyFolder.lnk"
Shell "start.exe " & zFilename, vbHide
zFilename = "C:\MyFolder.lnk"
Shell "start.exe " & zFilename, vbHide
<<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.
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.
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
rofl..you sure did mention that. how could I have over looked hat.
ASKER
Adjusted points from 50 to 90
ASKER
Wsh2, perfect thanks!
viewed
x = Shell("Start " & LNKFileName)