Posted: Wed Jul 24, 2002 4:09 am Post subject: VB shell function on XP
Ages ago I wrote a little VB program to list all files and folders in a folder (in an indented heirarchical format). The list was written to a text file, and the app then used the shell function to launch the text file.
All worked fine on '98, but a while ago I got XP. I went to use my app just now, and it won't launch the text file. At the time it was just an exercise in using the FileSystemObject, but now I need to use the shell function in another app to launch a file in the same way. I've searched MSDN and the web but got reams of nothing.
Sorry for the huge delay replying but I've been tied up on other projects.
Thanks very much Kingster that did the trick. For anyone else wanting to do the same, here's the code to copy'n'paste (it looks like a lot but there's only one line to change for your file ).
In General Declarations:
' API stuff for launching the file:
Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As _
String, ByVal lpszFile As String, ByVal lpszParams As String, _
ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Const SW_SHOWNORMAL = 1
Const SE_ERR_FNF = 2&
Const SE_ERR_PNF = 3&
Const SE_ERR_ACCESSDENIED = 5&
Const SE_ERR_OOM = 8&
Const SE_ERR_DLLNOTFOUND = 32&
Const SE_ERR_SHARE = 26&
Const SE_ERR_ASSOCINCOMPLETE = 27&
Const SE_ERR_DDETIMEOUT = 28&
Const SE_ERR_DDEFAIL = 29&
Const SE_ERR_DDEBUSY = 30&
Const SE_ERR_NOASSOC = 31&
Const ERROR_BAD_FORMAT = 11&
Then a new function:
Function StartDoc(DocName As String) As Long
Dim Scr_hDC As Long
Scr_hDC = GetDesktopWindow()
StartDoc = ShellExecute(Scr_hDC, "Open", DocName, _
"", "C:\", SW_SHOWNORMAL)
Then where you want to open the file:
r = StartDoc("C:\myFile.txt") ' Edit this line!
If r <= 32 Then
'There was an error
Select Case r
strMessage = "File not found"
strMessage = "Path not found"
strMessage = "Access denied"
strMessage = "Out of memory"
strMessage = "DLL not found"
strMessage = "A sharing violation occurred"
strMessage = "Incomplete or invalid file association"
strMessage = "DDE Time out"
strMessage = "DDE transaction failed"
strMessage = "DDE busy"
strMessage = "No association for file extension"
strMessage = "Invalid EXE file or error in EXE image"
strMessage = "Unknown error"
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
Looking for more Windows Networking info?
Sign up to the WindowsNetworking.com Monthly Newsletter, written by Enterprise Security MVP Deb Shinder, containing news, the hottest tips, Networking links of the month and much more. Subscribe today and don't miss a thing! View a sample newsletter.
Become a WindowsNetworking.com member!
Discuss your Windows Networking issues with thousands of other Windows Newtorking experts. Click here to join!