Ask a Question

I need to Start and Stop Window Services using Test complete J script?

SOLVED
VasanthVijay
Contributor

I need to Start and Stop Window Services using Test complete J script?

Hello ,

I need to Start and Stop Window Services using TestComplete J Script?

 

ThanksinAdvances

Vasanth.V

Thanks and Regards,
Vasanth.V
Wittmann Battenfeld India Pvt. Ltd.,
Chennai.
Email : Vasanth.Veeravijayan@wittmann-group.com
Website : www.wittmann-group.com
Mobile: +91 8870219392 | Landline: +91 44 4207700
23 REPLIES 23
k_de_boer03
Contributor

AlexKaras
Community Hero

Hi Vasanth,

 

You may either execute 'net start/stop' command using WScript.Run() or do this via WMI (google for something like "WMI stop windows service").

You may also search this forum - there were a couple of samples here on how to do this using WMI.

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
================================

Hello ,

           I already refered this link.But same code i use and it not affect on the Services .

Thanks and Regards,
Vasanth.V
Wittmann Battenfeld India Pvt. Ltd.,
Chennai.
Email : Vasanth.Veeravijayan@wittmann-group.com
Website : www.wittmann-group.com
Mobile: +91 8870219392 | Landline: +91 44 4207700

Hi,

 

-- Did you check in Task Manager that the relevant service process starts/stops?

-- Does the account that executes the start/stop code have anough privileges (as mentioned in the referenced article)?

-- Can you post here your actual code?

-- Any related messages in the Windows Event Viewer logs?

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
================================

I need to stop/start the service using javascript , I found this in testcomplete but it is using jscript. When I ran this I got an invalid parameter error. Can you help me convert this to javascript? I tried the suggestion in the thread as well to convert it somehow to javascript but got the not authorized error

 

function fn_GetService(computerName, serviceName)

{

var wmiService, objectsList, eObjectsList, item, sysID;

wmiService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\" +

computerName + "\\root\\cimv2");

objectsList = wmiService.InstancesOf("Win32_Service")

 

if (objectsList.Count > 0) {

eObjectsList = new Enumerator(objectsList);

for (; !eObjectsList.atEnd(); eObjectsList.moveNext()) {

item = eObjectsList.item();

if (item.Name == serviceName)

return item;

}

}

return null;

}

 

I appreciate your help. Thanks

 

tristaanogre
Esteemed Contributor

Actually, starting/stopping a windows service is simply a command line of "net start <servicename>" or "net stop <servicename>".  This can be done using the WshShell.Run method (https://support.smartbear.com/testcomplete/docs/reference/program-objects/wshshell/index.html).

 

The way I would do it is simply something like this.  FYI, this should work both for JScript as well as JavaScript&colon;

 

function startService(serviceName){
    WshShell.Run('net start ' + serviceName, 1, true);
}

function stopService(serviceName){
    WshShell.Run('net stop ' + serviceName, 1, true);
}. 

 


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

Thank you Robert, let me try.

CSL
Contributor

By the way can i use net stop remotely? I tried entering the path but failed. I need to stop & start the service remotely. Can you help?

CSL
Contributor

I also need to pass on credentials.

 

SO how can i use net stop to stop the service remotely with different credentials. Help please!

cancel
Showing results for 
Search instead for 
Did you mean: