Go4Expert (http://www.go4expert.com/)
-   Visual Basic ( VB ) (http://www.go4expert.com/forums/visual-basic/)
-   -   Need help overcoming Permission denied error for vb script in Vista (http://www.go4expert.com/forums/help-overcoming-permission-denied-error-t22518/)

SimonG 24Jun2010 15:19

Need help overcoming Permission denied error for vb script in Vista

I am writing script that will refresh a users environment (desktop and start menu) with master copies. Using wsh and vb I have a routine to replace the folders and files; but when ran on Vista the routine returns a runtime error: code 800A0046 Permission denied. Can anyone advise what I am missing to get the script to work?

The script is ran manually by an administrator user.

To try and overcome the premissions problem I run the following* before trying to remove the old files:

Function SetPermissions(strChangeFolder, strUser, strRights)
Dim strHome
Dim intRunError, objShell, objFSO
Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strChangeFolder) Then
    intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " & _
          strChangeFolder & " /e /c /g " & _
          strUser & ":" & strRights, 2, True)
    If intRunError <> 0 Then
          reply = MsgBox ("Error assigning permissions for user " & strUser & Chr(13) & _
              " to folder: " & Chr(13) & _
              strChangeFolder, _
    End If
End If
End Function

The routine is passed the username of the administrator, and F as the required rights. Although the intRunError returns 0, the rights on the the target folder do not appear to be changed (looking through Windows Explorer).

As a final sanity check I can complete the scripts tasks manually using Explorer. Doing this when I first attempt to open the target folder (eg the users desktop folder) Explorer first tells me I have no rights and asks me to confirm that I am an administrator, once this is done the rest of the tasks can be completed.

* Code based on recommendations in the posting "How to set folder permissions with VBScript" on this forum (sorry - new to board so can't link yet)

Windows version: Vista Business SP2 32-bit

All times are GMT +5.5. The time now is 17:23.