Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

Windows Service & Clipboard

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Humam - 24 Feb 2008 16:43 GMT
I am developing a windows service that reads from the serial port and then
put the data read from the serial to the clipboard, so the client can use
Ctrl + v to paste,
I am using
Clipboard.Clear();
Clipboard.SetData(DataFormats.Text, (Object)IDCard.FirstName);
but for some reason it seems that the clipboard does not fill up with data.
Is there any security restriction of calling the clipboard methods from the
same thread that the windows service is running? How can I fill the clipboard?
Jeroen Mostert - 24 Feb 2008 17:41 GMT
> I am developing a windows service that reads from the serial port and then
> put the data read from the serial to the clipboard, so the client can use
> Ctrl + v to paste,

There are several reasons why this is a really bad idea.

First, services shouldn't interact with user sessions at all. This is a
security risk and poor design to boot, since services should run correctly
even when nobody is logged on.

Second, the clipboard should only be filled with data in response to a user
action. The clipboard is *not* a general mechanism for applications to
communicate, it's a way for users to transfer information of their own
choosing between applications. If you're not an interactive application, you
have no business accessing the clipboard.

> I am using
> Clipboard.Clear();
> Clipboard.SetData(DataFormats.Text, (Object)IDCard.FirstName);
> but for some reason it seems that the clipboard does not fill up with data.
> Is there any security restriction of calling the clipboard methods from the
> same thread that the windows service is running? How can I fill the clipboard?

The clipboard is associated with a window station. Services run in a
separate, noninteractive window station. The clipboard *does* contain your
data, but the user (who is logged on in another window station) does not
(and cannot) access that clipboard.

What you want to do can probably be done better. First of all, there is no
need to use a Windows service to read from a serial port -- a regular
application can do that just fine. It may need elevated privileges to run,
but these can be asked for. You could make your application invisible
(displaying no forms) and have it start at user logon if it is desirable
that the user doesn't need to start and stop it explicitly.

Second, your application should not pump data to the clipboard without being
asked to. A much cleaner way of achieving the same effect is to give the
application an interface with the data in a textbox, so the user can copy
the data themselves. You could supply a "copy to clipboard" button to
quickly copy all data gathered so far.

Finally, if it's necessary that the application supply the data without
being asked for, using the clipboard is still not a good idea. You could
have the application write to a file, which people or applications can read
at their leasure, or you could communicate the data through remoting
(consult the MSDN for more information on that).

Signature

J.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.