Solved

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

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jboss 7.1 start up error 1 82
Infrastructure development vs software development 3 106
Selenium docs api java index 3 96
MySQL programmer starter 25 63
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …

739 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