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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resetting home profile permissions for windows 7 and XP users

Status
Not open for further replies.

Mediocer

IS-IT--Management
Apr 6, 2011
8
US
Here is the script that I am using.
It works for me in a testing environment.
Any input or suggestions is helpful.
I am not a programmer by any means, but can Google pretty well =D
We now have windows 7 and our current bat script is not working due to the fact the Vista and 7 tag a .V2 at the end of the folder name. The folder name is the user name (shortname).
Users have roaming profiles, so the script will be running on the server that contains the data.

'********************************************************************************************
' Resetting home profile permissions.
' Modifed by Jeffro with help from Joe S, Keith S, Google and credit to Ric Charlton's post:
' '********************************************************************************************
'
'********************************************************************************************
' Setting the Parameters
'********************************************************************************************
'
Set FSO = CreateObject("Scripting.FileSystemObject")
Set ObjShell = Wscript.CreateObject("Wscript.Shell")
'
'********************************************************************************************
' Set the folder path "(ShowSubfolders FSO.GetFolder("OMG CHANGE ME")
'********************************************************************************************
'
ShowSubfolders FSO.GetFolder("E:\home-profiles")
'
'********************************************************************************************
' Run the sub command to Reset permissions based on home folder name.
' If userName contains a .V2 replace it with "" nothing.
' Added ,,True to wait for each CMD to finish before the next one starts.
'********************************************************************************************
'
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
userName = Replace(SubFolder.Name,".V2","")

CMDLine1 = "takeown /f """ & Subfolder & """ /r /d y"
CMDLine2 = "icacls.exe """ & Subfolder & """ /reset /T"
CMDLine3 = "icacls.exe """ & Subfolder & """ /grant:r ELKRIVER\" & userName & ":(OI)(CI)F"
CMDLine4 = "icacls.exe """ & Subfolder & """ /setowner ELKRIVER\" & userName & " /T"

ObjShell.Run CMDLine1,,True
ObjShell.Run CMDLine2,,True
ObjShell.Run CMDLine3,,True
ObjShell.Run CMDLine4,,True

Next
End Sub
'
'********************************************************************************************
' quit the script
'********************************************************************************************
'
Wscript.quit
 
I am looking for a way to export errors if the user does not exist, i.e. cannot set owner to userName.

Any thoughts?
 
Code:
[green]'set a trap before defining parameters[/green]
on error goto 0

[green]'open an "error log" using your FSO[/green]
set objLog = FSO.OpenTextFile("errors.log", 2, true,0)

[green]'send the error to the log file[/green]
[green]'put this line where ever an error you want to log may occur[/green]
if (Err.Number) then objLog.WriteLine Err.Number & ": " & Err.Description

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top