Need help overcoming Permission denied error for vb script in Vista

Discussion in 'Visual Basic ( VB )' started by SimonG, Jun 24, 2010.

  1. SimonG

    SimonG New Member

    Jun 24, 2010
    Likes Received:
    Trophy Points:
    Home Page:

    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

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice