2

I want to select printer in Silverlight program, just like ATM or POS that will automatically print without selecting printer.

I browse internet and found: http://bytes.com/topic/c-sharp/answers/255914-set-default-printer-machine, it says that using System.Management package, using ManagementObject and ManagementBaseObject class, but I cannot add/import the class.

How to add using System.Management in Silverlight, or is any other way to selectt printer in silverlight code?

Regards, Imam

1 Answers1

2

You can't do this natively in Silverlight. The System.Management "package" (as you call it) is not compatible with the Silverlight runtime, its designed for the full .NET CLR.

If you are running OOB with Elevated Trust then you may be able to use the AutomationFactory to achieve this goal:-

 var scriptNetwork = AutomationFactory.CreateObject("WScript.Network");
 scriptNetwork.SetDefaultPrinter("nameOfPrinterToSetAsDefault");
AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
  • Thank you anthony, yes indeed now I try to print using OOB / dll, and it already run in local, but when I install in the hardware machine, I cannot REGSVR32 WScriptCom.dll – ibaihaqi_silverlight Dec 12 '11 at 03:14
  • So I add new project inside the solution the name of project is ComExampleLib inside that project there is let say WScript and method SetDefaultPrinter, and it already run in local I can print wiithout popup select printer, but I need to run in the hardware, so I register the .dll file: ComExampleLib\bin\Debug\ComExampleLib.dll with Regsvr32 ComExampleLib.dll the error is Make sure that "ComExampleLib.dll" isa valid DLL or OCX file. Please help me how to register dll file? thank you again – ibaihaqi_silverlight Dec 12 '11 at 03:24
  • What are you trying intall `WScriptCom.dll`? The WScript component is already present on a Windows machine. – AnthonyWJones Dec 12 '11 at 12:44
  • oh ic thank you, I was trying create dll for printing name it WScriptCom, which consist System.Management inside the code – ibaihaqi_silverlight Dec 13 '11 at 05:35