i write this code, that suppose to show me permissions list of users and groups on specific file or folder
import os, sys
import win32api
import win32security
import ntsecuritycon as con
from sys import argv
script, FILENAME = argv
def show_cacls (filename):
print
print
for line in os.popen ("cacls %s" % filename).read ().splitlines ():
print (line)
open (FILENAME,'w')
print (show_cacls(FILENAME))
it work great with files, but when i try to run on folder i get this error message:
Traceback (most recent call last): File "C:\Users\tzuriel\Desktop\test.py", line 15, in open (FILENAME,'w') PermissionError: [Errno 13] Permission denied: 'd:/study'
i run from administrator user.
any idea? TNX people
There could be many things wrong as your question is a little vague. I'll try and list some possible issues.
In Windows paths you have to use backslashes '\'. In your error it looks like you are passing 'd:/study' which is not a valid Windows path.
You should not be using os.popen
to call an external program. Please look at examples using the subprocess
module, http://docs.python.org/2/library/subprocess.html.
You could do something like:
import subprocess
import sys
script, filename = sys.argv
output = subprocess.check_output(["cacls", filename]).splitlines()
for i in output:
print(i)
There is no reason here to use a function here in a script file. I've also tried to follow standard Python (PEP8) formatting of variables, how to properly import modules, whitespace etc.