473,378 Members | 1,407 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,378 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 1622
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.