?
Solved

Specifying a "start in" or working directory

Posted on 2006-03-27
3
Medium Priority
?
211 Views
Last Modified: 2012-05-05
I am launching another program using the shell statement within a VB6 program, but I need to also specify the working directory.  For example, in a shortcut to a program, you can specify the "Start in" directory.  I need to specify this as a UNC path.  Is there any way to do this within a VB program?  This is what I have tried so far:

ChDir ("\\ServerName\Share")
Shell "\\ServerName\Share\Program.exe"


Thanks for the help!
0
Comment
Question by:bpl5000
[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
  • 2
3 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 16301803
Private Declare Function SetCurrentDirectory Lib "kernel32" Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long
Private Declare Function GetCurrentDirectory Lib "kernel32" Alias "GetCurrentDirectoryA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

Private Sub Form_Load()
Dim cwd As String
Dim length As Long
SetCurrentDirectory "\\ServerName\Share"
cwd = Space(128)
length = GetCurrentDirectory(128, cwd)
cwd = Left(cwd, length)
MsgBox cwd
End Sub
0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 2000 total points
ID: 16301833
actually this should be all you need:

Private Declare Function SetCurrentDirectory Lib "kernel32" Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long

Private Sub Command1_Click()
SetCurrentDirectory "\\ServerName\Share"
Shell "\\ServerName\Share\Program.exe"
End Sub
0
 
LVL 5

Author Comment

by:bpl5000
ID: 16302240
That's perfect!  Thanks vinnyd!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 18 hours left to enroll

765 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