473,395 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 1623
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sri | last post by:
I am writing an asp.net applicaition using VB coding. In a function, I am opening an excel file with the following code, Dim objExcel As Object Dim objWorkBook As Object objExcel =...
10
by: Mark Day | last post by:
Hi All, I am using Access 2000 to generate over 40 Excel charts and pivot tables using early binding to the Excel 9.0 object library. I am finding that if I show the Excel object while processing...
10
by: Sorin Dolha [MCSD .NET] | last post by:
I would like to start a process from C# code as another user. The C# code is executed as the ASPNET user because it relies in a Web Page class, and I would like that the process will run as another...
3
by: hari krishna | last post by:
hi, I am generating excel reports through vb.Net. After creating excel.application and the report is generated, each report leaves Excel in memory. I can see them in task manager in Process tab...
2
by: Larry Jones | last post by:
I want to place information from an active Excel spreadsheet to a VB.net form. I just want to place numbers from an Excel cell in a standard VB.net text box. Does anyone have sample code to...
1
by: Dwight | last post by:
The place I'm working for has a need to sort an excel spread sheet the contains data from bill of materials. The spreadsheets can be up to 60,000 records. We had a process that did it in a macro...
1
by: myname | last post by:
Hello, in VB.Net, I use Excel to display results : dim xl as new Excel.Application // creates an Excel process // snip (putting values into cells) xl.Visible = true If the user closes the...
2
by: B.N.Prabhu | last post by:
In my web application(C#) . I am adding one excel sheet and then save and closing that excel file. In the finally bloack i gave Marshal.ReleaseComObject(clsExcel); But when i go and see in the...
4
by: spirit | last post by:
Hi, I have C++ code to write data to a .csv file thereby resulting in an excel spreadsheet. I was just wondering whether it wud be possible for us to further manipulate the csv file like for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.