i want to check if specific printer i installed was installed properly and was added to the printer's list.i don't want to do it by recording but by using code lines.
does anyone have an idea what code lines (JScript or any other) should i add to my script in order to do that?
my script is running C#Script.
The following code will print out to the log file the listing of all printers and their ports currently configured on the system. Instead of logging, you could put a comparison check to see if the printer collection contains a printer who's name equals the name you are looking for.
<font class="small">Code:</font><hr /><pre>function PrintersListing()
var WScriptObj = Sys.OleObject("WScript.Network")
var PrintersCollection = WScriptObj.EnumPrinterConnections()
for (Index=0;Index<PrintersCollection.length;Index += 2)
Log.Message("Port " + PrintersCollection.Item(Index) + " = " + PrintersCollection.Item(Index+1))
Automated Testing Evangelists
Definition expert - noun - Unknown drip under pressure
Here's another sample:
<font class="small">Code:</font><hr /><pre>function test()
var printerName = "PDF Printer for LoadComplete";
Log.Message("The \"" + printerName + "\" printer exists in the system.");
Log.Warning("The \"" + printerName + "\" printer doesn't exist in the system.");
var oWMIService = WMI.Service;
var installedPrinters = oWMIService.ExecQuery("Select * from Win32_Printer");
for (var i = 0; i < installedPrinters.Count; i++)
if (installedPrinters.ItemIndex(i).Properties_.Item(" Name").Value == printerName)
BTW, I recommend using JScript instead of C#Script, unless you are going to create C# Connected applications or Self-Testing applications. The JScript syntax is more intuitive, and the two languages have equal functionality. Also, note that C#Script scripts can be launched in JScript projects, and vice versa. The same applies to C++Script. Please see the "Selecting the Scripting Language" help topic for more information.