Solved

Specifying a "start in" or working directory

Posted on 2006-03-27
3
207 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
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 500 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

831 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