Solved

Connect to a Network Drive and open a file using Visual Basic

Posted on 2006-11-17
4
1,879 Views
Last Modified: 2011-09-20
Hello:

I am creating a Visual Basic 5.0 application and I placed a command control button on a form. Behind the command button, I need to put in code that will do the following:

Look at a Network Drive and launch an .exe(ex: dan.exe) file no matter where it is located on the drive and run it ontop of the form.

Is this possible?

If so, can you give me some examples of code on how I can do this?

Thanx,

Dan M
0
Comment
Question by:dmfish1968
[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
4 Comments
 
LVL 2

Accepted Solution

by:
jay_s5 earned 250 total points
ID: 17967987
Hi Dan,

There are basically two ways to run an application from a VB app. Take a look at this KB article for details and sample code for each:

http://support.microsoft.com/kb/129797

You would simply add code to substitute the name of your executable (dan.exe) where they used calc.exe in the examples.

I need more specifics on what you are doing with the network drive to help with that part.
0
 
LVL 2

Assisted Solution

by:sb_ee
sb_ee earned 250 total points
ID: 17968037
'Step 1: Map the target network drive if you haven't map yet like "H:/" on your computer. Else", just skip to step 2 and put in "H:/" as the target drive.

'Find and check the Windows Script Host object from Project - Reference

'code this under your command button

Private Sub Command1_Click()

Dim onet As New WshNetwork
Dim strTargetdrive as String

On Error GoTo Command1_Click_Error

strTargetdrive="H:"

onet.MapNetworkDrive strTargetdrive, "\\" & servername & "\" & sharename
'replace with the your targer servername and the sharename; you may name other letter than H, but make sure no other drive using the same

'If the user is not logged on to the network you will have to do this:
onet.MapNetworkDrive strTargetdrive, "\\" & servername & "\" & sharename, , DomainName\UserName, Password

'call step 2

'call step 3

Exit Sub

Command1_Click_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Command1_Click of Form Form1"

End Sub


'Step 2: Search the network drive for the target file and get its path

'You need to select the Microsoft Scripting Runtime from Reference. But I don't recall VB 5 has it. So you either go for VB 6 or use the API Call as explained from the link:

http://support.microsoft.com/kb/185476/EN-US/

'You need to return the target path from the search function againsting the target exe file

'Step 3: fire up the exe file

Dim strTarget As String
strTarget =  thetargetpathfromstep2 & targetexefilename
Call ShellExecute(0, "Open", strTarget, "", "", 1)

'at the end, you could even check if the Shelled process has terminated or not from the sample code at this link:
http://support.microsoft.com/kb/96844/EN-US/


HTH

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is about my first experience with programming Arduino.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

740 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