# "pywintypes.error: (5, 'OpenSCManager', 'Access is denied.')" #43150

**URL:** <https://forum.ansible.com/t/pywintypes-error-5-openscmanager-access-is-denied-43150/28148>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [July 25, 2018, 10:52am UTC](https://forum.ansible.com/t/pywintypes-error-5-openscmanager-access-is-denied-43150/28148 "2018-07-25T10:52:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Usha\_Rani](https://avatars.discourse-cdn.com/v4/letter/u/22d042/32.png) [@Usha\_Rani](https://forum.ansible.com/u/Usha_Rani)\
**Post date:** [July 25, 2018, 10:52am UTC](https://forum.ansible.com/t/pywintypes-error-5-openscmanager-access-is-denied-43150/28148/1 "2018-07-25T10:52:39Z")

</div>

Hi Jborean,

I have tried with "win\_scheduled\_task"option like below…This time its not giving any error …and its not stopping the services as well. And the windows server i am trying is on 2008R2.  
Please tell how exactly i have to use this module to run the python script.

cat winStop.yml

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [July 25, 2018, 1:05pm UTC](https://forum.ansible.com/t/pywintypes-error-5-openscmanager-access-is-denied-43150/28148/2 "2018-07-25T13:05:10Z")

</div>

See the examples here: [https://docs.ansible.com/ansible/2.4/win\_scheduled\_task\_module.html#examples](https://docs.ansible.com/ansible/2.4/win_scheduled_task_module.html#examples) - this might clarify things a bit.

`path` needs to be a location for storing the task definition within scheduled tasks. If you run the scheduled tasks program on windows you can browse through the tree structure to find an appropriate location - its not a file system path

Also you probably need to set `executable:` to the full path to wherever python is installed on your windows machine and use `arguments` to tell python where the script is i.e. D:\smtn17\scripts\pystop.py

You might also need to set the user that scheduled tasks runs your python script as.

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [July 25, 2018, 7:37pm UTC](https://forum.ansible.com/t/pywintypes-error-5-openscmanager-access-is-denied-43150/28148/3 "2018-07-25T19:37:48Z")

</div>

If you wanted to go the scheduled task route I would use [https://docs.ansible.com/ansible/latest/modules/win\_scheduled\_task\_module.html#examples](https://docs.ansible.com/ansible/latest/modules/win_scheduled_task_module.html#examples) instead of the 2.4 link. win\_scheduled\_task went through a big overhaul in 2.5 deprecating some of the options like path. Anyway there’s a reason why I had that as the last option, you are going to have much more luck doing it with become like this

`

- name: run script with become  
win\_command: python.exe D:\smtn17\scripts\pystop.py  
become: yes  
become\_method: yes  
vars: # the values can be anything, I’m just using the standard connection user/var but you can choose any other  
ansible\_become\_user: ‘{{ ansible\_user }}’  
ansible\_become\_pass: ‘{{ ansible\_password }}’

`

[https://docs.ansible.com/ansible/latest/user\_guide/become.html#become-and-windows](https://docs.ansible.com/ansible/latest/user_guide/become.html#become-and-windows)

Scheduled tasks are cumbersome and hard to get right while become is a lot easier to use.

Thanks

Jordan

---

<div class="post-metadata">

**Author:** ![Usha\_Rani](https://avatars.discourse-cdn.com/v4/letter/u/22d042/32.png) [@Usha\_Rani](https://forum.ansible.com/u/Usha_Rani)\
**Post date:** [July 26, 2018, 10:47am UTC](https://forum.ansible.com/t/pywintypes-error-5-openscmanager-access-is-denied-43150/28148/4 "2018-07-26T10:47:37Z")

</div>

Hi JBorean,

I have tried the below options:

1. Method:  
become: yes

YAML:

- name: Stopping Hyperion Services  
win\_command: python.exe D:\smtn17\scripts\pystop.py  
become: yes  
become\_method: yes  
vars:  
ansible\_become\_user: ‘{{ ansible\_user }}’  
ansible\_become\_pass: ‘{{ ansible\_password }}’

ERROR:  
fatal: : FAILED! =\> {“msg”: “Internal Error: this connection module does not support running commands via True”}

1. Method:  
win\_psexec:

YAML:

- name: Stopping Hyperion Services  
win\_psexec:  
command: python.exe D:\smtn17\scripts\pystop.py  
executable: C:\Temp\PSTools\PsExec.exe  
register: stop\_mt

ERROR:  
{“changed”: true, “delta”: “0:00:01.297000”, “end”: “2018-07-26 09:53:00.248778”, “psexec\_command”: “C:\Temp\PSTools\PsExec.exe -accepteula "python.exe D:\smtn17\scripts\pystop.py"”, “rc”: 2, “start”: “2018-07-26 09:52:58.951778”, “stderr”: “The system cannot find the file specified.\r\n\rPsExec could not start python.exe D:\smtn17\scripts\pystop.py:\r\n”, “stderr\_lines”: [“The system cannot find the file specified.”, “”, “PsExec could not start python.exe D:\smtn17\scripts\pystop.py:”], “stdout”: “\r\nPsExec v2.2 - Execute processes remotely\r\nCopyright (C) 2001-2016 Mark Russinovich\r\nSysinternals - [www.sysinternals.com](http://www.sysinternals.com)\r\n\r\n”, “stdout\_lines”: [“”, “PsExec v2.2 - Execute processes remotely”, “Copyright (C) 2001-2016 Mark Russinovich”, “Sysinternals - [www.sysinternals.com](http://www.sysinternals.com)”, “”]}

1. Method:  
win\_scheduled\_task

YAML:

- name: Stopping Hyperion Services  
win\_scheduled\_task:  
name: Stop Task  
actions:
- path: D:\smtn17\scripts\pystop.py  
arguments: D:\smtn17\scripts  
register: stop\_mt

ERROR:  
NO ERROR. Executing succesfully. But task not executed. i.e services not stopped.

And i am going to try credssp auth method. Will keep you posted the result.

Thanks,  
Usha.

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [July 26, 2018, 11:06am UTC](https://forum.ansible.com/t/pywintypes-error-5-openscmanager-access-is-denied-43150/28148/5 "2018-07-26T11:06:40Z")

</div>

Sorry the first one should work, just change become\_method to `become_method: runas`. That’s my fault.

---

<div class="post-metadata">

**Author:** ![Usha\_Rani](https://avatars.discourse-cdn.com/v4/letter/u/22d042/32.png) [@Usha\_Rani](https://forum.ansible.com/u/Usha_Rani)\
**Post date:** [July 26, 2018, 12:13pm UTC](https://forum.ansible.com/t/pywintypes-error-5-openscmanager-access-is-denied-43150/28148/6 "2018-07-26T12:13:16Z")

</div>

Hi JBorean,

Thats Worked!!!.. Thanks So much JB…i am struggling from 3 days for this second hop issue. Thanks a lot.
