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 / .NET Framework / New Users / May 2005

Tip: Looking for answers? Try searching our database.

Setting the Windows default printer

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Guido Kraus - 11 May 2005 20:20 GMT
I would like to set the Windows default printer from a C# application. I
searched MSDN but cannot find an answer to this simple problem...

Any ideas?
Thanks,
Guido
Scott Maskiel - 12 May 2005 03:07 GMT
Hi Guido,

AFAIK this can only be done by directly editing the Registry key.  See
this MSDN article:

http://support.microsoft.com/default.aspx?scid=kb;en-us;271257

Regards,
Scott

>I would like to set the Windows default printer from a C# application. I
>searched MSDN but cannot find an answer to this simple problem...
>
>Any ideas?
>Thanks,
>Guido
"Peter Huang" [MSFT] - 12 May 2005 03:19 GMT
Hi

Here is a link for your reference including the sample code.

http://groups.google.co.jp/group/microsoft.public.dotnet.distributed_apps/br
owse_thread/thread/dafccb4b376cb368/686aaae2ea164cd0?q=SetDefaultPrinter++%2
2C%23%22&rnum=3&hl=zh-CN#686aaae2ea164cd0

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Guido Kraus - 12 May 2005 09:58 GMT
Thanks for your reply.
The WMI code has one problem: it requires Windows XP or newer. Since I need
Windows 2000 support WMI does not work for me. However, I found the
SetDefaultPrinter function in the Win32 API (see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_02
7m.asp
)
This works for Windows 2000 and above.

Guido

> Hi
>
[quoted text clipped - 11 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no rights.
"Peter Huang" [MSFT] - 13 May 2005 03:29 GMT
Hi

Thanks for your feedback.

Because we can use WMI in .NET via System.Management namespace which is all
managed code, but if you wants to use it on earlier OS, I think we have to
use the P/Invoke into the API.

So the P/Invoke is also a good alternative on earlier OS platforms.

Thanks for your sharing the experience here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


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.