WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Registry

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Update All Open and Not-Open User Profiles

 Keywords: Update All Profiles User Hive RegLoadHive RegUnLoadHive Registry

; UpdateAllProfiles.wbt
; Update all open and not-open user profiles with one or more new registry values
; Les Ferch, June 2010

;------------------------------------------------------------------------------------------------
; Edit this function to set the value(s) you require

#DefineFunction UpdateProfile(UserKey)
ErrMode = ErrorMode(@OFF)
RegSetValue(@REGUSERS,UserKey:"\Control Panel\Desktop[ScreenSaveTimeOut]",1800)
ErrorMode(ErrMode)
#EndFunction

;------------------------------------------------------------------------------------------------
; Main

; Get a list of all open profiles
HKUList = RegQueryKeys(@REGUSERS)
HKUCount = ItemCount(HKUList,@TAB)

; Update all open profiles
For i = 1 To HKUCount
   UserKey = ItemExtract(i,HKUList,@TAB)
   UpdateProfile(UserKey)
Next

; Get list of all profiles on disk
UserProfile = Environment("UserProfile")
ProfDir = StrSub(UserProfile,1,StrIndex(UserProfile,"\",0,@BACKSCAN))
IntControl(5,1,0,0,0) ; Include hidden and system folders
DirChange(ProfDir)
ProfList = DirItemize("*.*")
ProfCount = ItemCount(ProfList,@TAB)
DirChange(DirScript())

; Update all not-open profiles
For i = 1 To ProfCount
   UserKey = ItemExtract(i,ProfList,@TAB)
   ErrMode = ErrorMode(@OFF)
   RegLoadHive(@REGUSERS,UserKey,ProfDir:UserKey:"\NTUSER.DAT")
   ErrorMode(ErrMode)
   If RegExistKey(@REGUSERS,UserKey)
      UpdateProfile(UserKey)
      ErrMode = ErrorMode(@OFF)
      RegUnloadHive(@REGUSERS,UserKey)
      ErrorMode(ErrMode)
   EndIf
Next

Article ID:   W18265
Filename:   Update All Open and Not-Open User Profiles .txt
File Created: 2010:06:11:09:40:48
Last Updated: 2010:06:11:09:40:48