Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript to change file permissions

Status
Not open for further replies.

srantheman

IS-IT--Management
Apr 14, 2010
2
US
Hello, we are currently going through a mail upgrade in the school district. One of the steps involved is to save everybody's current mailbox to the server as a .pst file. We are trying to use calcs.exe to change each file so that only us and the user has access to that file. I have used calcs to change folder permsissions but never on a single file. Below is a script that I have written and it runs fine but does not change the permissions on the individual file. Anybody got any suggestions.

Dim fso, folder, files, NewsFile,sFolder, oShell, sSysDir
dim WshNetwork
Dim FoldPerm1, Calcds, oFSO
sFolder = "c:\PST"
Set fso = CreateObject("Scripting.FileSystemObject")
set WshNetwork = CreateObject("Wscript.Network")
set oShell = CreateObject("Wscript.Shell")
Set NewFile = fso.CreateTextFile("c:\PST\FileList.txt", True)
Set folder = fso.GetFolder(sFolder)
Set files = folder.Files

For each folderIdx In files
NewFile.WriteLine(folderIdx.Name)
Next
NewFile.Close

Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim MyFile, FileName, TextLine



' Open the file for output.
FileName = "c:\PST\FileList.txt"

' Open the file for input.
Set MyFile = fso_OpenTextFile(FileName, ForReading)

' Read from the file and display the results.
sSysDir = fso.GetSpecialFolder(1).path
If Right(sSysDir,1) <> "\" Then sSysDir = sSysDir & "\"
Calcds = sSysDir & "cacls.exe"

Do While MyFile.AtEndOfStream <> True
TextLine = MyFile.ReadLine
TextLine = UCase(TextLine)
Username= Replace(TextLine, ".PST", "")
FoldPerm1 = """" & Calcds &"""" & """C:\PST\""" & TextLine & " /E /T /C /G " & """Username""" & ":C"
oShell.Run FoldPerm1, 1 ,True
Wscript.Sleep 1000
Loop

MyFile.Close
fso.DeleteFile "C:\PST\FileList.txt
 
> FoldPerm1 = """" & Calcds &"""" & """C:\PST\""" & TextLine & " /E /T /C /G " & """Username""" & ":C"
[tt] FoldPerm1 = """" & Calcds & """" [red]& " "[/red] & """C:\PST\[highlight]"[/highlight] & TextLine [red] & """"[/red] & " /E /T /C /G " & """[red]" &[/red] Username[red] & """"[/red] & ":C"[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top