VB.net shell call

Add-in Express™ Support Service
That's what is more important than anything else

VB.net shell call
mading the code wait for a shell to close 
Jonathan Dorling




Posts: 31
Joined: 2005-06-14
hi there,

When i run this code with any exe it look as if outlook as crashed and the cpu on notepad.exe in task manager is 99%, How can i get round this if i run it as shell(cmdline) in works fine but i need to code that run after the shell window as been close?


Private Sub Fax_BW_Click(ByVal sender As Object) Handles Fax_BW.Click

'starting code
Dim PID As Integer
Dim cmdline As String
cmdline = "c:\WINDOWS\notepad.exe"

PID = Shell(cmdline, AppWinStyle.NormalFocus, True, 600000)

MsgBox(Format(PID))

'after code

End Sub


Posted 17 Jun, 2005 06:08:46 Top
Sergey Grischenko


Add-in Express team


Posts: 7187
Joined: 2004-07-05
Hi Jonathan.

Try to use the System.Diagnostics.Process class to implement your idea.
You can find some examples in MSDN.
Posted 17 Jun, 2005 08:34:43 Top
Jonathan Dorling




Posts: 31
Joined: 2005-06-14
could you point me to one so i get it right please? or send me an example over please

rememeber i need the shell call to wait for x seconds or continue when the shell is exit

example would be better

thnaks

Jonathan
Posted 17 Jun, 2005 08:38:30 Top
Sergey Grischenko


Add-in Express team


Posts: 7187
Joined: 2004-07-05
Try the following code.

Try

Dim myProcess As Process
myProcess = Process.Start("Notepad.exe")
' Display physical memory usage 5 times at intervals of 2 seconds.
Dim i As Integer
For i = 0 To 4
If not myProcess.HasExited Then

' Discard cached information about the process.
myProcess.Refresh()
' Print working set to console.
Console.WriteLine("Physical Memory Usage: " + _
myProcess.WorkingSet.ToString())
' Wait 2 seconds.
Thread.Sleep(2000)
Else
Exit For
End If

Next i

' Close process by sending a close message to its main window.
myProcess.CloseMainWindow()
' Free resources associated with process.
myProcess.Close()

Catch e As Exception
Console.WriteLine("The following exception was raised: ")
Console.WriteLine(e.Message)
End Try
Posted 17 Jun, 2005 09:08:09 Top
Jonathan Dorling




Posts: 31
Joined: 2005-06-14
but with that you have to wait for the 2sec before seeing if they have exit which is just about ok but not the best.

But why does PID = Shell(cmdline, AppWinStyle.NormalFocus, True, 600000) not work with add-in Express.net
Posted 17 Jun, 2005 10:33:24 Top
Eugene Starostin


ADX Team
Add-in Express team


Posts: 430
Joined: 2004-04-05
Jonathan,

You emulate calling PID = Shell(cmdline, AppWinStyle.NormalFocus, True, 600000) in pure VBA to make sure if the problem relates to Add-in Express.
Posted 17 Jun, 2005 10:36:22 Top
Sergey Grischenko


Add-in Express team


Posts: 7187
Joined: 2004-07-05
Jonathan, what do you mean that it doesn't work with ADX?
I have just tested your code and all works fine.

Private Sub AdxCommandBarButton1_Click(ByVal sender As Object) Handles AdxCommandBarButton1.Click

Dim PID As Integer
Dim cmdline As String = "D:\Windows\notepad.exe"

PID = Shell(cmdline, AppWinStyle.NormalFocus, True, 600000)

MessageBox.Show(PID.ToString())

End Sub
Posted 17 Jun, 2005 10:56:21 Top
Jonathan Dorling




Posts: 31
Joined: 2005-06-14
the call

Dim cmdline As String = "D:\Windows\notepad.exe"

PID = Shell(cmdline, AppWinStyle.NormalFocus, True, 600000)


works fine with in my form and then i using ADX with outlook to made it a command bar button and it made outlook crashed (and goes white) and send the cmdline program to 100% put u get still use the computer and the cmdline program

i do the call like
Dim cmdline As String = "D:\Windows\notepad.exe"

PID = Shell(cmdline)


and it works fine with ADX

jonathan
Posted 17 Jun, 2005 17:20:55 Top
Sergey Grischenko


Add-in Express team


Posts: 7187
Joined: 2004-07-05
Hi Jonathan.

Could you show me the code that you use to add a control to Outlook?
Posted 19 Jun, 2005 04:45:38 Top
Jonathan Dorling




Posts: 31
Joined: 2005-06-14
this is the button if you want more just say!!

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Dim PID As Integer
Dim cmdline As String = "C:\Windows\notepad.exe"

PID = Shell(cmdline, AppWinStyle.NormalFocus, True, 600000)

MsgBox(PID.ToString())

End Sub


that is it???

thanks again
Posted 20 Jun, 2005 03:46:14 Top