Solved

Specifying a "start in" or working directory

Posted on 2006-03-27
3
202 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
  • 2
3 Comments
 
LVL 28

Expert Comment

by:vinnyd79
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
That's perfect!  Thanks vinnyd!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 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

12 Experts available now in Live!

Get 1:1 Help Now