Forum Discussion
19 Replies
Sort By
Hi Ofer,
You can use WScript.Shell:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Exec("control printers")- OfervSuper Contributor
- OfervSuper Contributormy purpose is to see if new printer i installed is on the printer's list.
is there any other way to do that by using only code lines,without recording?
thanks - AlexKarasChampion Level 3Hi Ofer,
'wmi get installed printers list' Google request (http://www.google.com/#sclient=psy-ab&hl=en&newwindow=1&source=hp&q=wmi+get+installed+printers+list&pbx=1&oq=wmi+get+installed+printers+list&aq=f&aqi=&aql=1&gs_sm=e&gs_upl=0l0l1l67l0l0l0l0l0l1l1392l1392l7-1l1l0&bav=on.2,or.r_gc.r_pw.&fp=bbee5fb44766566e&biw=1075&bih=713) returns a set of script code samples that you may adopt to your needs.
E.g. you may get the list of installed printers before and after installing a printer and check if they are different and whether the latter list contains the just installed printer name. - OfervSuper ContributorHi Alex,
that's cool but i don't know how to merge WMI code with c#script code and if it's possible at all.
can you give an example please?
Thanks - OfervSuper Contributori got this code lines:
Set objNetwork = WScript.CreateObject("WScript.Network")
Set colPrinters = objNetwork.EnumPrinterConnections
For i = 0 to colPrinters.Count -1 Step 2
Wscript.Echo colPrinters.Item(i) & vbTab & colPrinters.Item (i + 1)
Next
that if i put in a .vbs file and run i get the list of printes.now, is there an option that this code will run not from a .vbs file but from the test complete and that i'll be able to get each printer's name a nd compare it to a name i'm looking for?
Thanks - tristaanogreEsteemed ContributorHere's how that VBS stuff code would work, translated to JScript in TestComplete (posted, BTW, on the SQAForums thread you started on this topic... it's helpful if you keep conversations on a single source to make it easier to know what has been discussed already)
function PrintersListing()
{
var WScriptObj = Sys.OleObject("WScript.Network")
var PrintersCollection = WScriptObj.EnumPrinterConnections()
var Index
for (Index=0;Index<PrintersCollection.length;Index += 2)
{
Log.Message("Port " + PrintersCollection.Item(Index) + " = " + PrintersCollection.Item(Index+1))
}
}
To do the comparison that you want, it would be a matter of changing the Log.Message call to a comparison call. I haven't tested this part yet but I assume it would look something like this.function CheckPrinterExists(PrinterName)
{
var WScriptObj = Sys.OleObject("WScript.Network")
var PrintersCollection = WScriptObj.EnumPrinterConnections()
var Index
for (Index=0;Index<PrintersCollection.length;Index += 2)
{
if (PrintersCollection.Item(Index+1) == PrinterName)
return true
}
Log.Warning("Printer " + PrinterName + " not found in windows installation")
return false
} - OfervSuper ContributorThanks Robert,
sure :) - OfervSuper ContributorHi Robert,
few month ago you reply me with an answer contain the following line:
VBS stuff code would work, translated to JScript in TestComplete
can you please tell me how exactly TC translate VBS to JScript?how you did it?
Thanks - irina_lukinaSuper Contributor
Hi Ofer,
I guess, when Robert said:
,VBS stuff code would work, translated to JScript in TestComplete
he meant that he just converted this code manually. He replaced VBScript commands and operations with their analogs used in JScript. The fact is that TestComplete doesn't provide you with such automatically converting features.I hope this information helps :)
Related Content
- 6 years agocmbdnne
- 8 years agom_essaid
- 5 years agodjvakarjoshi1
Recent Discussions
- 14 seconds agoSvetaG