Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Adding Printers
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Titre:
Versions des environnements
Visual FoxPro:
VFP 6 SP5
OS:
Windows XP SP2
Network:
Windows NT
Database:
Visual FoxPro
Divers
Thread ID:
00996148
Message ID:
00996368
Vues:
17
Hello Hugo

thank you for your reply!

isn't wsh 'that thingy' which people sometime switch off because of security reasons, or do i mix something up.

2nd. you write it need winXP+, i need this to work with win98+. but i am gonna look at it and keep it in my records for future task.

thank you!

>Gunnar,
>
>You can add printers with the method AddPrinterConnection of the WshNetwork object or with WMI (I preferr using WMI), but, having skimmed your other threads, my gut feeling is that are having other problems?
>
>A quick WMI function would be like (Requires XP or +):
>
>
>lcMessage = ''
>if addPrinter('\\PRINTSERVER\FRIENDLY PRINTER NAME', @lcMessage)
>	? 'Printer installed. Driver used: ' + lcMessage
>else
>	? 'Printer was not installed, the reason was: ' + lcMessage
>endif
>
>function addPrinter(tcPrinter, tcMessage)
>local loWMI, loPrinterClass, loPrinter, lnReturn, lcMessage, llMessage
>
>llMessage = pcount() = 2
>if Vartype(tcPrinter) # 'C' or Empty(tcPrinter)
>	if llMessage
>		tcMessage = 'Printer name is mandatory'
>	endif
>	return -1
>endif
>
>loWMI		= Getobject('WinMgmts:')
>loPrinterClass	= loWMI.Get('Win32_Printer')
>lnResult	= loPrinterClass.AddPrinterConnection(tcPrinter)
>do case
>case lnResult = 0
>	loPrinter = loWMI.Get('Win32_Printer.deviceID="' + Strtran(tcPrinter, '\', '\\') + '"')
>	lcMessage = loPrinter.DriverName
>case lnResult = 5
>	lcMessage = 'Access denied'
>case lnResult = 1797
>	lcMessage = 'The printer driver is unknown'
>case lnResult = 1801
>	lcMessage = 'Invalid printer name'
>case lnResult = 1930
>	lcMessage = 'Incompatible printer driver'
>otherwise
>	lcMessage = 'Unknown Error(' + Transform(lnResult) + ')'
>endcase
>
>tcMessage = lcMessage
>return lnResult = 0
>
>
>Update, Just saw you are using VFP 6, you probably will find a problem in the line:
>
>loWMI		= Getobject('WinMgmts:')
>
>replace it with
>
>loLocator	= createobject('WbemScripting.SWbemLocator')
>loWMI		= loLocator.ConnectServer()
>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform