Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shell Function and Start In Folder 2

Status
Not open for further replies.

colobill

Programmer
Dec 16, 2003
22
US
I have an application that I am using the Shell command to run. My application is in another folder. However, the application I am trying to run will not run even when passed an argument which it needs. The problem is that somehow my VB program needs to be in the application's folder in order to run. That is not possible in this case.

The closes example is when you check the properties of a desktop icon and it has a "Start In:" parameter. In VB 6 what could I do to fake out the program being called into thinking I am actually in it's folder when it is being called?
 
Show us your code to do the Shell

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Shell "C:\ASSESS\KIDSWAY.EXE ASSESS.LAP", vbNormalFocus.

The problem is that when kidsway.exe starts it apparently calls another program in that folder called slrun32 or something like that, which in turns apparently loads information from assess.lap. When I tried it in VB.NET it worked because I could set the "start in" parameter. I need to know what the VB 6 counterpart to "start in" is.
 
Your issue may be that you need a path to the parameter as well. Try:

Shell "C:\ASSESS\KIDSWAY.EXE C:\ASSESS\ASSESS.LAP", vbNormalFocus


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Tried that but did not work. Need a VB.Net "start in" [folder] parameter for VB 6.
 
You should also try ChDrive and ChDir statements to switch to the drive and folder where KIDSWAY.EXE is present. This might solve the problem.
___
[tt]
CDrive "C" 'Make sure you are switched to C drive
ChDir "C:\ASSESS" 'Switch to the desired folder
Shell "KIDSWAY.EXE ASSESS.LAP", vbNormalFocus
[/tt]
 
If, for some reason, Hypetia's solution doesn't work, try the following. For this example you'll need to add a reference to the Windows Script Host Object Model library:
[tt]
Private Function RunProgramInFolder(strProgramPath As String, strRunInFolder As String, Optional strArguments As String = "", Optional WindowStyle As WshWindowStyle = WshNormalFocus, Optional WaitOnReturn As Boolean = False) As Long
Dim TempShortcut As String

With New FileSystemObject
TempShortcut = .GetTempName & ".lnk" ' .lnk extension required
End With

With New WshShell
With .CreateShortcut(TempShortcut)
.TargetPath = strProgramPath
.WorkingDirectory = strRunInFolder
.Arguments = strArguments
.Save
End With
RunProgramInFolder = .Run(TempShortcut, WindowStyle, WaitOnReturn) ' Use .Run because the generally better .Exec doesn't work properly on shortcuts...
End With
Kill TempShortcut
End Function
 
thank you hpetia, that fixed it. Also, thank you strongm for your code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top