Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Script: Profile Fixer


  • Please log in to reply
No replies to this topic

#1 jftuga

jftuga

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 335 posts

Posted 21 December 2006 - 04:13 PM

I have also attached the source code, icon, and executable in a rar file. See below.

-John

AutoIt         
#cs ProfileFixer.au3 -John Taylor Dec-21-2006 Every now & then, Windows decides to append the AD domain to a user's profile path.  When the user logs in the next time, his desktop icons are gone and Outlook stops working.  This programs takes a computer name as input, then remotely queries the registry on that system, and finally corrects all of it's user profile entries. icon: <a href='http://www.iconarchive.com/icon/sci-fi/star-wars-1-by-iconfactory/R2D2.ico' class='bbc_url' title='External link' rel='nofollow external'>http://www.iconarchive.com/icon/sci-fi/star-wars-1-by-iconfactory/R2D2.ico</a> #ce Opt("MustDeclareVars",1) Global $title="Profile Fixer" Global $profile_list_key="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" Global $profile_value="ProfileImagePath" Global $profile_list[128] ; display error when a registry read/write problem occurs func reg_error($i)     local $msg     Select         case $i = 1               $msg="unable to open requested key"         case $i = 2               $msg="unable to open requested main key"         case $i = 3               $msg="unable to remote connect to the registry"         case $i = -1             $msg="unable to open requested value"         case $i = -2             $msg="return value type not supported"         case else             $msg="unknown error value: " & $i     EndSelect     MsgBox(0,"Registry Error", $msg) endfunc ; build a list of all of the profiles on the given machine func get_profile_list($h)     local $i, $var, $ev     for $i = 1 to 128         $var = RegEnumKey("\\" & $h & "\" & $profile_list_key, $i)         $ev = @error         if StringLeft($var,2) <> "S-" then ExitLoop         if $ev <> 0 then             reg_error($ev)         else             $profile_list[$i] = $var         endif     next     $i -= 1     $profile_list[0] = $i     return $i endfunc ; search the ProfileImagePath reg entry for a trailing .DOMAIN ; if found, this entry is corrupted and the .DOMAIN will be ; summarily truncated off the end of this registry entry func fix_corrupted($h,$dn)     local $i, $var, $var2, $propath, $dn_len, $fixed, $ev, $ev2     local $err_count=0     $dn = "." & $dn     $dn_len = StringLen($dn)     ; iterate through each user entry and search for a corrupt registry value     for $i = 1 to $profile_list[0]         $propath = "\\" & $h & "\" & $profile_list_key & "\" & $profile_list[$i]         $var = RegRead($propath, $profile_value)         $ev = @error         if $ev <> 0 then             reg_error($ev)         else             if StringRight($var, $dn_len) == $dn then                 $err_count += 1                 ; write fixed data back to registry                 $fixed = StringTrimRight($var,$dn_len)                 $var2 = RegWrite($propath, $profile_value, "REG_EXPAND_SZ", $fixed)                 $ev2 = @error                 MsgBox(0,"Corrupt entry found on " & $h, $propath & @CRLF & @CRLF & "Current value: " & $var & @CRLF & "    Fixed value: " & $fixed & @CRLF & @CRLF & "Registry Write Status: " & $var2)                 if $ev2 <> 0 then                     reg_error($ev2)                 endif             endif         endif     next     return $err_count endfunc ; ; Program's Main Execution begins here ; Dim $h = "" Dim $ev Dim $total_count = 0 Dim $fixed_count = 0 $h = InputBox( $title, "Enter Computer Name (ex: PC8725) ", "", "") $ev = @error if $ev > 0 then     exit endif if StringLen($h) < 2 then     exit endif     $total_count = get_profile_list($h) $fixed_count = fix_corrupted($h, @LogonDomain ) MsgBox(0,$h,"Number of profiles: " & $total_count & @CRLF & "Number corrected: " & $fixed_count)

Attached Files


Edited by jftuga, 21 December 2006 - 07:21 PM.











0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users