1
import os
import shutil

dir_src='D:\\'
dir_dst='C:\\Windows\\System32\\oobe\\Info\\backgrounds\\'
src_file=os.path.join(dir_src,'background.jpg')
dst_file=os.path.join(dir_dst,'backgroundefault.jpg')
print(os.path.join(dir_dst,'backgroundefault.jpg'))
shutil.move(src_file,dst_file)

I've been trying to copy a file to C:\Windows\System32\oobe\Info\backgrounds but I am getting this error:

Traceback (most recent call last):
C:\Windows\System32\oobe\Info\backgrounds\backgroundefault.jpg
  File "C:\python\python36\lib\shutil.py", line 544, in move
    os.rename(src, real_dst)
PermissionError: [WinError 5] Access is denied: 'D:\\background.jpg' -> 'C:\\Windows\\System32\\oobe\\Info\\backgrounds\\backgroundefault.jpg'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/Harish/Downloads/demo (1).py", line 9, in <module>
    shutil.move(src_file,dst_file)
  File "C:\python\python36\lib\shutil.py", line 558, in move
    copy_function(src, real_dst)
  File "C:\python\python36\lib\shutil.py", line 257, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "C:\python\python36\lib\shutil.py", line 121, in copyfile
    with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: 'C:\\Windows\\System32\\oobe\\Info\\backgrounds\\backgroundefault.jpg'

How can I resolve it?

Harry
  • 33
  • 1
  • 9
  • maybe a stupid question but do you run your script with admin rights? – studioj Jan 22 '18 at 07:11
  • If "ALL APPLICATION PACKAGES" means what it sounds like, what you did is probably pretty dangerous if you ever get any malware on your system. That said that doesn't actually sound like something microsoft would write, so are you sure you didn't give these permissions to a group with that name. – Bailey Parker Jan 22 '18 at 07:12
  • @BaileyParker, ok, I reverted permissions. Now, How can I run a script that can copy files to the path mentioned in the post.? – Harry Jan 22 '18 at 07:23
  • 1
    I don't windows anymore, but did you right click your cmd prompt and "Run as Administrator"? – Bailey Parker Jan 22 '18 at 07:25
  • Standard users don't have the right to modify system directories. With UAC enabled, `LsaLogonUser` (an RPC in lsass.exe) logs administrator accounts on with two linked tokens. One is restricted, and the other is unrestricted. It returns the restricted token, which, for example, is what winlogon.exe sets as the session token, which in turn is the access token of the shell (Explorer) and all processes that it creates by normal means. To start an elevated program that uses the unrestricted token (i.e. "Run as Administrator"), the shell sends the request to the "Application Information" service. – Eryk Sun Jan 23 '18 at 03:14
  • `ShellExecute[Ex]` (an in-process shell API from shell32.dll) implements elevating via its "runas" verb. This is a convenience API, so Windows programmers don't have to directly deal with the complications of making a remote procedure call to a system service. I don't know why they chose to implement it in only in the shell API rather than add another function in the `CreateProcess*` family. It's not fundamentally different from `CreateProcessWithLogonW` or `CreateProcessWithTokenW`, which send a request to the Secondary Logon service. – Eryk Sun Jan 23 '18 at 03:21

0 Answers0