external app with arguments in working dir

jwtimmons

New member
Joined
Jan 20, 2007
Messages
3
Programming Experience
Beginner
Newbie at VB having some trouble.

I am trying to call an external exe that is very fussy about it being called from within its own directory (due to associated dlls I assume)

Things that dont' work

VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] proc [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Process = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Process[/SIZE]
[SIZE=2]proc.StartInfo.FileName = [/SIZE][SIZE=2][COLOR=#800000]"F:\rsyncrypto\rsyncrypto.exe"[/COLOR][/SIZE]
[SIZE=2]proc.StartInfo.Arguments() = [/SIZE][SIZE=2][COLOR=#800000]" c:\text.txt c:\text.enc F:\rsyncrypto\1234.KEY F:\rsyncrypto\BACKUP.CRT"[/COLOR][/SIZE]
[SIZE=2]proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden [/SIZE]
[SIZE=2]proc.Start()[/SIZE]


VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] psInfo [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Diagnostics.ProcessStartInfo([/SIZE][SIZE=2][COLOR=#800000]"F:\rsyncrypto\rsyncrypto.exe"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]" c:\text.txt c:\text.enc F:\rsyncrypto\1234.KEY F:\rsyncrypto\BACKUP.CRT"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]psInfo.WindowStyle = ProcessWindowStyle.Hidden[/SIZE]
[SIZE=2]System.Diagnostics.Process.Start(psInfo)[/SIZE]

What does is work is me going into a cmd prompt navigating to f:\rsyncrypto and running

VB.NET:
[COLOR=#800000]rsyncrypto.exe c:\text.txt c:\text.enc F:\rsyncrypto\1234.KEY F:\rsyncrypto\BACKUP.CRT[/COLOR]

I have run this in debug mode and built an exe and run the exe in F:\rsyncrypto but neither works.

So all I can think of is it that the vb isn't running in the directory and associated dlls aren't being used.

I have also tried moving the exe and files intothe debug folder and running the above without any path info but still no go


Any thoughts?



Regards


John
 
Have you looked into the WorkingDirectory property of ProcessStartInfo ?
 
yep I gave that a whirl as well but with no luck. and the tried UseShellExecute for good measure.


I'm really into the realm of voodoo coding now, throwing things at it to see what sticks :D


John

VB.NET:
[SIZE=2]proc.StartInfo.WorkingDirectory = [/SIZE][SIZE=2][COLOR=#800000]"f:\rsyncrypto"[/COLOR][/SIZE]
[SIZE=2]proc.StartInfo.UseShellExecute = [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE]
[SIZE=2]proc.Start()[/SIZE]
 
True is the default value of UseShellExecute. That documentation topic have some remarks about WorkingDirectory I don't quite understand, it seems WorkingDirectory is ignored in default case, so you might want to try specifying WorkingDirectory and setting UseShellExecute to False.
 
Found the problem ! :)

External app was taking a long time to complete and vb was looping through calling the app repeatedly causing issues.

Using a proc.WaitForExit() solve the issue
so implemented folllowing type of catch

http://support.microsoft.com/kb/305368


VB.NET:
p.WaitForExit(timeOut)
 'HasExited is true if the application closed before the time-out.     
If p.HasExited = False Then         'Process is still running.         
  'Test to see if process is hung up.         
  If p.Responding Then
     'Process was responding; close the main window. 
     p.CloseMainWindow()         
  Else             
     'Process was not responding; force the process to close.             
     p.Kill()         
  End If     
End If
Many thanks for the help


John
 
Back
Top