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
( #1 )
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 ! :)
|
|
|
dm_4ever
-
Total Posts
:
3613
- Scores: 78
-
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
( #2 )
Man....talk about a frequently asked question..... "%COMSPEC% /c Echo Y| cacls " _ & Chr(34) & strDirectory & Chr(34) & " /c /e /g ""LocalAccess"":F "
|
|
|
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
( #3 )
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!
|
|
|
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.