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
irina_lukina
Super 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 🙂

I’m not a member of the SmartBear Support Team, I’m just helping users in this community. Any views or opinions expressed do not necessarily represent those of SmartBear Software.
Oferv
Super Contributor

Hi Irina,



Thanks for clarify that but, if we'll take for example the following script:



 TargetFolder = "C:\Logs" 
 Set objShell = CreateObject("Shell.Application")
 Set objFolder = objShell.Namespace(TargetFolder)
 Set colItems = objFolder.Items
 For i = 0 to colItems.Count - 1
     colItems.Item(i).InvokeVerbEx("Print")
 Next



and try and convert it to c#script it will fail.



this is what i did so far but it fail:




 TargetFolder = ProjectSuite["Variables"]["TextFile"] 

     var objShell = Sys.OleObject("Shell.Application")

     var objFolder = objShell.Namespace(TargetFolder) 

     var colItems = objFolder.Items

     for (i = 0 ; i < colItems.Count - 1 ; i++)

         colItems.Item(i).InvokeVerbEx("Print")

     Next


would be happy if you can help me solve that one,the purpose is to print all files in a folder one by one



Thanks
irina_lukina
Super Contributor

Hi Ofer,


I've corrected your code a little bit, and it works fine:



 var TargetFolder = "C:\\Logs";

 var objShell = new ActiveXObject("Shell.Application");

 var objFolder = objShell["Namespace"](TargetFolder);

 var colItems = objFolder["Items"]();

 for (var i = 0; i < colItems["Count"]; i++)

     colItems["Item"](i)["InvokeVerbEx"]("Print");


FYI, the CreateObject object in VBScript corresponds to the new ActiveXObject statement in C#Script. Also, there is no need to specify Next at the end of the For statement. I hope this information helps 🙂

I’m not a member of the SmartBear Support Team, I’m just helping users in this community. Any views or opinions expressed do not necessarily represent those of SmartBear Software.
Oferv
Super Contributor

Thanks,You are great



Where can i read about all the objects purposes? like OleObject,ActiveXObject,etc i want to know how to convert this kind of code line by myself



Thanks
Oferv
Super Contributor

Irina,



How can i tell the system to use specific printer for printing the documents?the printer i want to use is the default one but somehow it doesn't use it for printing.



Thanks
irina_lukina
Super Contributor

Hi Ofer,


Where can i read about all the objects purposes? like OleObject,ActiveXObject,etc


You can find descriptions for all of these objects in MSDN (http://msdn.microsoft.com/).


i want to know how to convert this kind of code line by myself


I've found one useful article (it contains instructions on how to convert JScript code to VBScript code). I recommend that you read it and use some of the mentioned tips vice-versa.

Tips for Converting Samples to VBScript


How can i tell the system to use specific printer for printing the documents? the printer i want to use is the default one but somehow it doesn't use it for printing.


Please clarify one thing: does the script fail to print the selected files, or does it print them using another printer (not the default one)?

I’m not a member of the SmartBear Support Team, I’m just helping users in this community. Any views or opinions expressed do not necessarily represent those of SmartBear Software.
Oferv
Super Contributor

Hi Irina,



The document does printed but as you said it is using the wrong printer.

I'm using a script who install the printer and as it installed it becomes the default printer.once the script finish installing the printer it start printing list of document located in specific folder but,it start printing using the wrong printer.



Thanks
irina_lukina
Super Contributor

Hi Ofer,


Are you sure that the installed printer is recognized as the default one when you try using it for printing? I recommend that you try using Sys.Refresh() before printing the documents. Does this help?

I’m not a member of the SmartBear Support Team, I’m just helping users in this community. Any views or opinions expressed do not necessarily represent those of SmartBear Software.
Oferv
Super Contributor

Hi Irina,



Yes it does.no need to refresh,once it appear after the installation it has the green V mark,says it's the default.



I'm trying to install that printer using command line and when type this command line in the command prompt window it does install the printer's driver but,when trying to run it in TC i'm getting an error message:



here is the code:




  var cmdLine = rundll32.exe printui.dll,PrintUIEntry /ia /m "Printer Name" /v "Windows 7" /f "C:\\Users\\<USER>\\Downloads\\Drivers\\v3-x64\\xxx.inf"

  var WshShell = Sys.OleObject("WScript.Shell") 

  WshShell.Run(cmdLine)



Still need to solve the printing to default issue but it can wait for later,this one is more important for me right now.


Thanks
Oferv
Super Contributor

Hi Irina,



Well,i solved the command line issue.

and with regarding the sys.refresh,it looks like it's working as well.



Thanks for the help
cancel
Showing results for 
Search instead for 
Did you mean: