获得64位Vista中的默认打印机

编程入门 行业动态 更新时间:2024-10-23 18:23:15
本文介绍了获得64位Vista中的默认打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用下面的代码返回32位WinXP中的默认打印机 Pro,但现在我正在运行64 -bit Vista Business我收到一个错误: 使用System.Drawing.Printing; 使用(PrintDocument objPrintDocument = new PrintDocument ()) { string strDefaultPrinter = objPrintDocument.PrinterSettings.PrinterName; } 错误消息是:未安装打印机。这似乎来自一个名为HdevmodeInternal的方法 但是,我安装了几台打印机,默认打印机是 旧HP LaserJet 5. 上述代码是否不适用于64位Vista?有问题的应用程序是为x86编译的 ... 我最好使用WMI返回默认打印机的名称? 我试图在谷歌和MSDN上找到一个解决方案,但是没有多少运气好吗? 感激不尽的任何帮助。 - http ://www.markrae

解决方案

" Mark Rae" < ma ** @ markNOSPAMraewrote in message news:u5 ************** @ TK2MSFTNGP04.phx.gbl ... 我使用下面的代码返回32位WinXP中的默认打印机 Pro ,但现在我正在运行64位Vista Business我收到一个错误: 使用System.Drawing.Printing; 使用(PrintDocument objPrintDocument = new PrintDocument()) { string strDefaultPrinter = objPrintDocument.PrinterSettings.PrinterName; } 错误消息是:未安装打印机。这似乎来自一个名为HdevmodeInternal的方法 但是,我安装了几台打印机,默认打印机是 旧HP LaserJet 5. 上述代码是否不适用于64位Vista?有问题的应用程序是为x86编译的 ... 我最好使用WMI返回默认打印机的名称? 我试图在谷歌和MSDN上找到一个解决方案,但是没有多少运气好吗? 感激不尽的任何帮助。 - www.markrae

适用于Vista 64和32位。如果您制作Microsoft XPS Document Writer会发生什么?默认打印机? Willy。

" Willy Denoyette [MVP]" < wi ************* @ telenet.bewrote in message 新闻:%2 **************** @ TK2MSFTNGP06.phx.gbl ...

" Mark Rae" < ma ** @ markNOSPAMraewrote in message news:u5 ************** @ TK2MSFTNGP04.phx.gbl ... > 我使用下面的代码返回32位WinXP Pro中的默认打印机,但现在我已经运行64位Vista Business我收到了一个错误: 使用System.Drawing.Printing; 使用(PrintDocument objPrintDocument = new PrintDocument() ) 字符串strDefaultPrinter = objPrintDocument.PrinterSettings.PrinterName; 错误信息是:没有安装打印机。而且似乎来自一个名为HdevmodeInternal的方法 但是,我安装了几台打印机,默认打印机是旧的HP LaserJet 5. <上面的代码不能在64位Vista上运行吗?有问题的应用程序是为x86编译的... 我最好使用WMI返回默认打印机的名称吗? 我试图在Google和MSDN上找到解决方案,但没有太多运气...... 感激不尽的任何帮助。 - www.markrae

适用于Vista 64和32位。如果您制作Microsoft XPS Document Writer会发生什么?默认打印机?

同样的事情......顺便提一下,它适用于我在32位Vista上...你有没有试过 它带有32在64位Vista上运行的应用程序...? 此外,当我尝试查询objPrintDocument.PrinterSettings.PrinterName时,它会返回b $ b。默认打印机没有设置。,虽然肯定是...... 生成的Exception仍然没有InnerException的任何值,并且 < Exception> .TargetSite.Name是HdevmodeInternal。 - 我甚至无法在Google的任何地方找到 ! - www.markrae

" Mark Rae" < ma ** @ markNOSPAMraewrote in message news:u4 ************** @ TK2MSFTNGP04.phx.gbl ... " Willy Denoyette [MVP]" < wi ************* @ telenet.bewrote in message 新闻:%2 **************** @ TK2MSFTNGP06.phx.gbl ...

