emendelson Posted June 1, 2006 Share Posted June 1, 2006 I'm trying to write a script that installs a printer driver (one of the freeware ones that create PDF files) and then assigns it a share name so it can later be used in the command net use lptn \\computername\sharename Two questions: First, can AutoIt change the settings of a printer on a local machine so that the printer is shared? And can AutoIt assign a sharename to the printer? Next, I know how to read "Net use" to see if any LPTn ports are already assigned. But how can I tell if LPT1, LPT2, or LPT3 are PHYSICALLY present on the machine so that my script doesn't try to assign them? Thanks for any help. Link to comment Share on other sites More sharing options...
ptrex Posted June 1, 2006 Share Posted June 1, 2006 (edited) This is how you install a printer and share it. $strComputer = "." $objWMIService = ObjGet("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") $objPrinter = $objWMIService.Get("Win32_Printer").SpawnInstance_ $objPrinter.DriverName = "HP LaserJet 4000 Series PS" $objPrinter.PortName = "IP_169.254.110.160" $objPrinter.DeviceID = "PublicPrinter" $objPrinter.Location = "USA/Redmond/Building 37/Room 114" $objPrinter.Network = 1 $objPrinter.Shared = 1 $objPrinter.ShareName = "PublicPrinter" $objPrinter.Put_() oÝ÷ Ù8b²X¬¶Æ¥â׫¦í±«ÚV殶s` ¢b33c¶ö&¤F7Föæ'Òö&¤7&VFRgV÷Cµ67&FæräF7Föæ'gV÷C² ¢b33c·7G$6ö×WFW"ÒgV÷C²âgV÷C°¢b33c¶ö&¥tÔ6W'f6RÒö&¤vWBgV÷C·væÖv×G3¢gV÷C²ð¢fײgV÷C·¶×W'6öæFöäÆWfVÃÖ×W'6öæFWÒb333²b3#²b3#²gV÷C²fײb33c·7G$6ö×WFW"fײgV÷C²b3#·&ö÷Bb3#¶6×c"gV÷C² ¢b33c¶6öÅ&çFW'2Òb33c¶ö&¥tÔ6W'f6RäWV5VW'ð¢gV÷Cµ6VÆV7B¢g&öÒvã3%õ&çFW"gV÷C² ¤f÷"b33c¶ö&¥&çFW"âb33c¶6öÅ&çFW'2¢b33c¶ö&¤F7Föæ'äFBb33c¶ö&¥&çFW"å÷'DæÖRÂb33c¶ö&¥&çFW"å÷'DæÖR¤æW@ ¢b33c¶6öÅ÷'G2Òb33c¶ö&¥tÔ6W'f6RäWV5VW'ð¢gV÷Cµ6VÆV7B¢g&öÒvã3%õD5&çFW%÷'BgV÷C²¤f÷"b33c¶ö&¥÷'Bâb33c¶6öÅ÷'G0¢bb33c¶ö&¤F7Föæ'äW7G2b33c¶ö&¥÷'BäæÖRFVà¢b33c·7G%W6VE÷'G2Òb33c·7G%W6VE÷'G2fײð¢b33c¶ö&¤F7Föæ'äFVÒb33c¶ö&¥÷'BäæÖRfײ5$Äb¢VÇ6P¢b33c·7G$g&VU÷'G2Òb33c·7G$g&VU÷'G2fײb33c¶ö&¥÷'BäæÖRfײ5$Ä`¢VæD`¤æW@ ¦×6v&÷ÂgV÷C²gV÷C²gV÷C²ÂgV÷CµFRföÆÆ÷vær÷'G2&RâW6S¢gV÷C²fײ5$Äbfײb33c·7G%W6VE÷'G2¦×6v&÷ÂgV÷C²gV÷C²ÂgV÷CµFRföÆÆ÷vær÷'G2&RfÆ&ÆS¢gV÷C²fײ5$Äbfײb33c·7G$g&VU÷'G2 There are lot's of more possibilities with WMI. regards Edited June 1, 2006 by ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
ptrex Posted June 1, 2006 Share Posted June 1, 2006 this one lists all parallel port on a machine $strComputer = "." $objWMIService = ObjGet("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") $colItems = $objWMIService.ExecQuery("Select * from Win32_ParallelPort") For $objItem in $colItems _WriteLog ("Availability: " & $objItem.Availability) For $strCapability in $objItem.Capabilities() MsgBox (0,"","Capability: " & $strCapability) Next MsgBox (0,"","Description: " & $objItem.Description) MsgBox (0,"","Device ID: " & $objItem.DeviceID) MsgBox (0,"","Name: " & $objItem.Name) MsgBox (0,"","OS Auto Discovered: " & $objItem.OSAutoDiscovered) MsgBox (0,"","PNP Device ID: " & $objItem.PNPDeviceID) MsgBox (0,"","Protocol Supported: " & $objItem.ProtocolSupported) Next regards Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
emendelson Posted June 1, 2006 Author Share Posted June 1, 2006 ptrex, Many thanks for these. The first script you posted, the one that installs and shares the printer, fails in this situation, apparently because the printer is already installed - and all I want to do is share the printer that is installed already. The downloaded driver file installs the printer by itself - what I want the script to do is share the already-existing printer. I've plugged-in the settings that I found for the already-installed printer, and invented a Device ID like this: $strComputer = "." $objWMIService = ObjGet("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") $objPrinter = $objWMIService.Get ("Win32_Printer").SpawnInstance_ $objPrinter.DriverName = "BullZIP PDF Printer" $objPrinter.PortName = "BULLZIP" $objPrinter.DeviceID = "PDFPrinterTest" $objPrinter.Location = "Local" $objPrinter.Network = 1 $objPrinter.Shared = 1 $objPrinter.ShareName = "PDFPrint" $objPrinter.Put_ () But the Put_ line always fails. I've searched in the various Windows scripting sites for a solution, but can't find one. Many thanks again. Link to comment Share on other sites More sharing options...
emendelson Posted June 1, 2006 Author Share Posted June 1, 2006 In the script to list available printer ports, I got various syntax errors (there's a triple quote rather than a double quote in the second-to-last line, easily fixed): I don't know how to fix the error that seems to be in this line: $objDictionary.Item($objPort.Name) (& @CRLF) I tried various varieties of removing the parens, which let the script get to the point of an error in this line: $objDictionary.Add ($objPrinter.PortName, $objPrinter.PortName) Any further help gratefully received! Link to comment Share on other sites More sharing options...
emendelson Posted June 1, 2006 Author Share Posted June 1, 2006 In the script to list all parallel ports on a machine, it fails, first because the _WriteLog function isn't available (but still fails if I comment out that line), and next, it fails on this line: For $strCapability in $objItem.Capabilities() with the error message: Variable must be of type "Object".: Again, any help in making these work would be very gratefully received. Link to comment Share on other sites More sharing options...
ptrex Posted June 1, 2006 Share Posted June 1, 2006 @Edward Mendelson 1. Shares : Share information is stored in the registry key : SYSTEM\CurrentControlSet\Services\LanmanServer\Shares Best way is to add a share manually -> open the registry and read the key above. Than you can use the RegWrite() Function to create the key by AutoIT. 2. List Ports Try this one : $strComputer = "." $objWMIService = ObjGet("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") $colItems = $objWMIService.ExecQuery("Select * from Win32_ParallelPort") For $objItem in $colItems MsgBox (0,"","Availability: " & $objItem.Availability) ;For $strCapability in $objItem.Capabilities() ; MsgBox (0,"","Capability: " & $strCapability) ;Next MsgBox (0,"","Description: " & $objItem.Description) MsgBox (0,"","Device ID: " & $objItem.DeviceID) MsgBox (0,"","Name: " & $objItem.Name) MsgBox (0,"","OS Auto Discovered: " & $objItem.OSAutoDiscovered) MsgBox (0,"","PNP Device ID: " & $objItem.PNPDeviceID) MsgBox (0,"","Protocol Supported: " & $objItem.ProtocolSupported) Next Sorry I did not test it all. Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
emendelson Posted June 1, 2006 Author Share Posted June 1, 2006 @Edward Mendelson 1. Shares : Share information is stored in the registry key : SYSTEM\CurrentControlSet\Services\LanmanServer\Shares Best way is to add a share manually -> open the registry and read the key above. Than you can use the RegWrite() Function to create the key by AutoIT. 2. List Ports Try this one : $strComputer = "." $objWMIService = ObjGet("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") $colItems = $objWMIService.ExecQuery("Select * from Win32_ParallelPort") For $objItem in $colItems MsgBox (0,"","Availability: " & $objItem.Availability) ;For $strCapability in $objItem.Capabilities() ; MsgBox (0,"","Capability: " & $strCapability) ;Next MsgBox (0,"","Description: " & $objItem.Description) MsgBox (0,"","Device ID: " & $objItem.DeviceID) MsgBox (0,"","Name: " & $objItem.Name) MsgBox (0,"","OS Auto Discovered: " & $objItem.OSAutoDiscovered) MsgBox (0,"","PNP Device ID: " & $objItem.PNPDeviceID) MsgBox (0,"","Protocol Supported: " & $objItem.ProtocolSupported) Next Sorry I did not test it all. No need to apologize - I'm very glad to have this. On my system the script correctly reports that LPT1 is "available" - so presumably that means that I can use LPT2 or LPT3 in a "net use" command - but it seems that I also have to parse the output of NET USE to see if either of those is being used. (This is for a DOS app, so I can't use LPT4 or higher.) Does that sound right? As for shares, your method looks as if it's going to work perfectly. I manually added the share, and found the Multi-string entry that was created. Thanks again for all this! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now