• RSS
  • Twitter
  • FaceBook

Security Forums

Log in

FAQ | Usergroups | Profile | Register | RSS | Posting Guidelines | Recent Posts

VB shell function on XP

Users browsing this topic:0 Security Fans, 0 Stealth Security Fans
Registered Security Fans: None
Post new topic   Reply to topic   Printer-friendly version    Networking/Security Forums Index -> Programming and More

View previous topic :: View next topic  
Author Message
Wombat
Trusted SF Member
Trusted SF Member


Joined: 24 Apr 2002
Posts: 0
Location: Canberra

Offline

PostPosted: Wed Jul 24, 2002 4:09 am    Post subject: VB shell function on XP Reply with quote

Hi everyone,

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.


Code:
Shell ("start " & Chr(34) & "C:\Folder Contents.txt" & Chr(34)), vbHide


Does anyone know why it won't work in XP?

Thanks in advance!
Back to top
View user's profile Send private message
TheKingster
Link Spammer
Link Spammer


Joined: 03 May 2002
Posts: 0
Location: UK

Offline

PostPosted: Wed Jul 24, 2002 12:04 pm    Post subject: Reply with quote

You need to use an API call
Back to top
View user's profile Send private message
Wombat
Trusted SF Member
Trusted SF Member


Joined: 24 Apr 2002
Posts: 0
Location: Canberra

Offline

PostPosted: Fri Aug 16, 2002 2:26 am    Post subject: Reply with quote

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 Wink ).

In General Declarations:



Code:
' 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:

Code:
Function StartDoc(DocName As String) As Long
    Dim Scr_hDC As Long
    Scr_hDC = GetDesktopWindow()
    StartDoc = ShellExecute(Scr_hDC, "Open", DocName, _
    "", "C:\", SW_SHOWNORMAL)
End Function


Then where you want to open the file:

Code:
    r = StartDoc("C:\myFile.txt") ' Edit this line!
    If r <= 32 Then
        'There was an error
        Select Case r
            Case SE_ERR_FNF
                strMessage = "File not found"
            Case SE_ERR_PNF
                strMessage = "Path not found"
            Case SE_ERR_ACCESSDENIED
                strMessage = "Access denied"
            Case SE_ERR_OOM
                strMessage = "Out of memory"
            Case SE_ERR_DLLNOTFOUND
                strMessage = "DLL not found"
            Case SE_ERR_SHARE
                strMessage = "A sharing violation occurred"
            Case SE_ERR_ASSOCINCOMPLETE
                strMessage = "Incomplete or invalid file association"
            Case SE_ERR_DDETIMEOUT
                strMessage = "DDE Time out"
            Case SE_ERR_DDEFAIL
                strMessage = "DDE transaction failed"
            Case SE_ERR_DDEBUSY
                strMessage = "DDE busy"
            Case SE_ERR_NOASSOC
                strMessage = "No association for file extension"
            Case ERROR_BAD_FORMAT
                strMessage = "Invalid EXE file or error in EXE image"
            Case Else
                strMessage = "Unknown error"
        End Select
        MsgBox strMessage
    End If
Back to top
View user's profile Send private message
Display posts from previous:   

Post new topic   Reply to topic   Printer-friendly version    Networking/Security Forums Index -> Programming and More All times are GMT + 2 Hours
Page 1 of 1


 
Jump to:  
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!

Community Area

Log in | Register

Readers' Choice

Which is your preferred data recovery solution?

Follow TechGenix on Twitter