Setting File Permissions on Windows 7
Setting File Permissions on Windows 7
I have an application that installs a folder with files to the All Users/Application Data folder. When an admin installs the application the files are available. However, if another, non-admin user tries to run the application and access the files there's an error because the files only have read and execute permissions and not write permissions. How can I give the folder and files write permissions?
-
- Enthusiast
- Posts: 252
- Joined: Mon Aug 16, 2010 4:29 am
Re: Setting File Permissions on Windows 7
If you do not want to put things in a shared public folder then do this from a command window opened with "Run As Administrator":
This allows any user to modify anything in \appname\ but not in \ProgramData\. If you want only one user to be able to modify a file then create a directory for each user and use ICACLS once for each username and directory.
Code: Select all
ICACLS.EXE C:\ProgramData\appname\ /T /C /grant Users:F
Re: Setting File Permissions on Windows 7
Thanks for the reply. Where can I find info on running ICACLS from PureBasic. My searches haven't returned anything useful. If I understand your response, it tells how to set the permissions from the desktop but not at runtime from PB.
Do I need to do something like this:
In this example, would it be better to get "C:\Windows\System32\" from PB so it works with all drive configs and OS versions?
Where do I find the parameters to pass to the icacls.exe to change permissions?
If I have to create a directory for each user, how are the files configured and named? I don't know much about how Windows does this.
Do I need to do something like this:
Code: Select all
RunProgram("C:\Windows\System32\icacls.exe"," "+file$ + " /grant administrators:F","",#PB_Program_Wait|#PB_Program_Hide)
Where do I find the parameters to pass to the icacls.exe to change permissions?
If I have to create a directory for each user, how are the files configured and named? I don't know much about how Windows does this.
-
- Enthusiast
- Posts: 252
- Joined: Mon Aug 16, 2010 4:29 am
Re: Setting File Permissions on Windows 7
The example you posted would only give write permission to users with elevated privileges(Administrators) and not all users. If you are not familiar with using CreateDirectory(), CreateFile(), or RunProgram(), just search the PB forum for examples. It matters little if you run ICACLS from your program or from a script or BAT file ... just run it after creating the folders. As I recall, special directory permissions will not be needed on versions of windows before VISTA however CACLS was the command before ICACLS.
Your toughest problem will be with modern Windows User Account Control (UAC). Keep in mind a user with elevated privileges will have to OK changes to his PC through UAC. Usually that is started by right-clicking after download and selecting "Run as Administrator". Good luck.
Your toughest problem will be with modern Windows User Account Control (UAC). Keep in mind a user with elevated privileges will have to OK changes to his PC through UAC. Usually that is started by right-clicking after download and selecting "Run as Administrator". Good luck.
-
- Enthusiast
- Posts: 536
- Joined: Mon Feb 16, 2009 10:42 am
- Location: sweden
- Contact:
Re: Setting File Permissions on Windows 7
Also keep in mind that ICACLS is language-dependant. If I have Swedish windows, you cannot write "Users:F".... You need to write that in the original language! (damn tools). Try to stay as far away from UAC as possible, move your files to "my documents" or whatever...
-
- Enthusiast
- Posts: 536
- Joined: Mon Feb 16, 2009 10:42 am
- Location: sweden
- Contact:
Re: Setting File Permissions on Windows 7
Also keep in mind that ICACLS is language-dependant. If I have Swedish windows, you cannot write "Users:F".... You need to write that in the original language! (damn tools). Try to stay as far away from UAC as possible, move your files to "my documents" or whatever...
Re: Setting File Permissions on Windows 7
Ok. I've been able to come up with this which doesn't seem to quite work. The values do work when I run it icacls.exe directly.
Also, how can I use ReadProgramError to catch errors? I couldn't find any good examples, and what I've tried hasn't worked.
Code: Select all
RunProgram("C:\Windows\System32\icacls.exe", "C:\ProgramData\AppName\Content\data\" + "/grant Users:(OI)(CI)M", "", #PB_Program_Wait|#PB_Program_Hide)
Also, how can I use ReadProgramError to catch errors? I couldn't find any good examples, and what I've tried hasn't worked.
Re: Setting File Permissions on Windows 7
Here's a version I that does work:
Besides minor tweaks, I think this only work when the directory is first created which is one of the reasons it wasn't initially working for me.
Code: Select all
RunProgram("C:\Windows\System32\icacls.exe", Chr(34)+"C:\ProgramData\Fablevision\Big Screen Books\data" +Chr(34)+ " /grant Users:(OI)(CI)M", "", #PB_Program_Wait|#PB_Program_Hide)
Re: Setting File Permissions on Windows 7
Hi,
To catch the out put, use something like this :
To catch the out put, use something like this :
Code: Select all
Procedure RunCom(cmd$,arg$,extra=0)
result=-245678 ; returned if our cmd fails
prgid=RunProgram(cmd$,arg$, "", #PB_Program_Read|#PB_Program_Open|#PB_Program_Hide)
If prgid
Repeat
While AvailableProgramOutput(prgid)
in$=(ReadProgramString(prgid))
Debug in$
Wend
Delay(10)
Until ProgramRunning(prgid)=0
result=ProgramExitCode(prgid)
EndIf
ProcedureReturn result
EndProcedure
result=RunCom("wrong.exe","dir c:")
Debug "Exit Code : " + Str(result)
result=RunCOm("C:\Windows\System32\icacls.exe", Chr(34)+"C:\ProgramData\Fablevision\Big Screen Books\data\*.*" +Chr(34)+ " /grant Users:(OI)(CI)M")
Debug "Exit Code : " + Str(result)
----
R Tape loading error, 0:1
R Tape loading error, 0:1