Ask a Question

how to launch control panel using code

Oferv
Super Contributor

how to launch control panel using code

Hi,



i would like to launch-->Devices and Printers but not by using recording but by using simple line codes.



does anyone have a solution?



Thanks 
19 REPLIES 19
AlexanderM
Staff


Hi Ofer,





You can use WScript.Shell:







Set WshShell = CreateObject("WScript.Shell")

WshShell.Exec("control printers")

-----

Alexander
Customer Care Manager
Oferv
Super Contributor

Hi Alex,



i did what you said and i'm getting the following error message.

see attached file



i think the proble is with VBS if you can provide the same code in JScript i think it's going to work



thanks
Oferv
Super Contributor

my 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
AlexKaras
Community Hero

Hi 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&... 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.
Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Oferv
Super Contributor

Hi 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
Oferv
Super Contributor

i 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
tristaanogre
Esteemed Contributor

Here'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
}


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Oferv
Super Contributor

Thanks Robert,



sure 🙂
Oferv
Super Contributor

Hi 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
cancel
Showing results for 
Search instead for 
Did you mean: