Solved

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

Posted on 2006-11-17
4
1,871 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
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

A short article about problems I had with the new location API and permissions in Marshmallow
This is about my first experience with programming Arduino.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now