Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-11-17
4
Medium Priority
?
1,886 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 1000 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:Johnny Newbee
Johnny Newbee earned 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

609 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