Script to fix issues described in KB947215 (VBScript) 

Introduction 

This sample can help you resolve the issue, “You receive a 'The User Profile Service failed the logon' error message”. This script shows how to list user SID information and delete invalid SID registry keys by using the VBScript. 

Scenario 

When you log on to a Windows 7-based or a Windows Vista-based computer by using a temporary profile, you receive the following error message: The User Profile Service failed the logon. User profile cannot be loaded. 

To resolve this issue, use the script described in this sample to remove the invalid SID registry key. 

Script 

This script contains one function, DeleteInvalidSID. You can use this script in following way: 

Method:

  1. Download the script and copy it to your computer.
  2. Open the script file with Notepad or any other script editors.
  3. Press “Ctrl + End” add the codes which are listed in the Examples section.
  4. Save the file then run the script by using cscript.
    Note: You have to run cscript as administrator.

Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page. 

VB Script
Edit|Remove
    For Each subKey In subKeys 
        '    Check if a “NT AUTHORITY” user SID is specified 
        '    Omit bellow SIDs: 
        '    s-1-5-18 for NT AUTHORITY\SYSTEM 
        '    s-1-5-19 for NT AUTHORITY\LOCAL SERVICE 
        '    s-1-5-20 for NT AUTHORITY\NETWORK SERVICE 
        If subKey <> "S-1-5-18" And subKey <> "S-1-5-19" And subKey <> "S-1-5-20" Then  
            ObjReg.GetExpandedStringValue HKEY_LOCAL_MACHINE, KeyPath & "\" & subKey, ValueName, profileImagePath 
             
            ' If a SID with a invalid profileImagePath, this SID is invalid, and it need to be deleted 
            If Not ObjFSO.FolderExists(profileImagePath) Then 
                ObjReg.DeleteKey HKEY_LOCAL_MACHINE, KeyPath & "\" & subKey 
                WScript.Echo "Invalid SID: [" & subKey & "] was deleted successfully!" 
            End If 
        End If  
    Next

Examples

Example 1 Repair a user account profile by specifying the user SID.
Code: RepairUserAccountProfile (<SID>)
Screenshot:

 

Example 2: Delete all invalid SID registry keys in the computer.
Code:
DeleteInvalidSIDRegKey()
Screenshot:
 

Additional Resources

Technical Resources:

You receive a "The User Profile Service failed the logon” error message