473,695 Members | 3,057 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

URGEN HELP: Starting a process from my application ???

Dear all,

I have an application which is suppose to start another executable process.
As soon as that process is running, I need to retrive its handle. The
problem of the particular process I am starting is that it has a welcome
window first which gets displayed and then the real windows after a while,in
other words it means that the process name is the same, but the handle I need
to retrive is the one from the final window and not the welome window.

So in real that means that from my main application I need to wait for a
while that the whol process started is really finishe to load befor getting
the real handle I am interresting on. The problem I get if I set a kind of
small loop in my main application is that the process I try to start is
freezed as long as I remain in my main application loop.

In other words how can I start my process, asynchronously from my main
application and then after a while try to retrive its handle ??

For you infor I use the follwoing code to starting it:
=============== =============== =============== ====

.......
Dim myProcessStartI nfo As New ProcessStartInf o(m_sIntouchIns tallPath &
"\view.exe" )
myProcessStartI nfo.UseShellExe cute = False
myProcess.Start Info = myProcessStartI nfo
myProcess.Start Info.WindowStyl e =
ProcessWindowSt yle.Normal

myProcess.Start ()
AddHandler myProcess.Exite d, AddressOf MyProcessExited
' Set 'EnableRaisingE vents' to true, to raise
'Exited' event when process is terminated.
myProcess.Enabl eRaisingEvents = True

Dim i As Integer

While m_iViewerHandle = 0 Or i < 10
m_iViewerHandle = FindWindow(vbNu llString, "VIEW")
i = i + 1
End While

m_iHandle = m_iViewerHandle
Return m_iHandle
.......

With this code, as long as I am in my While.... loop, the process I start is
freeze and my all application gets "No responding status".

To sumurize the situation I need to:
- strart my exe process without locking my my application
- retrive the correct window handle
Thanks to help me to solve my issue.
regards
CALDERARA Serge
Jul 21 '05 #1
12 2933
I suggest calling myProcess.WaitF orExit(1000) in your while loop. This will
give control to other apps (allowing them to process events) and come back to
your loop after a second (1000 mS).

Regards
John

"serge calderara" wrote:
Dear all,

I have an application which is suppose to start another executable process.
As soon as that process is running, I need to retrive its handle. The
problem of the particular process I am starting is that it has a welcome
window first which gets displayed and then the real windows after a while,in
other words it means that the process name is the same, but the handle I need
to retrive is the one from the final window and not the welome window.

So in real that means that from my main application I need to wait for a
while that the whol process started is really finishe to load befor getting
the real handle I am interresting on. The problem I get if I set a kind of
small loop in my main application is that the process I try to start is
freezed as long as I remain in my main application loop.

In other words how can I start my process, asynchronously from my main
application and then after a while try to retrive its handle ??

For you infor I use the follwoing code to starting it:
=============== =============== =============== ====

......
Dim myProcessStartI nfo As New ProcessStartInf o(m_sIntouchIns tallPath &
"\view.exe" )
myProcessStartI nfo.UseShellExe cute = False
myProcess.Start Info = myProcessStartI nfo
myProcess.Start Info.WindowStyl e =
ProcessWindowSt yle.Normal

myProcess.Start ()
AddHandler myProcess.Exite d, AddressOf MyProcessExited
' Set 'EnableRaisingE vents' to true, to raise
'Exited' event when process is terminated.
myProcess.Enabl eRaisingEvents = True

Dim i As Integer

While m_iViewerHandle = 0 Or i < 10
m_iViewerHandle = FindWindow(vbNu llString, "VIEW")
i = i + 1
End While

m_iHandle = m_iViewerHandle
Return m_iHandle
......

With this code, as long as I am in my While.... loop, the process I start is
freeze and my all application gets "No responding status".

To sumurize the situation I need to:
- strart my exe process without locking my my application
- retrive the correct window handle
Thanks to help me to solve my issue.
regards
CALDERARA Serge

