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

Sample Code from Users

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 Profiles

 Keywords: regSetValue Profile NTUSER.DAT Update  

The code below updates all open and not-open profiles. This example sets the screen saver timeout to 30 minutes. Change the UpdateProfile function to set your desired per-user registry values.
;------------------------------------------------------------------------------------------------
; 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:   W18234
Filename:   Update All Open and Not-open Profiles.txt
File Created: 2010:06:07:14:21:18
Last Updated: 2010:06:07:14:21:18