471,342 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,342 software developers and data experts.

increasing Excel process place in taskmanager hierarchy

Bob
Hi,
I have an application that uses a excel in conjuction with a third
party application. I create an excel instance in c# and mark it as
invisible. The third party application is programmed to interact with
excel and everything works fine as I monitor interactions with my
hidden excel sheet. The problem comes if a user opens another
instance of excel. Is there any way that I can use the process
classes or another means to increase my invisible excel's task-
manager priority to be above every other excel instance? Making my
Excel application visible and then invisible temporarily makes it most
recent one but it creates a flickering and is likely resource
intensive.

Thanks,
Bob
Sep 6 '08 #1
6 1547
I've never had need to try this, but
System.Diagnostics.Process.PriorityClass seems to be appropriate for this.
"Bob" <bs********@yahoo.comwrote in message
news:c2**********************************@w1g2000p rk.googlegroups.com...
Hi,
I have an application that uses a excel in conjuction with a third
party application. I create an excel instance in c# and mark it as
invisible. The third party application is programmed to interact with
excel and everything works fine as I monitor interactions with my
hidden excel sheet. The problem comes if a user opens another
instance of excel. Is there any way that I can use the process
classes or another means to increase my invisible excel's task-
manager priority to be above every other excel instance? Making my
Excel application visible and then invisible temporarily makes it most
recent one but it creates a flickering and is likely resource
intensive.

Thanks,
Bob
Sep 6 '08 #2
Bob
On Sep 6, 7:47*am, "Family Tree Mike"
<FamilyTreeM...@ThisOldHouse.comwrote:
I've never had need to try this, but
System.Diagnostics.Process.PriorityClass seems to be appropriate for this..

"Bob" <bshumsk...@yahoo.comwrote in message

news:c2**********************************@w1g2000p rk.googlegroups.com...
Hi,
I have an application that uses a excel in conjuction with a third
party application. *I create an excel instance in c# and mark it as
invisible. *The third party application is programmed to interact with
excel *and everything works fine as I monitor interactions with my
hidden excel sheet. *The problem comes if a user opens another
instance of excel. *Is there any way that I can use the process
classes or another means to *increase my invisible excel's task-
manager priority to be above every other excel instance? Making my
Excel application visible and then invisible temporarily makes it most
recent one but it creates a flickering and is likely resource
intensive.
Thanks,
Bob
I don't think that is the right solution. It throws an exception when
I try to change the priority either in C# or manually in task
manager. More generally, I am not trying to increase the programs
processor priority (ie how fast it executes), but rather just make
sure it is the top excel instance in visibility. Does a process with
higher priority show higher in visibility?
Sep 6 '08 #3
That is a different question than you asked before in my opinion...

The solution will likely involve FindWindow,
http://www.pinvoke.net/default.aspx/user32.FindWindow, and
SetForegroundWindow,
http://www.pinvoke.net/default.aspx/...regroundWindow.

Now, the tricky part which I cannot answer, is how are you going to know
when to execute the code? I mean, that if you put in a timer and check if a
process of Excel exists, then you will be constantly moving Excel to the
front. This would be annoying as a user.

Then there is also the condition where there are more than one Excel
window...

"Bob" <bs********@yahoo.comwrote in message
news:22**********************************@n38g2000 prl.googlegroups.com...
I don't think that is the right solution. It throws an exception when
I try to change the priority either in C# or manually in task
manager. More generally, I am not trying to increase the programs
processor priority (ie how fast it executes), but rather just make
sure it is the top excel instance in visibility. Does a process with
higher priority show higher in visibility?

Sep 6 '08 #4
Bob

Thanks for your response, sorry if my question was unclear. Is this
the correct way to implement your suggestion, I am not used to
PInvoke. If it is correct, it doesn't seem to work.

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);

void b1_Click(object sender, EventArgs e)
{


Process[] allProcesses=Process.GetProcesses();
for (int i = 0; i < allProcesses.Length; i++)
{
if (allProcesses[i].ProcessName.Contains("EXCEL")){
excelHndl=allProcesses[i].Handle;
excelProc = allProcesses[i];
}
}

SetForegroundWindow(excelHndl);
}
Thanks Again,
Bob
Sep 7 '08 #5
Close... This line:

excelHndl=allProcesses[i].Handle;

should be:

excelHndl=allProcesses[i].MainWindowHandle;

"Bob" <bs********@yahoo.comwrote in message
news:8c**********************************@b30g2000 prf.googlegroups.com...
>
Thanks for your response, sorry if my question was unclear. Is this
the correct way to implement your suggestion, I am not used to
PInvoke. If it is correct, it doesn't seem to work.

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);

void b1_Click(object sender, EventArgs e)
{


Process[] allProcesses=Process.GetProcesses();
for (int i = 0; i < allProcesses.Length; i++)
{
if (allProcesses[i].ProcessName.Contains("EXCEL")){
excelHndl=allProcesses[i].Handle;
excelProc = allProcesses[i];
}
}

SetForegroundWindow(excelHndl);
}
Thanks Again,
Bob
Sep 7 '08 #6
Bob
On Sep 6, 9:41*pm, "Family Tree Mike"
<FamilyTreeM...@ThisOldHouse.comwrote:
Close... *This line:

* excelHndl=allProcesses[i].Handle;

should be:

* excelHndl=allProcesses[i].MainWindowHandle;

"Bob" <bshumsk...@yahoo.comwrote in message

news:8c**********************************@b30g2000 prf.googlegroups.com...
Thanks for your response, sorry if my question was unclear. Is this
the correct way to implement your suggestion, I am not used to
PInvoke. *If it is correct, it doesn't seem to work.
*[DllImport("user32.dll")]
* * * [return: MarshalAs(UnmanagedType.Bool)]
* * * static extern bool SetForegroundWindow(IntPtr hWnd);
* * * void b1_Click(object sender, EventArgs e)
* * * {
* * * * * Process[] allProcesses=Process.GetProcesses();
* * * * * * for (int i = 0; i < allProcesses.Length; i++)
* * * * * {
* * * * * *if * (allProcesses[i].ProcessName.Contains("EXCEL")){
* * * * * * * * * excelHndl=allProcesses[i].Handle;
* * * * * * * * * excelProc = allProcesses[i];
* * * * * * * }
* * * * * }
* * * * * SetForegroundWindow(excelHndl);
}
Thanks Again,
Bob
Beautiful, thanks! This seems to work fine as long as I initialize the
excel instance to be visible, get the main window handle then, and
then make it invisible.
Sep 7 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Mark Day | last post: by
10 posts views Thread by Sorin Dolha [MCSD .NET] | last post: by
2 posts views Thread by Larry Jones | last post: by
1 post views Thread by Dwight | last post: by
1 post views Thread by myname | last post: by
4 posts views Thread by spirit | last post: by
reply views Thread by rosydwin | last post: by

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.