A little VB script help?

Associate
Joined
29 Aug 2006
Posts
867
Location
South London
Hi, I’m trying to write a script in visual basic (2005 express) to close an external application. The script I’ve already done to open the aforementioned application uses the lines of code:

Shell("C:\mplayerc.exe C:\Media\Spacetheme.AVI", vbNormalFocus)
Me.Close()

Does anyone know what I should write for a separate script that when run, would close the above application at any given moment?

Thanks very much :)
 
Opening and closing application can be very tricky.

Since you are using 2005 i would look at the Process namespace this can be used to open and close programms.
 
Sorry I’m not sure I follow what you're saying :confused: Do you mean there's a way to close the application using the same kind of method I used to open it? Is there some command like 'Close.Shell' that I’m missing? I'm pretty new to VB, apologies for being a bit slow.
 
AWBbox said:
Sorry I’m not sure I follow what you're saying :confused: Do you mean there's a way to close the application using the same kind of method I used to open it? Is there some command like 'Close.Shell' that I’m missing? I'm pretty new to VB, apologies for being a bit slow.


There is not method to directly close a shell command. This is because the id returned by the shell command isnt compatable with the api function you would need to call to close it. It is possible to convert a shell id to a process id but ive never had much success with this and requires the use of api calls.

it is also possible to close a application bassed on its title again this is a api call.

The best method ive found is to forget about the shell command and api calls and use the new functions in .net2005.

a simple example, ive not tested this so it may not work. But the method is sound and ive used it myself.

Code:
Dim MyProcess as new process
Myprocess.startinfo = new processstartinfo("NotePad.exe",Chr(34) & "c:\ATESTFILE.txt"  & Chr(34))
MyProcess.start()
sleep(5000)
MyProcess.kill
 
Back
Top Bottom