Not able to "import win32com.shell.shell" in python3.8.3 to execute admin command prompt commands using python3

Viewed 3293

We were using python 2 in our project and we had created various scripts that work on Windows 10 using pywin32 lib and were using import win32com.shell.shell as shell and then execute the shell commands like shell.ShellExecuteEx(lpVerb='runas', lpFile='cmd.exe', lpParameters='/c ' + commands) where commands is the command which we use to execute as admin prompt.

Our script needs to do some installation which we pass as command and recently due to executive decision we have to move to python3 and when I am trying to import import win32com.shell.shell as shell it is not able to import it.

Can someone please suggest how can we execute shell command as admin in python 3.8.3 on Windows 10?

1 Answers

win32com.shell.shell as shell would be imported exclusively on python2 if you wanted to upgrade you would have to update to a newer version of pywin32. A github repo has released v225 which supports Python 3.8.3 install the files and you should be able to use your code without any import errors

https://github.com/CristiFati/Prebuilt-Binaries/tree/master/PyWin32/v225

if that does not work that alternative solution is using a replica module

pip3 install pypiwin32


import pypiwin32 

this module should come with shell capabilities

Related