>" Mark Rae" < ma ** @ markNOSPAMrae写信息新闻:u5 ************** @ TK2MSFTNGP04.phx.gbl ...

>> 我使用下面的代码返回32位WinXP Pro中的默认打印机,但现在我正在运行64 -bit Vista Business我收到了一个错误: 使用System.Drawing.Printing; 使用(PrintDocument objPrintDocument = new PrintDocument()) { string strDefaultPrinter = objPrintDocument.PrinterSettings.PrinterName; } 错误信息是:没有安装打印机。而且,它似乎来自一个名为HdevmodeInternal的方法 但是,我安装了几台打印机,默认打印机是旧的HP LaserJet 5. <上面的代码不能在64位Vista上运行吗?有问题的应用程序是为x86编译的... 我最好使用WMI返回默认打印机的名称吗? 我试图在Google和MSDN上找到解决方案,但没有太多运气...... 感激不尽的任何帮助。 - www.markrae

适用于Vista 64和32位。如果您制作Microsoft XPS Document Writer会发生什么?默认打印机?

同样的事情......顺便说一下,它适用于我在32位Vista上...你有没有尝试 它带有32在64位Vista上运行的应用程序应用程序......?

是的,X86和X64版本都适用于64位Vista Ultimate。 请注意,我总是将应用程序清单添加到我的可执行文件 程序集中。如果您没有向运行在 wow64下的应用程序添加清单,则此应用程序将获得注册表的虚拟化视图(部分 off)和文件系统(部分关闭)。 为了防止虚拟化,您必须添加如下清单: <?xml version =" 1.0"编码= QUOT; UTF-8英寸standalone =" yes"?> < assembly xmlns =" urn:schemas-microsoft-com:asm.v1" manifestVersion =" 1.0"> < assemblyIdentity version =" 1.0.0.0" name =" MyApplication.app">< / assemblyIdentity> < trustInfo xmlns =" urn:schemas-microsoft-com:asm.v2"> < security> < requestedPrivileges xmlns =" urn:schemas-microsoft-com:asm.v3"> < requestedExecutionLevel level =" asInvoker">< ; / requestedExecutionLevel> < / requestedPrivileges> < / security> < / trustInfo> < / assembly> 将上述内容保存在名为MyApplication.manifest的文件中,其中 " MyApplication"是程序集的名称(不是绝对必需的任何 名称将作为清单文件名)。 完成后,运行以下命令: mt -manifest MyApplication.manifest -outputresource:MyApplication.exe;#1 mt.exe是VS2005的一部分。 我'我不确定这会有什么帮助,但值得一试。 威利。

Hi, I have used the code below to return the default printer in 32-bit WinXP Pro, but now that I am running 64-bit Vista Business I''m getting an error: using System.Drawing.Printing; using (PrintDocument objPrintDocument = new PrintDocument()) { string strDefaultPrinter = objPrintDocument.PrinterSettings.PrinterName; } The error message is: "No printers are installed." and which seems to come from a method called HdevmodeInternal However, I have several printers installed, and the default printer is an old HP LaserJet 5. Does the above code not work on 64-bit Vista? The app in question is compiled for x86... Would I be better off using WMI to return the name of the default printer? I''ve tried to find a solution in Google and MSDN, but haven''t had much luck... Any assistance gratefully received. -- www.markrae

解决方案

"Mark Rae" <ma**@markNOSPAMraewrote in message news:u5**************@TK2MSFTNGP04.phx.gbl...

Hi, I have used the code below to return the default printer in 32-bit WinXP Pro, but now that I am running 64-bit Vista Business I''m getting an error: using System.Drawing.Printing; using (PrintDocument objPrintDocument = new PrintDocument()) { string strDefaultPrinter = objPrintDocument.PrinterSettings.PrinterName; } The error message is: "No printers are installed." and which seems to come from a method called HdevmodeInternal However, I have several printers installed, and the default printer is an old HP LaserJet 5. Does the above code not work on 64-bit Vista? The app in question is compiled for x86... Would I be better off using WMI to return the name of the default printer? I''ve tried to find a solution in Google and MSDN, but haven''t had much luck... Any assistance gratefully received. -- www.markrae

