Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Granting Folder Permissions to Users

Status
Not open for further replies.

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
 
This is almost certainly down to Windows user account control, you would need to run the command line with elevated privileges for it to work for the Program Files or Program Files (x86) folders. I am sure that you could use Windows API calls to accomplish the same thing, but a far better approach would be to put your application on a network drive, with a network group granting appropriate permissions to front and back end locations. It also means that your data are run from a server so that they can be backed up quite easily.

This way the only things in the Program Files or Program Files (x86) folder are Access itself or the Access runtime, rather than your data.

John
 
I install apps on large networks, this has become a problem with Windows 7 computers, the rights are much more restricted on a lot of the Windows standard folders. Interestingly, while you cannot create folders under Program Files, you can create one under the C:\ root as the logged in user, and it will give the folder the same rights as the currently logged in user, that's been my work around.
 
Oh, and on installing an .mdb based app on the server side, I don't agree, put the front end on the user's hard drive, the only thing that should be on the network is any shared data, it will run a lot faster, especially if your users are on a slow VPN. Also, if you ware distributing code for use on a corporate network, put a shared "main menu" app on the server and put code in it to check for a "latest update" front end copy that you control using a single record version# table, if the front end client's version does not match whatever your current version number is from your distribution copy, the "main menu" program automatically copies your latest version to his hard drive, it is a great way to automatically install bug fixes and such.
 
Jock is right non the money, here! Only the Back End belongs on a server; copies of Front Ends must go on the users' hard drives.

The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top