Sign in to follow this  
Followers 0

Script: Profile Fixer

1 post in this topic

#1 ·  Posted (edited)

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

-John

#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:
http://www.iconarchive.com/icon/sci-fi/star-wars-1-by-iconfactory/R2D2.ico

#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)

ProfileFixer.rar

Edited by jftuga

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0