• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

Specifying a "start in" or working directory

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
bpl5000
Asked:
bpl5000
  • 2
1 Solution
 
vinnyd79Commented:
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
 
vinnyd79Commented:
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
 
bpl5000Author Commented:
That's perfect!  Thanks vinnyd!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now