PercyN
Programmer
- May 16, 2007
- 86
Hi,
I'm using the code below on my spalsh form to giving permission to the folder in the folder that houses my FE and BE. This only runs, the first time the application executes on a computer after installtion. Seems quite straight forward, but it does not work.
It works when I install application anywhere apart from C:\Program Files (x86). In one of my tests I used C:\Test and it worked but once I reverted back to the former, then nothing works. Perhaps windows does not allow read/write permission to be granted to folders in the Program Files folder. Manually though it works when I grant permissions to the current User. I know there is a way to get the current User and grant read/write permissions to just that User instead of to Everyone. That would probably work.
Can someone please point me in the right direction.
Thanks
Code:
Public Function SetPermissions()
Dim strHomeFolder, strHome, strUser
Dim intRunError, objShell, objFSO
strHomeFolder = Application.CurrentProject.Path 'Points to "C:\Program Files (x86)\ApplicationFolder"
Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strHomeFolder) Then
intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls """ & strHomeFolder & """ /e /c /g everyone:F ", 2, True)
If intRunError <> 0 Then
MsgBox "Error assigning permissions for user " _
& strUser & " to application folder " & strHomeFolder
End If
End If
End Function