mbt masai
 
Welcome !
         

                                
After experiencing a lot of down time, We decided to move this site to CrystalTech.com. CrystalTech.com is powered by only the finest Windows servers providing the best performance, reliability, and value anywhere.

 Create Folder and set permissions via script

Author Message
r0b3rd

  • Total Posts : 1
  • Scores: 0
  • Reward points : 0
  • Joined: 2/11/2008
  • Status: offline
Create Folder and set permissions via script Monday, February 11, 2008 1:43 PM (permalink)
0
hello,
 
I'm trying to create a folder on a local workstation and set permissions of this folder. This is my script:
 
Option Explicit
Dim objFSO, objFolder, objShell, strDirectory, intRunError, strUser
strDirectory = "c:\test test"

' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Note If..Exists. Then, Else ... End If construction
If objFSO.FolderExists(strDirectory) Then
   Set objFolder = objFSO.GetFolder(strDirectory)
   WScript.Echo strDirectory & " already created "
Else
   Set objFolder = objFSO.CreateFolder(strDirectory)
WScript.Echo "Just created " & strDirectory
End If

If err.number = vbEmpty then
   Set objShell = CreateObject("WScript.Shell")
   objShell.run ("Explorer" &" " & strDirectory & "\" )
Else WScript.echo "VBScript Error: " & err.number
End If


If objFSO.FolderExists(strDirectory) Then
' Assign user permission to folder.
   intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " _
   & strDirectory & " /c /e /g ""LocalAccess"":F ", 2, True)
   If intRunError <> 0 Then
      Wscript.Echo "Error assigning permissions to folder " & strDirectory
   End If
End If


WScript.Quit
 
 
the script works fine if the folder name doesn't contain any spaces. But i want the script to create a folder in 'Program Files'. The folder creation works fine; the problem is setting the permission. Does anybody know what i am doing wrong here?
 
THNX ! :)
 
#1
    dm_4ever

    • Total Posts : 3673
    • Scores: 82
    • Reward points : 0
    • Joined: 6/29/2006
    • Location: Orange County, California
    • Status: offline
    RE: Create Folder and set permissions via script Monday, February 11, 2008 2:29 PM (permalink)
    0
    Man....talk about a frequently asked question.....

    "%COMSPEC% /c Echo Y| cacls " _
      & Chr(34) & strDirectory & Chr(34) & " /c /e /g ""LocalAccess"":F "
    dm_4ever

    My philosophy: K.I.S.S - Keep It Simple Stupid
    Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
    Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
    #2
      fbords

      • Total Posts : 4
      • Scores: 0
      • Reward points : 0
      • Joined: 7/23/2008
      • Status: offline
      RE: Create Folder and set permissions via script Wednesday, July 23, 2008 9:37 AM (permalink)
      0
      I'm using a very similar script customized for my needs. The permissions appear to set correctly, however, the intRunError portion keeps displaying it's error. Do you have any idea why? I posted my code here:
      http://www.visualbasicscript.com/m_62640/tm.htm

      thanks!
      #3

        Online Bookmarks Sharing: Share/Bookmark

        Jump to:

        Current active users

        There are 0 members and 1 guests.

        Icon Legend and Permission

        • New Messages
        • No New Messages
        • Hot Topic w/ New Messages
        • Hot Topic w/o New Messages
        • Locked w/ New Messages
        • Locked w/o New Messages
        • Read Message
        • Post New Thread
        • Reply to message
        • Post New Poll
        • Submit Vote
        • Post reward post
        • Delete my own posts
        • Delete my own threads
        • Rate post

        2000-2012 ASPPlayground.NET Forum Version 3.8
        mbt shoes www.wileywilson.com