Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Lauch .RDP from a C# App while keeping taskbar hidden

95 views
Skip to first unread message

Matthew Arkin

unread,
May 15, 2010, 5:07:24 PM5/15/10
to
First: I'm not the best developer so please excuse any noobiness.

I have a friend that a CS teacher and he want to let his students use an
IDE during their exam. To minimize cheating I recommened that he set up
a server with RemoteApp and install the IDE (Greenfoot). Then I was able
to make a little app that will launch it.

I want the app to be on top of the taskbar but I can't do that unless I
set TopMost to true, but then they can't view the RDP session and if I
kill explorer then RDP won't connect.

So the real question is a) can I have an application sit on top of the
taskbar with out killing explorer and using TopMost? B) is there a way
to embed RDP into the app (I can use WPF or WinForm) or C) any other
suggestions?


Thanks!

Matthew Arkin
Windows Desktop Experience MVP

Jackie

unread,
May 16, 2010, 3:58:12 AM5/16/10
to

It appears like you would be willing to terminate the shell process if
it allowed RDP to work properly. Taking that into consideration, how
about simply hiding the taskbar?

Jackie

unread,
May 16, 2010, 5:11:20 AM5/16/10
to
On 5/16/2010 09:58, Jackie wrote:
> It appears like you would be willing to terminate the shell process if
> it allowed RDP to work properly. Taking that into consideration, how
> about simply hiding the taskbar?

I don't currently have a chance to test anything in C# but at at least
the following WinAPIs can be used:
GetDesktopWindow
FindWindowEx - "Shell_TrayWnd" class
ShowWindow - hide/show

If I recall correctly, it may show itself again some time. Using this
method, you would need to make sure to hide it again. It would look a
little amateurish having it show up and then disappear again, so there
may be better ways.
You can also of course disable or hide the desktop using this method as
well.

Matthew Arkin

unread,
May 16, 2010, 2:10:29 PM5/16/10
to
Thanks, Would it be possible to just make the remote desktop window
topmost? (It also launches a seperate credentials window)? If so, would
that be easier?

Jackie

unread,
May 16, 2010, 3:45:40 PM5/16/10
to

It does not appear to be a way to do this with only managed code. I am
thinking about something like this...
EnumWindows - enumerates all top-level windows
GetWindowThreadProcessId - get the ID of the process thread that created
the window
OpenProcess and GetModuleFileNameEx - get the file name of the process
and check if it's RDP

By now, you know that this window is owned by RDP at least and you can
do some additional checks, maybe.

After finding the right window(s)...
SetWindowPos - HWND_TOPMOST

Phew..

PInvoke is a good site to see how to use each API into C#:
http://www.pinvoke.net/

Jackie

unread,
May 16, 2010, 4:35:12 PM5/16/10
to
I wrote an example application, however, entirely in C/C++.
It follows pretty much the same instructions as I mentioned earlier.

It finds all top-level windows associated with the process mstsc.exe (if
that's the one you want) and just prints some info into a console window.

--------------------
Windows associated with RD:
'Remote Desktop Connection' (0x00410AF4)
'Remote Desktop Connection' (0x000A0C56)
'' (0x001E0BDA)
'' (0x000A0D34)
'' (0x00090BE0)
'' (0x00200916)
'MSCTFIME UI' (0x00240C0A)
'Default IME' (0x00150BFE)
--------------------

I didn't try anything more than opening mstsc without doing anything. At
least the window where you can connect stays on top of all other
non-topmost windows.
I wrote the code in C++ because it was quicker for me without converting
any APIs to C# code. I can give you the code. Just use the site I gave
you earlier (PInvoke) to check how to use the APIs in C# (mostly
copy/paste).

Matthew Arkin

unread,
May 16, 2010, 4:50:25 PM5/16/10
to

Thanks for all your help, I'll see if I can get it to work.

Matthew Arkin

unread,
May 16, 2010, 5:10:32 PM5/16/10
to
Though some sample c++ code would be awesome! I have some c++ experience.

Jackie

unread,
May 16, 2010, 5:19:05 PM5/16/10
to
On 5/16/2010 22:50, Matthew Arkin wrote:
> Thanks for all your help, I'll see if I can get it to work.

In case you would like to see my C/C++ code for reference, I put it up here:
http://pastebin.com/rFi4UrQ3

I used QueryFullProcessImageName instead of GetModuleFileNameEx to not
depend on psapi.dll.

Should hopefully be easy to convert it to C# with some help from
PInvoke. Good luck! :)

Jackie

unread,
May 16, 2010, 5:31:06 PM5/16/10
to
On 5/16/2010 23:10, Matthew Arkin wrote:
> Though some sample c++ code would be awesome! I have some c++ experience.

Great! I made a small change by adding the IsWindowVisible API. :)

http://pastebin.com/bTnasaUX

Matthew Arkin

unread,
May 16, 2010, 8:21:24 PM5/16/10
to

Hi Jackie,
I found this class at
http://www.codeproject.com/KB/miscctrl/hide_vista_start_orb.aspx
Which allowed me to just hide the taskbar, and with RemoteApp even if
the user clicked my app window, if they click the button that loads the
RDP, all their work is still their. Now I just need to add some code to
block any bad keystrokes and that should be it.

Thanks for all your time and help.

Matt
Windows Desktop Experience MVP

Jackie

unread,
May 17, 2010, 1:56:03 AM5/17/10
to

Oh I see. I am glad that works well for you. Good luck! :)

David Ching

unread,
May 17, 2010, 10:49:32 PM5/17/10
to
"Matthew Arkin" <ad...@arkinsupport.com> wrote in message
news:e0OufbH9...@TK2MSFTNGPRV04.privatenews.microsoft.com...

> B) is there a way to embed RDP into the app (I can use WPF or WinForm)

Just today I stumbled onto the Microsoft RDP Client Control that appears in
the Choose Toolbox Items dialog in the COM Components tab of Visual Studio,
so it does seem there is already an ActiveX control for you to be able to
put into your app. Search "microsoft rdp client control" or "Remote Desktop
ActiveX Control" for more info.

-- David

Jeff Johnson

unread,
May 18, 2010, 12:20:35 PM5/18/10
to
"Matthew Arkin" <ad...@arkinsupport.com> wrote in message
news:e0OufbH9...@TK2MSFTNGPRV04.privatenews.microsoft.com...

> Matthew Arkin
> Windows Desktop Experience MVP

May I recommend that you don't cross-post between the MS public and private
groups? Not that it's going to matter for much longer, but, you know....


0 new messages