Jul 21 '05 #2
HI john,

Thnaks for your answer. I give a try by changing my code according to your
advise but it is still the same. Having this while loop place my application
in a Non Responding satus and my process is partialy started but lock at the
welcome screen.

Now if I close my main application with task manager, my started process
continue to execute and open fully .....

Any other idea how to start that process and retrive its handle without
locking the whole application ? it seems it all runs in the same context and
threads that is may be the reason.. if so shouzdl I create a thread that
launch my process ?

The modify loop isas follow :
While m_iViewerHandle = 0
------> myProcess.WaitF orExit(1000)
System.Threadin g.Thread.Sleep( 500)
m_iViewerHandle = FindWindow(vbNu llString, "VIEW
- " & m_sApplicationP ath)
End While

Thnaks for your help
serge

"John Roper" wrote:
I suggest calling myProcess.WaitF orExit(1000) in your while loop. This will
give control to other apps (allowing them to process events) and come back to
your loop after a second (1000 mS).

Regards
John

"serge calderara" wrote:
Dear all,

I have an application which is suppose to start another executable process.
As soon as that process is running, I need to retrive its handle. The
problem of the particular process I am starting is that it has a welcome
window first which gets displayed and then the real windows after a while,in
other words it means that the process name is the same, but the handle I need
to retrive is the one from the final window and not the welome window.

So in real that means that from my main application I need to wait for a
while that the whol process started is really finishe to load befor getting
the real handle I am interresting on. The problem I get if I set a kind of
small loop in my main application is that the process I try to start is
freezed as long as I remain in my main application loop.

In other words how can I start my process, asynchronously from my main
application and then after a while try to retrive its handle ??

For you infor I use the follwoing code to starting it:
=============== =============== =============== ====

......
Dim myProcessStartI nfo As New ProcessStartInf o(m_sIntouchIns tallPath &
"\view.exe" )
myProcessStartI nfo.UseShellExe cute = False
myProcess.Start Info = myProcessStartI nfo
myProcess.Start Info.WindowStyl e =
ProcessWindowSt yle.Normal

myProcess.Start ()
AddHandler myProcess.Exite d, AddressOf MyProcessExited
' Set 'EnableRaisingE vents' to true, to raise
'Exited' event when process is terminated.
myProcess.Enabl eRaisingEvents = True

Dim i As Integer

While m_iViewerHandle = 0 Or i < 10
m_iViewerHandle = FindWindow(vbNu llString, "VIEW")
i = i + 1
End While

m_iHandle = m_iViewerHandle
Return m_iHandle
......

With this code, as long as I am in my While.... loop, the process I start is
freeze and my all application gets "No responding status".

To sumurize the situation I need to:
- strart my exe process without locking my my application
- retrive the correct window handle
Thanks to help me to solve my issue.
regards
CALDERARA Serge

Jul 21 '05 #3
Hi Serge,

Your app will freeze while you wait and sleep, but the new process
shouldn't. Perhaps it would be worth trying UseShellExecute = True? You only
really need to set this to False if you are going to change stdin/out.

Cheers
John

"serge calderara" wrote:
HI john,

Thnaks for your answer. I give a try by changing my code according to your
advise but it is still the same. Having this while loop place my application
in a Non Responding satus and my process is partialy started but lock at the
welcome screen.

Now if I close my main application with task manager, my started process
continue to execute and open fully .....

Any other idea how to start that process and retrive its handle without
locking the whole application ? it seems it all runs in the same context and
threads that is may be the reason.. if so shouzdl I create a thread that
launch my process ?

The modify loop isas follow :
While m_iViewerHandle = 0
------> myProcess.WaitF orExit(1000)
System.Threadin g.Thread.Sleep( 500)
m_iViewerHandle = FindWindow(vbNu llString, "VIEW
- " & m_sApplicationP ath)
End While

Thnaks for your help
serge

"John Roper" wrote:
I suggest calling myProcess.WaitF orExit(1000) in your while loop. This will
give control to other apps (allowing them to process events) and come back to
your loop after a second (1000 mS).

Regards
John

"serge calderara" wrote:
Dear all,

I have an application which is suppose to start another executable process.
As soon as that process is running, I need to retrive its handle. The
problem of the particular process I am starting is that it has a welcome
window first which gets displayed and then the real windows after a while,in
other words it means that the process name is the same, but the handle I need
to retrive is the one from the final window and not the welome window.

So in real that means that from my main application I need to wait for a
while that the whol process started is really finishe to load befor getting
the real handle I am interresting on. The problem I get if I set a kind of
small loop in my main application is that the process I try to start is
freezed as long as I remain in my main application loop.

In other words how can I start my process, asynchronously from my main
application and then after a while try to retrive its handle ??

For you infor I use the follwoing code to starting it:
=============== =============== =============== ====

......
Dim myProcessStartI nfo As New ProcessStartInf o(m_sIntouchIns tallPath &
"\view.exe" )
myProcessStartI nfo.UseShellExe cute = False
myProcess.Start Info = myProcessStartI nfo
myProcess.Start Info.WindowStyl e =
ProcessWindowSt yle.Normal

myProcess.Start ()
AddHandler myProcess.Exite d, AddressOf MyProcessExited
' Set 'EnableRaisingE vents' to true, to raise
'Exited' event when process is terminated.
myProcess.Enabl eRaisingEvents = True

Dim i As Integer

While m_iViewerHandle = 0 Or i < 10
m_iViewerHandle = FindWindow(vbNu llString, "VIEW")
i = i + 1
End While

m_iHandle = m_iViewerHandle
Return m_iHandle
......

With this code, as long as I am in my While.... loop, the process I start is
freeze and my all application gets "No responding status".

To sumurize the situation I need to:
- strart my exe process without locking my my application
- retrive the correct window handle
Thanks to help me to solve my issue.
regards
CALDERARA Serge

Jul 21 '05 #4
It sounds like the process is starting on the same thread. Might be good to
start the process on another thread and let it invoke a callback method when
it is ready. This will prevent your primary thread from hanging.

The following example is in C#.
1. Make sure the namespace System.Threadin g is imported:
using System.Threadin g;

2. Instead of starting the process, queue the process into the thread pool.
ThreadPool.Queu eUserWorkItem(n ew WaitCallback(Th readProc));

3. The ThreadProc procedure should be declared, which actually starts the
process on the new thread.
private void ThreadProc(obje ct stateInfo)
{
// Start the process here.
// Whenever the process is finished, it can execute another method
// which continues where this leaves off.
}

Hope that helps.

--
Jason Whitted

"serge calderara" wrote:
Dear all,

I have an application which is suppose to start another executable process.
As soon as that process is running, I need to retrive its handle. The
problem of the particular process I am starting is that it has a welcome
window first which gets displayed and then the real windows after a while,in
other words it means that the process name is the same, but the handle I need
to retrive is the one from the final window and not the welome window.

So in real that means that from my main application I need to wait for a
while that the whol process started is really finishe to load befor getting
the real handle I am interresting on. The problem I get if I set a kind of
small loop in my main application is that the process I try to start is
freezed as long as I remain in my main application loop.

In other words how can I start my process, asynchronously from my main
application and then after a while try to retrive its handle ??

For you infor I use the follwoing code to starting it:
=============== =============== =============== ====

......
Dim myProcessStartI nfo As New ProcessStartInf o(m_sIntouchIns tallPath &
"\view.exe" )
myProcessStartI nfo.UseShellExe cute = False
myProcess.Start Info = myProcessStartI nfo
myProcess.Start Info.WindowStyl e =
ProcessWindowSt yle.Normal

myProcess.Start ()
AddHandler myProcess.Exite d, AddressOf MyProcessExited
' Set 'EnableRaisingE vents' to true, to raise
'Exited' event when process is terminated.
myProcess.Enabl eRaisingEvents = True

Dim i As Integer

While m_iViewerHandle = 0 Or i < 10
m_iViewerHandle = FindWindow(vbNu llString, "VIEW")
i = i + 1
End While

m_iHandle = m_iViewerHandle
Return m_iHandle
......

With this code, as long as I am in my While.... loop, the process I start is
freeze and my all application gets "No responding status".

To sumurize the situation I need to:
- strart my exe process without locking my my application
- retrive the correct window handle
Thanks to help me to solve my issue.
regards
CALDERARA Serge

Jul 21 '05 #5
HI John,

I I use what you mentionned it freeze everything, my application and the
process I start.

I have mange to make it working by using the following code :
=============== =============== =============== =
myProcess.Enabl eRaisingEvents = True
myProcess.WaitF orInputIdle(200 00)

If myProcess.Respo nding Then
m_iViewerHandle =
myProcess.MainW indowHandle.ToI nt32
Dim sTitle As String
sTitle = myProcess.MainW indowTitle
Me.m_ObjMessage Prvd.LogMessage ("Process has ben
catch with hdl: " & CStr(m_iViewerH andle) & " and WIndow name as : " &
sTitle, TraceLevel.Info )
Else
myProcess.Kill( )
End If
Then I can play with the timeout value for
myProcess.WaitF orInputIdle(200 00) as a parameter.

THis the launching application start my process and wait for the idle state
of the launched process, if it fails during that time then this means trouble
with the process.

If I use this, what is the best way afterwards to retrive the handle of the
process window by its window name ?

I use the following if my process is responding:
=============== =============== ====
m_iViewerHandle = myProcess.MainW indowHandle.ToI nt32
Dim sTitle As String
sTitle = myProcess.MainW indowTitle

but I het m_iViewerHandle = 0 and sTitle="", it seems that even the process
is responding the main window is noit yet ready

thnaks for your help
serge

"John Roper" wrote:
Hi Serge,

Your app will freeze while you wait and sleep, but the new process
shouldn't. Perhaps it would be worth trying UseShellExecute = True? You only
really need to set this to False if you are going to change stdin/out.

Cheers
John

"serge calderara" wrote:
HI john,

Thnaks for your answer. I give a try by changing my code according to your
advise but it is still the same. Having this while loop place my application
in a Non Responding satus and my process is partialy started but lock at the
welcome screen.

Now if I close my main application with task manager, my started process
continue to execute and open fully .....

Any other idea how to start that process and retrive its handle without
locking the whole application ? it seems it all runs in the same context and
threads that is may be the reason.. if so shouzdl I create a thread that
launch my process ?

The modify loop isas follow :
While m_iViewerHandle = 0
------> myProcess.WaitF orExit(1000)
System.Threadin g.Thread.Sleep( 500)
m_iViewerHandle = FindWindow(vbNu llString, "VIEW
- " & m_sApplicationP ath)
End While

Thnaks for your help
serge

"John Roper" wrote:
I suggest calling myProcess.WaitF orExit(1000) in your while loop. This will
give control to other apps (allowing them to process events) and come back to
your loop after a second (1000 mS).

Regards
John

"serge calderara" wrote:

> Dear all,
>
> I have an application which is suppose to start another executable process.
> As soon as that process is running, I need to retrive its handle. The
> problem of the particular process I am starting is that it has a welcome
> window first which gets displayed and then the real windows after a while,in
> other words it means that the process name is the same, but the handle I need
> to retrive is the one from the final window and not the welome window.
>
> So in real that means that from my main application I need to wait for a
> while that the whol process started is really finishe to load befor getting
> the real handle I am interresting on. The problem I get if I set a kind of
> small loop in my main application is that the process I try to start is
> freezed as long as I remain in my main application loop.
>
> In other words how can I start my process, asynchronously from my main
> application and then after a while try to retrive its handle ??
>
> For you infor I use the follwoing code to starting it:
> =============== =============== =============== ====
>
> ......
> Dim myProcessStartI nfo As New ProcessStartInf o(m_sIntouchIns tallPath &
> "\view.exe" )
> myProcessStartI nfo.UseShellExe cute = False
> myProcess.Start Info = myProcessStartI nfo
> myProcess.Start Info.WindowStyl e =
> ProcessWindowSt yle.Normal
>
> myProcess.Start ()
> AddHandler myProcess.Exite d, AddressOf MyProcessExited
> ' Set 'EnableRaisingE vents' to true, to raise
> 'Exited' event when process is terminated.
> myProcess.Enabl eRaisingEvents = True
>
> Dim i As Integer
>
> While m_iViewerHandle = 0 Or i < 10
> m_iViewerHandle = FindWindow(vbNu llString, "VIEW")
> i = i + 1
> End While
>
> m_iHandle = m_iViewerHandle
> Return m_iHandle
> ......
>
> With this code, as long as I am in my While.... loop, the process I start is
> freeze and my all application gets "No responding status".
>
> To sumurize the situation I need to:
> - strart my exe process without locking my my application
> - retrive the correct window handle
>
>
> Thanks to help me to solve my issue.
> regards
> CALDERARA Serge

Jul 21 '05 #6
I will give a try, but then one important point is that, when the process is
properly launched, I need to retrive the handle of the displayed window...

If I start as a new thread, how can my main application is infromed that my
process window is ready. How can my new created thread can return the window
handle to my main applciatiom?

Thanks for your help

"JWhitted" wrote:
It sounds like the process is starting on the same thread. Might be good to
start the process on another thread and let it invoke a callback method when
it is ready. This will prevent your primary thread from hanging.

The following example is in C#.
1. Make sure the namespace System.Threadin g is imported:
using System.Threadin g;

2. Instead of starting the process, queue the process into the thread pool.
ThreadPool.Queu eUserWorkItem(n ew WaitCallback(Th readProc));

3. The ThreadProc procedure should be declared, which actually starts the
process on the new thread.
private void ThreadProc(obje ct stateInfo)
{
// Start the process here.
// Whenever the process is finished, it can execute another method
// which continues where this leaves off.
}

Hope that helps.

--
Jason Whitted

"serge calderara" wrote:
Dear all,

I have an application which is suppose to start another executable process.
As soon as that process is running, I need to retrive its handle. The
problem of the particular process I am starting is that it has a welcome
window first which gets displayed and then the real windows after a while,in
other words it means that the process name is the same, but the handle I need
to retrive is the one from the final window and not the welome window.

So in real that means that from my main application I need to wait for a
while that the whol process started is really finishe to load befor getting
the real handle I am interresting on. The problem I get if I set a kind of
small loop in my main application is that the process I try to start is
freezed as long as I remain in my main application loop.

In other words how can I start my process, asynchronously from my main
application and then after a while try to retrive its handle ??

For you infor I use the follwoing code to starting it:
=============== =============== =============== ====

......
Dim myProcessStartI nfo As New ProcessStartInf o(m_sIntouchIns tallPath &
"\view.exe" )
myProcessStartI nfo.UseShellExe cute = False
myProcess.Start Info = myProcessStartI nfo
myProcess.Start Info.WindowStyl e =
ProcessWindowSt yle.Normal

myProcess.Start ()
AddHandler myProcess.Exite d, AddressOf MyProcessExited
' Set 'EnableRaisingE vents' to true, to raise
'Exited' event when process is terminated.
myProcess.Enabl eRaisingEvents = True

Dim i As Integer

While m_iViewerHandle = 0 Or i < 10
m_iViewerHandle = FindWindow(vbNu llString, "VIEW")
i = i + 1
End While

m_iHandle = m_iViewerHandle
Return m_iHandle
......

With this code, as long as I am in my While.... loop, the process I start is
freeze and my all application gets "No responding status".

To sumurize the situation I need to:
- strart my exe process without locking my my application
- retrive the correct window handle
Thanks to help me to solve my issue.
regards
CALDERARA Serge

Jul 21 '05 #7
An other question I got is:

How my main thread will know that the process has finished started and it
interface is open?

In the other way, how can the new thread informed the maion frame about its
status and its main windows handle ? can the new thread raise an event and
tha main thread is registered to that events?

thanks for your help
serge

"JWhitted" wrote:
It sounds like the process is starting on the same thread. Might be good to
start the process on another thread and let it invoke a callback method when
it is ready. This will prevent your primary thread from hanging.

The following example is in C#.
1. Make sure the namespace System.Threadin g is imported:
using System.Threadin g;

2. Instead of starting the process, queue the process into the thread pool.
ThreadPool.Queu eUserWorkItem(n ew WaitCallback(Th readProc));

3. The ThreadProc procedure should be declared, which actually starts the
process on the new thread.
private void ThreadProc(obje ct stateInfo)
{
// Start the process here.
// Whenever the process is finished, it can execute another method
// which continues where this leaves off.
}

Hope that helps.

--
Jason Whitted

"serge calderara" wrote:
Dear all,

I have an application which is suppose to start another executable process.
As soon as that process is running, I need to retrive its handle. The
problem of the particular process I am starting is that it has a welcome
window first which gets displayed and then the real windows after a while,in
other words it means that the process name is the same, but the handle I need
to retrive is the one from the final window and not the welome window.

So in real that means that from my main application I need to wait for a
while that the whol process started is really finishe to load befor getting
the real handle I am interresting on. The problem I get if I set a kind of
small loop in my main application is that the process I try to start is
freezed as long as I remain in my main application loop.

In other words how can I start my process, asynchronously from my main
application and then after a while try to retrive its handle ??

For you infor I use the follwoing code to starting it:
=============== =============== =============== ====

......
Dim myProcessStartI nfo As New ProcessStartInf o(m_sIntouchIns tallPath &
"\view.exe" )
myProcessStartI nfo.UseShellExe cute = False
myProcess.Start Info = myProcessStartI nfo
myProcess.Start Info.WindowStyl e =
ProcessWindowSt yle.Normal

myProcess.Start ()
AddHandler myProcess.Exite d, AddressOf MyProcessExited
' Set 'EnableRaisingE vents' to true, to raise
'Exited' event when process is terminated.
myProcess.Enabl eRaisingEvents = True

Dim i As Integer

While m_iViewerHandle = 0 Or i < 10
m_iViewerHandle = FindWindow(vbNu llString, "VIEW")
i = i + 1
End While

m_iHandle = m_iViewerHandle
Return m_iHandle
......

With this code, as long as I am in my While.... loop, the process I start is
freeze and my all application gets "No responding status".

To sumurize the situation I need to:
- strart my exe process without locking my my application
- retrive the correct window handle
Thanks to help me to solve my issue.
regards
CALDERARA Serge

Jul 21 '05 #8
I wrote a little Console App that should show you what I'm talking about.
This app will start a process in another thread, which launches Internet
Explorer (you might need to change the path to get this to work on your box).
It then pauses for a few seconds and then calls a callback function which
accepts the handle of the window as a parameter. Once the handle of the
window is received, the IE window is flashed and then closed (along with the
process).

The only additional concern I can forsee you having is using this
functionality as part of a windows app instead of a console app. In that
case, instead of calling the callback function directly, you might have to
create a callback delegegate method and invoke it using the Form's Invoke
method. This will be necessary because all GUI modifications should happen
on the primary thread of the window. Any attempt to modify GUI elements from
a child thread usually results in an exception being thrown.

Hope that helps.

--
Jason Whitted

############### ##########
Class1.cs
############### ##########
using System;
using System.Diagnost ics;
using System.Runtime. InteropServices ;
using System.Threadin g;

namespace Testing
{
public class Class1
{
private Process proc;

public Class1()
{
Console.WriteLi ne("Class1 Constructor called");
ThreadPool.Queu eUserWorkItem(n ew WaitCallback(Th readProc));
}

public void ThreadProc(obje ct stateInfo)
{
Console.WriteLi ne("Starting Process");
proc = Process.Start(@ "C:\Program Files\Internet
Explorer\IExplo re.exe", "http://www.microsoft.c om");
Console.Write(" Pausing: ");
for(int x=5; x>0; x--)
{
Console.Write(" " + x);
Thread.Sleep(10 00);
}
Console.WriteLi ne();
Callback(proc.M ainWindowHandle );

}

public void Callback(IntPtr handle)
{
Console.WriteLi ne("Callback called (handle=" + handle.ToString ()
+ ")");
Thread.Sleep(10 00);
Console.WriteLi ne("Flashing window");
for(int x=0; x<20; x++)
{
FlashWindow(han dle, x%2);
Thread.Sleep(50 );
}
Console.WriteLi ne("Closing Window Process");
proc.CloseMainW indow();
Console.WriteLi ne("Closing Process");
proc.Close();
Console.WriteLi ne("Done");
}

[DllImport("user 32")]
public static extern int FlashWindow(Int Ptr handle, int bInvert);

public static void Main(string[] args)
{
new Class1();
Console.ReadLin e();
}
}
}

Jul 21 '05 #9
Thnaks for your sample appliction...
It helps me a lot to understand what you mean, but sorry to disturbed you
again, I still have some weal points on really understanding.. .

1 - CALLBACK term
===============
In your sample in the start process thread you call the function named
CALLBACK to retrive the window handle and close it after a while.
What I am confuse here is the term CALLBACK, because if I name your function
an other manner it works too, so does the CALLBACL terms you are mentionning
here is this wierd and strange system behaviour that developper like me do
not reaal understand. could you details what you means here by callback...

And I do not catch what you means also by Delegates call back events, I
never used that..

I am nearlyy close to the end but I like to do things that I am clearly
understanding

2 Getting handl back toi main applcation
=============== ===========
No problem for doing this in my WIndows applicatin, the only point is that
after my process is launch, I should be able to close it or show it if it has
been minimized and the only way is that my main application should retrive
the window handle.

3 Show the created process window application
Another point that come to my mind.lets say that the process has been
started properly and its main windows application is running. Now my user is
minimizing the windows whcih goes down to taskbar. I should be able from my
main application to show that window in normal mode in case it is called
again has it is already exist. Under VB 5 for instance i will use the
FindWindow and ShowWindow function. How to do then with this new thread to
call window in front.
If I call the same procedure that was callin it initially to start the
process, it will creat an other thred instance, and I would need in fact to
just call the one which have been launched..

Thnaks for your help

Serge

"JWhitted" wrote:
I wrote a little Console App that should show you what I'm talking about.
This app will start a process in another thread, which launches Internet
Explorer (you might need to change the path to get this to work on your box).
It then pauses for a few seconds and then calls a callback function which
accepts the handle of the window as a parameter. Once the handle of the
window is received, the IE window is flashed and then closed (along with the
process).

The only additional concern I can forsee you having is using this
functionality as part of a windows app instead of a console app. In that
case, instead of calling the callback function directly, you might have to
create a callback delegegate method and invoke it using the Form's Invoke
method. This will be necessary because all GUI modifications should happen
on the primary thread of the window. Any attempt to modify GUI elements from
a child thread usually results in an exception being thrown.

Hope that helps.

--
Jason Whitted

############### ##########
Class1.cs
############### ##########
using System;
using System.Diagnost ics;
using System.Runtime. InteropServices ;
using System.Threadin g;

namespace Testing
{
public class Class1
{
private Process proc;

public Class1()
{
Console.WriteLi ne("Class1 Constructor called");
ThreadPool.Queu eUserWorkItem(n ew WaitCallback(Th readProc));
}

public void ThreadProc(obje ct stateInfo)
{
Console.WriteLi ne("Starting Process");
proc = Process.Start(@ "C:\Program Files\Internet
Explorer\IExplo re.exe", "http://www.microsoft.c om");
Console.Write(" Pausing: ");
for(int x=5; x>0; x--)
{
Console.Write(" " + x);
Thread.Sleep(10 00);
}
Console.WriteLi ne();
Callback(proc.M ainWindowHandle );

}

public void Callback(IntPtr handle)
{
Console.WriteLi ne("Callback called (handle=" + handle.ToString ()
+ ")");
Thread.Sleep(10 00);
Console.WriteLi ne("Flashing window");
for(int x=0; x<20; x++)
{
FlashWindow(han dle, x%2);
Thread.Sleep(50 );
}
Console.WriteLi ne("Closing Window Process");
proc.CloseMainW indow();
Console.WriteLi ne("Closing Process");
proc.Close();
Console.WriteLi ne("Done");
}

[DllImport("user 32")]
public static extern int FlashWindow(Int Ptr handle, int bInvert);

public static void Main(string[] args)
{
new Class1();
Console.ReadLin e();
}
}
}

Jul 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6312
by: ChrisWinterscheid | last post by:
We are running DB2 8.1 on AIX 5.2. DB2level shows: DB21085I Instance "db2inst1" uses "32" bits and DB2 code release "SQL08016" with level identifier "02070106". Informational tokens are "DB2 v8.1.1.56", "s040616", "U497635", and FixPak "6". Product is installed at "/usr/opt/db2_08_01".
0
1021
by: calderara serge | last post by:
Dear All, I am building an application with VB.Net that is starting an external process from my application code by using the process object. The problem I get is that the application that I need to start from my code can takes some times to be really in full real mode. In other words, my main application should continue its next code line while the external process initialise. I have no control of the external process (its an OEM...
12
381
by: serge calderara | last post by:
Dear all, I have an application which is suppose to start another executable process. As soon as that process is running, I need to retrive its handle. The problem of the particular process I am starting is that it has a welcome window first which gets displayed and then the real windows after a while,in other words it means that the process name is the same, but the handle I need to retrive is the one from the final window and not the...
0
1331
by: graciezzzzz | last post by:
Hi all, I create a Web Service project called 'eSelectService' and another Class Library project called 'MonerisVO', and a Windows Form project called 'maps' as well. The reason why I need the Class Library project is because I don't want to pass more than 30 parameters when I try to invoke the Web Method. I used the class in Class Library as a value object to contain all the information I need.
4
2950
by: Phil Mc | last post by:
Say for example you have a application running on a windows 2003 server (that is on server, not from). This application needs to start child applications (must be stand alone console applications), but these child applications must have the same security privileges as the parent starting them. I have created a scheduling app (which will be started by autosys job), which must start child apps when certain criteria are met. The scheduling...
3
2603
by: zxo102 | last post by:
Hi there, I have a python application (many python scripts) and I start the application like this python myServer.py start in window. It is running in dos window. Now I would like to put it in background as NT service. I got a example code: SmallestService.py from chapter 18 of the book "Python Programming On Win32" by Mark Hammond etc. The code is as follows and runs well as an NT service.
1
4350
by: treelife | last post by:
I'm getting and internal server error when | run the following mod_python script. I am actually trying to run Django. Script: from mod_python import apache def handler(req): req.content_type = 'text/plain' req.write("Under Construction")
0
5567
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
5
3302
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name? Why do I need to set a property within my code to the service name? Are all these required or am I just doing this for consistency purposes?
0
8619
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8824
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7651
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5831
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4336
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4571
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2994
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2258
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.