Works for me on Vista 64 and 32 bit. What happens if you make "Microsoft XPS Document Writer" the default printer? Willy.

"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message news:%2****************@TK2MSFTNGP06.phx.gbl...

"Mark Rae" <ma**@markNOSPAMraewrote in message news:u5**************@TK2MSFTNGP04.phx.gbl...

>Hi,I have used the code below to return the default printer in 32-bit WinXPPro, but now that I am running 64-bit Vista Business I''m getting anerror:using System.Drawing.Printing;using (PrintDocument objPrintDocument = new PrintDocument()){ string strDefaultPrinter =objPrintDocument.PrinterSettings.PrinterName;}The error message is: "No printers are installed." and which seems tocome from a method called HdevmodeInternalHowever, I have several printers installed, and the default printer is anold HP LaserJet 5.Does the above code not work on 64-bit Vista? The app in question iscompiled for x86...Would I be better off using WMI to return the name of the defaultprinter?I''ve tried to find a solution in Google and MSDN, but haven''t had muchluck...Any assistance gratefully received. --www.markrae

Works for me on Vista 64 and 32 bit. What happens if you make "Microsoft XPS Document Writer" the default printer?

Same thing... Incidentally, it works for me on 32-bit Vista... Did you try it with a 32-bit app running on 64-bit Vista...? Also, when I try to query objPrintDocument.PrinterSettings.PrinterName, it returns "Default printer is not set.", though it definitely is... The Exception generated still doesn''t have any value for InnerException, and the <Exception>.TargetSite.Name is "HdevmodeInternal" - I can''t even find that anywhere in Google! -- www.markrae

"Mark Rae" <ma**@markNOSPAMraewrote in message news:u4**************@TK2MSFTNGP04.phx.gbl...

"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message news:%2****************@TK2MSFTNGP06.phx.gbl...

>"Mark Rae" <ma**@markNOSPAMraewrote in messagenews:u5**************@TK2MSFTNGP04.phx.gbl...

>>Hi,I have used the code below to return the default printer in 32-bit WinXPPro, but now that I am running 64-bit Vista Business I''m getting anerror:using System.Drawing.Printing;using (PrintDocument objPrintDocument = new PrintDocument()){ string strDefaultPrinter =objPrintDocument.PrinterSettings.PrinterName;}The error message is: "No printers are installed." and which seems tocome from a method called HdevmodeInternalHowever, I have several printers installed, and the default printer isan old HP LaserJet 5.Does the above code not work on 64-bit Vista? The app in question iscompiled for x86...Would I be better off using WMI to return the name of the defaultprinter?I''ve tried to find a solution in Google and MSDN, but haven''t had muchluck...Any assistance gratefully received. --www.markrae

Works for me on Vista 64 and 32 bit. What happens if you make "MicrosoftXPS Document Writer" the default printer?

Same thing... Incidentally, it works for me on 32-bit Vista... Did you try it with a 32-bit app running on 64-bit Vista...?

Yep, both X86 and X64 flavors work on 64-bit Vista Ultimate. Note that I''m allways adding an application manifest to my executable assemblies. If you don''t add a manifest to an application that runs under wow64, this application will get a virtualized view of the registry (part off) and the file system (part off). To prevent virtualization you have to add a manifest like this: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <assemblyIdentity version="1.0.0.0" name="MyApplication.app"></assemblyIdentity> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> <security> <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> <requestedExecutionLevel level="asInvoker"></requestedExecutionLevel> </requestedPrivileges> </security> </trustInfo> </assembly> save above contents in a file named "MyApplication.manifest", where "MyApplication" is the name of the assembly (not absolutely required any name will do as manifest filename). When done, run the following command: mt -manifest MyApplication.manifest -outputresource:MyApplication.exe;#1 mt.exe is part of VS2005. I''m not sure this will be of any help, but it''s worth a try. Willy.

更多推荐

获得64位Vista中的默认打印机

本文发布于:2023-06-05 19:12:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/526441.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:打印机   Vista

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!