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

Re: Setting the Windows default printer by Scott

Scott
Wed May 11 21:07:25 CDT 2005

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

On Wed, 11 May 2005 12:20:06 -0700, "Guido Kraus"
<guido.kraus@newsgroup.nospam> wrote:

>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


RE: Setting the Windows default printer by v-phuang

v-phuang
Wed May 11 21:19:56 CDT 2005

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

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


RE: Setting the Windows default printer by guido

guido
Thu May 12 03:58:06 CDT 2005

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_027m.asp )
This works for Windows 2000 and above.

Guido

""Peter Huang" [MSFT]" wrote:

> 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
>
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>

RE: Setting the Windows default printer by v-phuang

v-phuang
Thu May 12 21:29:04 CDT 2005

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

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