Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27210

VS 2008 process vs shell

$
0
0
I am trying to decide whether to use shell or a process to start a program called plot2emf.exe. This program takes a samples .hgl file and converts it to a .emf file so that I can put it in a picture box within the calling program. In my shell code below, it works fine in the effect that it runs in the background and converts .hgl files as needed, but the problem with shell is that when I go to close the main program out; I know what the plot2EMFTaskID is, but when I try to close that task ID the returned error message is: No process is associated with this object. My thought was to convert it to a process and I could just do a process.kill() within my close routine, but the problem here is that when I go to start the process, it closes out immediately after it converts the .hgl to the .emf file. I want it to stay open like it does in shell so that subsequent calls can be made for more conversions. I have tried spyXX as recommended by Dunnfiddlin, but the window is not open to 'see' it.


Here is the value for temp in my code:
"C:\Program Files\Plot2EMF\PLOT2EMF.EXE /B /Z c:\specdriver\temp\~062113095625.hgl"


Here is my attempt at using a process:
'Dim p() As Process

'p = Process.GetProcessesByName(Plot2EMFCaption) ' Don't include .exe, just the name.

'If p.Length > 0 Then

' Plot2EMFProcess.StartInfo.Arguments = " /B /Z " & tempname
' in doing some reading, I think this line will not do anything as the process has already started.
'Else
' Dim startit As New ProcessStartInfo(Plot2EMFCaption)
' startit.WindowStyle = ProcessWindowStyle.Minimized

' Plot2EMFProcess.StartInfo.FileName = PlotConverterProgram
' Plot2EMFProcess.StartInfo.Arguments = " /B /Z " & tempname
' Plot2EMFProcess.Start(startit)
' MsgBox(Plot2EMFProcess.MainWindowTitle()) ' this line was to get the window title, but it always comes back as ""
'End If


here is my code to use shell:
If Plot2EMF_Taskid = 0 Then
Plot2EMF_Taskid = Shell(temp, AppWinStyle.MaximizedFocus) 'MinimizedFocus) 'NormalFocus)
'wait(1)
Else
i = Shell(temp, AppWinStyle.MinimizedFocus) 'Additional attempts to start Plot2EMF result in the input file being passed to the original invocation
End If

My hope is that when I close the main program out, that it is closing out plot2emf before my close routine has a chance to execute, thus the reason I am getting the error when the following code executes:

If Plot2EMF_Taskid > 0 if it is > 0 , then the plot3EMF was called.
'Next line fails if plot2EMF was started before SpecDrvr
AppActivate(Plot2EMF_Taskid) 'Plot2EMFCaption
System.Windows.Forms.Application.DoEvents() 'Make sure PLot2EMF gets a chance to catch up
System.Windows.Forms.SendKeys.SendWait("% x") 'Maximize the window
System.Windows.Forms.Application.DoEvents() 'Make sure Plot2EMF gets a chance to catch up
System.Windows.Forms.SendKeys.SendWait("%fx") 'Maximize the window
System.Windows.Forms.Application.DoEvents() 'Make sure Plot2EMF gets a chance to catch up

End If

Viewing all articles
Browse latest Browse all 27210

Trending Articles