Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 20th, 2005, 09:37 AM
Registered User
 
Join Date: Jan 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to run files like in Windows

how can i run a file from vb, like i was double-clicking on it in Windows? <Shell> only runs executables and common programs with parameters, api's don't work much, better, and although, it isn't perfect, the best seems to be a bat file in which i write the path of the file i want to run. But when i run the bat file the command prompt will appear. So i'm back to my first question:

how can i run a file from vb, like i was double-clicking on it in Windows?

Please help, and thanks.

 
Old January 20th, 2005, 11:08 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

use ShellExecute WinAPI function. See http://support.microsoft.com/default.aspx?kbid=170918 for example
 
Old January 20th, 2005, 12:40 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

You never actually “run a file.” The program that runs the desktop (and much of Windows) is Explorer (not [u]Internet</u> Explorer). It has functionality built into it that comes into play when a file is double clicked.

If it is an executable, it loads it into memory, and starts it.

But if not, it looks up the file’s extension, checks to see if it has that extension registered, and if so, takes the action that is associated with that registration.

That is what is described in the link that pgtips provided.
 
Old January 22nd, 2005, 07:01 AM
Registered User
 
Join Date: Jan 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

the link helped. thanks
 
Old January 23rd, 2005, 11:47 AM
Authorized User
 
Join Date: Jan 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi try this out paste into a new form add a command button. F5 it

' code starts here

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

Function RunProg(hangle As Long, lzProgName As String, lpOpenState As VbAppWinStyle) As Long
    RunProg = ShellExecute(hangle, "open", lzProgName, vbNullString, vbNullString, lpOpenState)
End Function

Private Sub Command1_Click()
Dim lpReturn As Long

    lpReturn = RunProg(Form1.hwnd, "C:\test.txt", vbNormalFocus)

    If lpReturn = 2 Then
        MsgBox "Error opening file", vbInformation, "Error"
        Exit Sub
    End If

End Sub

' end of code


When ya dreams come true.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Run a Windows Service every 24 hours srkarthik_82 General .NET 5 January 10th, 2007 09:29 PM
What Windows can VB .NET App run on ocarroll General .NET 6 February 27th, 2006 08:14 AM
Files needed to run a VB.Net Windows Apps daniel VB.NET 2002/2003 Basics 2 October 15th, 2004 09:29 AM
how to run asp in windows xp cici Classic ASP Basics 2 April 16th, 2004 07:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.