From: Will Platnick on 5 Jan 2007 09:10 I've been scouring the Internet all morning trying to find an answer to this question. It seems to have been asked several times, but there's never been a response with any solution: We have a custom system setup that creates user profiles on the fly, giving them access to specific icons and what not. When a user logs off, the local profile is not deleted and stays on the machine. We want to delete all non-administrator profiles on startup. I know I can use delprof.exe to delete all profiles, but we need to keep the profiles of our administrators (all admin IDs begin with the same character sequence). How can we accomplish this?
From: MMO001 on 5 Jan 2007 09:47 Hi Will, You can do this by a script, We did it in a winbatch script but vbs is also possible. Greetings, Marcel Moreels ;============================================================================== ;= FILE : ProfileCleanUp.wbt ;= DATE : 4 januari 2007 ;= PURPOSE : Opschonen Lokale UserProfiel Directories op Citrix server ;= AUTHOR : F.Huitenga/MMoreels ;= VERSION : 1.0 ;= COMPILER : Winbatch 2002k + extra extender dll's ;= NOTES : ;= WORKS ON OS/SP : Win2003 ;= TEMPLATEVERSION : 1.0 ;= OPDRACHT : In opdracht specialisme imaging. ;============================================================================== ;* Running WinBatch without showing WinBatch icon AddExtender ("wwsop34i.DLL") IntControl(1002, 0, 0, 0, 0) ErrorMode(@Off) ; Functies declareren GoSub DeclareFunctions WindowsSystemDir = DirWindows(1) ;; Definieeren van bestandslocaties PROFILESDIRECTORY = aShellFolder (22, 0) ; Profile folder) PROFILESDIRECTORY = StrReplace (PROFILESDIRECTORY, "\All Users\Start Menu", "") CurrComp = environment("COMPUTERNAME") CurrUser = environment("USERNAME") LogDir = StrCat (DirHome(), "Log\", CurrComp) ;LogDir = StrCat (DirWindows(0), "Debug\Log\", CurrComp) LogFile = strcat(LogDir, "\", "Opschonen_gebruiker", ".log") ; // Aanmaken logdirectory en verwijderen log bestand If !DirExist(LogDir) Then DirMake(LogDir) If FileExist(LogFile) Then FileDelete(LogFile) WriteLog(";====================================================================", LogFile) WriteLog(StrCat("Environment -> Huidige computernaam : ", CurrComp), LogFile) WriteLog(StrCat("Environment -> Huidige gebruiker : ", CurrUser), LogFile) ;============================================================================== ; Start script ;============================================================================== WriteLog("Start Cleaning Profiles", LogFile) ; Build list of profiledirectories not to be cleaned nogolist = "" nogolist = strcat(nogolist, StrCat(WindowsSystemDir, "config\systemprofile")) nogolist = strcat(nogolist,@TAB) nogolist = strcat(nogolist, StrCat(PROFILESDIRECTORY, "\LocalService")) nogolist = strcat(nogolist,@TAB) nogolist = strcat(nogolist, StrCat(PROFILESDIRECTORY, "\NetworkService")) nogolist = strcat(nogolist,@TAB) nogolist = strcat(nogolist, StrCat(PROFILESDIRECTORY, "\Administrator")) nogolist = strcat(nogolist,@TAB) nogolist = strcat(nogolist, StrCat(PROFILESDIRECTORY, "\Default User")) nogolist = strcat(nogolist,@TAB) nogolist = strcat(nogolist, StrCat(PROFILESDIRECTORY, "\All Users")) nogolist = strcat(nogolist,@TAB) nogolist = strcat(nogolist, StrCat(PROFILESDIRECTORY, "\admin#prod4UWV")) nogolist = strcat(nogolist,@TAB) nogolist = strcat(nogolist, StrCat(PROFILESDIRECTORY, "\Ctx_SmaUser")) nogolist = strcat(nogolist,@TAB) ; En de huidige gebruiker uitsluiten van profiel schoning !! nogolist = strcat(nogolist, StrCat(PROFILESDIRECTORY, "\", CurrUser)) nogolist = strcat(nogolist,@TAB) nogolist = strupper(nogolist) ; Getting al the profilepaths from the registry regkey = RegOpenKey(@REGMACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList") For x=0 to 999 a=RegQueryKey(regkey, x) If a=="" then break result = "SUCCES" UserKey = strcat("SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList","\" ,a,"\[ProfileImagePath]") userprofilepath=StrUpper(RegQueryStr(@RegMachine, userkey)) ; check to see if userprofilepath is in nogolist index=ItemLocate(StrUpper(userprofilepath), nogolist, @TAB) ; If profilepath is not in nogolist we can clean the userprofilepath if index == 0 then WriteLog(StrCat("Cleaning Profile: ", userprofilepath), LogFile) result = SHDeleteDir(userprofilepath) if result <> "FAILED" then UserReg = StrCat("SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\", a) r = RegDeleteKey( @REGMACHINE , UserReg) ; Loggen van register schoning If r == @True Then WriteLog(StrCat("Deleting register entry ", UserReg), LogFile) If r == @False Then WriteLog(StrCat("Deleting register entry ", UserReg), LogFile) Drop (r, UserReg) if x <> 0 then x = x - 1 else x = 0 endif else WriteLog(StrCat("ERROR : Failed deleting directory ", userprofilepath), LogFile) endif else WriteLog(StrCat("Profile skipped: ", userprofilepath), LogFile) endif next RegClosekey(regkey) WriteLog("Finished Cleaning Profiles", LogFile) WriteLog(";====================================================================", LogFile) exit :DeclareFunctions ;============================================================================== ; Samenstellen UDF's (UserDefined Functions) ;============================================================================== ;============================================================================== #DefineFunction SHEmptyDir(dir) ;Deletes everything under the source directory, but leaves the directory itself. src = StrCat(dir, "*.*") flags = 1024 Errormode(@OFF) If DirExist(dir) then afiledelete(src,flags) EndIf ErrorMode(@CANCEL) #EndFunction ;============================================================================== ;============================================================================== #DefineFunction SHDeleteDir(dir) ;Deletes source directory and all of it's contents. src = dir flags = 1024 result = "FAILED" Count = 0 ; Errormode(@OFF) If DirExist(src) then While result == "FAILED" r = afiledelete(src,flags) If r == @True then result = "SUCCES" Else Count = Count + 1 If Count == 3 then result = "FAILED" Break EndIf EndIf EndWhile Else result = "SUCCES" Endif ErrorMode(@CANCEL) return(result) #EndFunction ;============================================================================== ;============================================================================== #DefineFunction WriteLog(Text, LogFile) If !FileExist(LogFile) Then handle = FileOpen(LogFile, "WRITE") Else handle = FileOpen(LogFile, "APPEND") EndIf curdate = TimeDate() Logtext = strcat(curdate," - ", Text) FileWrite(handle, Logtext) FileClose(handle) #EndFunction ;============================================================================== Return "Will Platnick" wrote: > I've been scouring the Internet all morning trying to find an answer to > this question. It seems to have been asked several times, but there's > never been a response with any solution: > > We have a custom system setup that creates user profiles on the fly, > giving them access to specific icons and what not. When a user logs > off, the local profile is not deleted and stays on the machine. > > We want to delete all non-administrator profiles on startup. I know I > can use delprof.exe to delete all profiles, but we need to keep the > profiles of our administrators (all admin IDs begin with the same > character sequence). > > How can we accomplish this? > >
|
Pages: 1 Prev: Windows 2003 is crashing not regurally Next: dcpromo fails |