0

In my Selenium Python script in my SetUpClass method I have some code which stops the tomcat service. It used to work fine but now I am getting the error: error: (5, 'OpenSCManager', 'Access is denied.')

Error details:

    C:\Python27\python.exe "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 5.0.3\helpers\pycharm\utrunner.py" G:\test_runners\selenium_regression_test_5_1_1\Regression_TestCase\split_into_parts\RegressionProject_TestCase_Part1.py true
Testing started at 09:13 ...

Error
Traceback (most recent call last):
  File "G:\test_runners\selenium_regression_test_5_1_1\Base\BaseTestCase.py", line 35, in setUpClass
    service_info(action_stop, Globals.machine, Globals.service_tomcat)
  File "G:\test_runners\selenium_regression_test_5_1_1\Utilities\HelperMethods.py", line 136, in service_info
    win32serviceutil.StopService(service, machine)
  File "C:\Python27\lib\site-packages\win32\lib\win32serviceutil.py", line 409, in StopService
    return ControlService(serviceName, win32service.SERVICE_CONTROL_STOP, machine)
  File "C:\Python27\lib\site-packages\win32\lib\win32serviceutil.py", line 315, in ControlService
    hscm = win32service.OpenSCManager(machine,None,win32service.SC_MANAGER_ALL_ACCESS)
error: (5, 'OpenSCManager', 'Access is denied.')


Process finished with exit code 0

setupClass method:

@classmethod
def setUpClass(cls):
    action_stop = 'stop' # to stop a service
    action_start = 'start' # to start a service
    build_text_file_directory = r"\\STORAGE-1\Builds\clearcore\autotest"


    # Stop Tomcat Service
    service_info(action_stop, Globals.machine, Globals.service_tomcat)

def service_info method:

def service_info(action, machine, service):
if action == 'stop':
    win32serviceutil.StopService(service, machine)
    print '%s stopped successfully' % service
elif action == 'start':
    win32serviceutil.StartService(service, machine)
    print '%s started successfully' % service
elif action == 'restart':
    win32serviceutil.RestartService(service, machine)
    print '%s restarted successfully' % service
elif action == 'status':
    if win32serviceutil.QueryServiceStatus(service, machine)[1] == 4:
        print "%s is running normally" % service
    else:
        print "%s is *not* running" % service

Globals.py:

machine = 'test1'
service_tomcat = 'Tomcat8'

How can I resolve the 'OpenSCManager', 'Access is denied.'please? My user details have not changed on the server.

Thanks, Riaz

Riaz Ladhani
  • 3,946
  • 15
  • 70
  • 127

0 Answers0