2

I am trying to install java silently in the background using a python script. The path is correct and verified with isfile. I recieve an Access Denied exception. I am running this as an administrator on my local machine.

subprocess.Popen('C:\Users\xUser\jdk-8u45-windows-x64.exe /s ADDLOCAL="ToolsFeature,SourceFeature"');

error returns

WindowsError: [Error 5] Access is denied
General4077
  • 435
  • 1
  • 8
  • 17
user2569803
  • 637
  • 6
  • 11
  • 19
  • 1
    You have some un-escaped backslashes in that path. Don't think that would cause the error, but it might be worth prepending the string with an **r**: **r'C\Users\...'** so it is interpreted as a raw string. – SiHa Jul 14 '15 at 20:53
  • related: [Why am i getting WindowsError: [Error 5\] Access is denied?](http://stackoverflow.com/q/28528020/4279). Make sure `import getpass; print(getpass.getuser())` prints the expected value. – jfs Jul 14 '15 at 22:52

1 Answers1

1

Are you running this in a regular terminal? In Windows, you need to open the terminal specially for administrative privileges:

  1. In the Start menu search window, type cmd and press Ctrl+Shift+Enter. Or, navigate to All Programs > Accessories > right click on Command Prompt and click Run as administrator.
  2. Run the python script in this new terminal.

Edit: a search yields it also may be an issue with executing the command after navigating to the directory the installer is located in; see WindowsError [error 5] Access is denied.

install_dir=r"C:\Users\xUser\"
assert os.path.isdir(install_dir)
os.chdir(install_dir)
subprocess.Popen('jdk-8u45-windows-x64.exe /s ADDLOCAL="ToolsFeature,SourceFeature"')

Finally, I always use an array of commands for Unix (not sure if it's required in Windows), not one long string, e.g.

subprocess.Popen(['jdk-8u45-windows-x64.exe', '/s', 'ADDLOCAL="ToolsFeature,SourceFeature"']).

Community
  • 1
  • 1
FTA
  • 335
  • 1
  • 7
  • So I actually have tried that. I can run C:\Users\xUser\jdk-8u45-windows-x64.exe /s ADDLOCAL="ToolsFeature,SourceFeature" from the command line as an administrator already. I just see the issue with subprocess within the script – user2569803 Jul 14 '15 at 20:52
  • Closer! only this issue now ::::: assert os.path.isdir(install_dir) AssertionError – user2569803 Jul 14 '15 at 20:59
  • Did you include the `r` before `"C:\Users\xUser\"`? – FTA Jul 14 '15 at 21:04
  • WindowsError: [Error 740] The requested operation requires elevation – user2569803 Jul 15 '15 at 12:59
  • Okay, so now you are getting the file to actually run. This error means you do not have the correct privileges/permissions. So make sure that you are now running this python script in a command prompt that was opened as an administrator. – FTA Jul 15 '15 at 16:14