Disabling right clicks on a console based C# app

D

Dilip

I have written a C# based console application. Due to some issues
thats been causing me endless nightmares, I was wondering, is there a
way to prevent right mousebutton clicks on my application when it
appears on the task bar? I don't want the context menu showing up
when a user right clicks on it. I don't want the user to be able to
do anything with it other than stare at it in its minimized form. I
know we can P/Invoke into some Win32 APIs to hide it completely
(FindWindow/ShowWindow/SW_HIDE) but for the moment is what I am aiming
to do possible?

I know there are many other ways to sidestep this problem completely
but the for the moment I am stuck with what I have (due to legacy
issues) and I need to find a way to disable the context menu from
showing up when an user right clicks on my app on the task bar.
 
J

Jon Skeet [C# MVP]

I have written a C# based console application.  Due to some issues
thats been causing me endless nightmares, I was wondering, is there a
way to prevent right mousebutton clicks on my application when it
appears on the task bar?  I don't want the context menu showing up
when a user right clicks on it.  I don't want the user to be able to
do anything with it other than stare at it in its minimized form.  I
know we can P/Invoke into some Win32 APIs to hide it completely
(FindWindow/ShowWindow/SW_HIDE) but for the moment is what I am aiming
to do possible?

It sounds unlikely.
I know there are many other ways to sidestep this problem completely
but the for the moment I am stuck with what I have (due to legacy
issues) and I need to find a way to disable the context menu from
showing up when an user right clicks on my app on the task bar.

I'm intrigued to hear why you're stuck with it being a console
application when you don't need a console. Why not just make it a GUI
app which doesn't show any forms?

Jon
 
D

Dilip

I'm intrigued to hear why you're stuck with it being a console
application when you don't need a console. Why not just make it a GUI
app which doesn't show any forms?

Because its a humongous application Jon. I don't know what might
happen if I convert it to an GUI app. It interacts with so many other
apps via remoting and such. At the very least it is going to involve
re-testing the entire functional specifications which probably will
not happen this late in the day. That is a kind of change the mgmt
won't allow anyway. At least for the current release I need to find a
way to prevent the context menu from showing up.
 
J

Jon Skeet [C# MVP]

Because its a humongous application Jon.  I don't know what might
happen if I convert it to an GUI app.

All you'd be changing is whether or not a console is allocated. Just
the project type, in the project settings. I'm not suggesting adding
an actual UI or anything like that - just changing a single property
of the project.
 It interacts with so many other
apps via remoting and such.  At the very least it is going to involve
re-testing the entire functional specifications which probably will
not happen this late in the day.  That is a kind of change the mgmt
won't allow anyway.  At least for the current release I need to find a
way to prevent the context menu from showing up.

I'm 99% sure that if you *do* find a way of doing that, it'll involve
considerably more risky changes than just changing it from a console
app to a WinForms app which happens not to ever create or display
anything.

If you're afraid of anything concrete in terms of not allocating a
console, how convinced are you that disabling the context menu won't
have similar effects?

Jon
 
M

Mr. Arnold

Dilip said:
I have written a C# based console application. Due to some issues
thats been causing me endless nightmares, I was wondering, is there a
way to prevent right mousebutton clicks on my application when it
appears on the task bar? I don't want the context menu showing up
when a user right clicks on it. I don't want the user to be able to
do anything with it other than stare at it in its minimized form. I
know we can P/Invoke into some Win32 APIs to hide it completely
(FindWindow/ShowWindow/SW_HIDE) but for the moment is what I am aiming
to do possible?

I know there are many other ways to sidestep this problem completely
but the for the moment I am stuck with what I have (due to legacy
issues) and I need to find a way to disable the context menu from
showing up when an user right clicks on my app on the task bar.

I used the gpedit.msc in the Run box on the machine running Vista Ultimate,
went to the group policy listed below and enabled it. No one can
right-click an application setting on the task bar.

http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/gp/109.mspx?mfr=true

Maybe, that's what you need to do, if this is a dedicated machine for
running legacy solutions.

The link was for Win 2K, but the same thing can be done on Vista, and I will
assume it can be done for other MS NT class O/S(s).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top