none
Folder Permissions VBscript

    Question

  • I have created a script to revoke permissions to certain folders in c Drive . but the problem is the script have revoked rights of admin too and now whenener i try to access the folders even with admin account it doesnt give permissions. how to i set permissions to everyone again i wrote following script to give permissions to everyone but it doesnt seem to work. 

    Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
    Set objShell= CreateObject("WScript.Shell")
    Set objFolder = objFSO.GetFolder("D:\")
    totalCount =  objFolder.SubFolders.Count
    wscript.echo totalCount 
    strHomeFolder= "D:\Data"
    wscript.echo strHomeFolder
    For Each folder in objFolder.SubFolders
    wscript.echo folder.name
    	If InStr(folder.name, "Data") then	
    	'intRunError= objShell.Run("icacls D:\Data /grant everyone:F")
    	intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls "_
    & myFolder & " /t /c /p everyone:F administrator:F ", 2, "True")
    End If
    	myFolder = "D:\" & folder.name
    	intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls "_
    & myFolder & " /t /c /p everyone:F administrator:F ", 2, "True")
    Next
    '==========================================================================
    
    Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
    Set objShell= CreateObject("WScript.Shell")
    Set objFolder = objFSO.GetFolder("C:\")
    
     
    
    For Each folder in objFolder.SubFolders
    wscript.echo folder.name
    	
    	myFolder = "C:\" & folder.name
    	intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls "_
    & myFolder & " /t /c /p everyone:F administrator:F ", 2, "True")
    Next

    • Moved by Bill_Stewart Sunday, December 29, 2013 2:55 PM Question beyond reasonable forum scope
    Thursday, August 22, 2013 6:04 AM

All replies

  • Wrapping iacls.exe and cacls.exe into a script serves no purpose other than making things much more complicated than they need be. It would be far simpler to execute these commands directly within a console screen.

    The problem of restoring proper folder permissions is not a scripting issue. You need to seize ownership of the folder D:\Data - see here.

    Thursday, August 22, 2013 6:58 AM
  • actually this is the same script I used to lock folders on drives. I used N instead of F in the script.. but now m not able to open the folders even with admin account... I need a solution to revert things back to normal where everyone had access to all the folders in both c and d drive.
    Thursday, August 22, 2013 9:14 AM
  • actually this is the same script I used to lock folders on drives. I used N instead of F in the script.. but now m not able to open the folders even with admin account... I need a solution to revert things back to normal where everyone had access to all the folders in both c and d drive.
    Thursday, August 22, 2013 11:37 AM
  • actually this is the same script I used to lock folders on drives. I used N instead of F in the script.. but now m not able to open the folders even with admin account... I need a solution to revert things back to normal where everyone had access to all the folders in both c and d drive.

    It does not matter what script you use. The fact still is that you are invoking console commands. If you must invoke console commands from within a script then  you must first test them at the Command Prompt.

    Did you check out the link I gave you in my previous reply?

    Thursday, August 22, 2013 4:34 PM