BAC Software Consulting Blog

How To Fix ‘Failed to Connect to a Windows Service’ Error

How To Fix ‘Failed to Connect to a Windows Service’ Error

Are you running Windows Vista/7 operating system on your computer? Have you ever had the problem where the desktop is black, the trash bin is the only item on the desktop and a message appearing at the corner of your screen saying:
“Failed to connect to a Windows service: Windows could not connect to the User Profile Service service. This problem prevents limited users from logging on to the system. As an administrator user, you can review the System Event Log for details about why the service didn´t respond.”

This Failed to Connect to a Windows Service Error, happened to me couple of weeks ago, and it took me full 4 days to recover. After extensive online searches and trying many suggested solutions and tricks, nothing worked for me, until I found my own solution which I want to share with you.

If you don´t know what I am talking about! That´s great. But continue reading anyway, you´ll never know if/when this happens to you.

What is the Root Cause of The Failed to Connect to a Windows Service Error?

Frankly, I could not figure out what caused this Error. I usually put my computer on Hibernate mode and I tend not to shutdown my computer often. That´s why it was hard to pinpoint the exact cause. But it seems that there are many scenarios that could cause this error on windows Vista and Windows 7 operating systems. It could be any of the following:

  1. The computer got infected by a virus or a worm.
  2. Your registry cleaner tool, if you use one, deleted some important registry values.
  3. A third-party software installation or update.
  4. Antivirus or other security software, either an update or a new installation.
  5. Believe it or not, Microsoft Windows updates.
  6. Installation of a new driver, or a driver update.
  7. And probably other reasons.

My Solution To Fix the Failed to Connect to a Windows Service Error

In my case, The Failed to Connect to a Windows Service happened after I restarted my computer. This error affects only the User Profile Service and the Themes services.

But I found a reasonable solution for the User Profile Service and Themes services not starting. This solution does not address the root cause of the problem. But it works very nicely for me, and I thought I will share it with you. Here is what you need to do:

  1. Create a NEW User Account with Administrative privileges. {Check Appx3 below for detailed instructions.}
  2. Restart your computer with your NEW User Account.
  3. Manually restart the User Profile Service. {Check Appx1 below for detailed instructions.}
  4. LogOff your computer, (DO NOT RESTART YOUR COMPUTER).
  5. Log back On with your ´Original´ User Account (NOT the NEW User Account that you just created)
  6. You should be able to get your User Profile back as you always had it since it already started.

If you notice that your Windows Theme, is different and it looks like ´Windows Classic´ theme. Do the following:

  1. Probably your Themes service did not start. Manually restart the Themes service. {Check Appx6 below for detailed instructions.}
  2. Then Personalize Your Computer. {Check Appx7 below for detailed instructions.}

Keep, in mind every time I shutdown the computer I have to redo the steps above. But they are very simple and they don´t bother me at all.

Notes:

  1. Update (Nov. 7, 2011): Sometimes when you restart the computer, and you get the Black screen and the User Profile Service not starting. All you have to do is: Manually restart the User Profile Service (toggle it Stop/Restart if you have to), then LogOff and Log back On to your computer with the same User Account that you logged-in with. Thus bypassing the NEW User Account method that I discussed above. This is even simpler method than creating a NEW User Account, and it also works perfectly for me.
  2. In my case, when I run my computer in safe mode my user profile is not corrupted. With this info in mind, I am still not able to pinpoint the root cause.
  3. Why is it possible that the root cause is some Windows updates. Because windows update can change how long some services take to get up and running, and thus windows Operating system does not or cannot wait for these services to start. A computer restart will simply reproduces the problem. What is required is a LogOff/LogOn. This gave the services time enough to start up. A Permanent solution, would be to uninstall recent updates, by doing system restore.
  4. In my case, a system restore did not work for me, even though I went at least two weeks earlier.
  5. I tried Starting up the computer with, Using Last Known Good Configuration, but it didn´t fix the problem either.
  6. I tried many other possible fixes, which need another post on their own, with no results.

Other Possible Solutions-1

This is quoted from the Microsoft Answers. It might provide other possible solutions to the Failed to Connect to a Windows Service – Windows could not connect to the User Profile Service error and might be a permanent fix that addresses the root cause.

Could not connect to the User Profile Service

Question:

I can not log into Windows properly. When I boot up and select my user account (also the sole administrator account, it spends an abnormally long time in the “Starting” screen, then I get the following message pop up from the notification area:
Failed to connect to a windows service. Windows could not connect to the User Profile Service service. This problem prevents limited users from logging on to the system. As an administrative user, you can review…

This all appears on just a black desktop with only the Recycle bin icon on it, and the classic Windows Start button. What´s the solution here?

Answer1:

It sounds like you are up and running only because of using a system restore to go back to when your system is working. Now you want to know what caused it. Usually, when the above error occurs, it is because of a corrupt user profile. The best way to correct this issue is to delete the user profile.

  1. Go to Start button .
  2. Right click on Computer.
  3. Go to Properties.
  4. Go to Advanced System Properties on the left pane.
  5. Select the Advanced Tab.
  6. Go to the User Profile Section and click on Settings button
  7. Find the profile for the <USER NAME> you want to delete and select the delete button. (This is the preferred way of deleting the local profile in Windows Vista).
  8. Login again and you will get a new profile.
  9. To get your favorites back, go to the old profile under C:\users and copy over the data manually.

The only way to pinpoint what caused the error with user profile; is to try and reproduce it. If you haven´t installed the Windows Update, then you can go to Windows Updates and see what updates are to be installed and download them manually and install them one at a time. In between the installs, make sure you have a restore point that you can go back to if needed. Once an update is installed, then log off and log back (or reboot if needed by the update) and see if you get the user profile error. If the error occurs, then go to Services and see if the User Profile service is running and set to Automatic.

If you are not able to do anything when the problem occurs, then try to boot in safe mode by using the F8 key and see if the problem happens in safe mode.

You can also look in the event viewer to see if there is any events dealing with User Profile or Windows Update errors. To get to event viewer, you can type in eventvwr.msc from the Start Search box. This will bring up the Event Viewer and you can review the summary logs and see what types of errors you are experiencing.

Answer2:

We would like you to answer a few questions to help better troubleshoot the issue you are having.

  1. Do you know of any software installs or system changes that took place when it started happening?
  2. Are you using any type of third party antivirus or security applications? If so, try disabling them temporarily and see if you have the same issue.

Also, do you have another User account you can test with to see if you have the same issue? If not, follow the instructions below to create a new User account and see what kind of results you get.

  1. Click the Start Button, and then click Control Panel.
  2. Click Classic View in left panel.
  3. Double-click User Accounts.
  4. Click Manage another user account.
  5. Click Create a new account, and type the name (whatever you want for a name)
  6. Choose account type as Computer administrator.
  7. Click Create Account.
  8. Log Off and log On with the NEW account.

Test with the new User account and let us know the results.

Other Possible Solutions-2

This is also quoted from the Windows Answers. It might provide more solutions to the Failed to connect to a Windows Service – Windows could not connect to the User Profile Service error and might be a permanent fix that addresses the root cause.

Failed to connect to a windows service – Windows could not connect to the User Profile Service.

Question:

When I restarted my computer, my theme is set back to Windows classic and the only thing on my desktop is the recycling. The background was blue I believe. I look at my task bar in the bottom right and a message comes up, saying: “Failed to connect to a windows service – Windows could not connect to the User Profile Service service. This problem prevents limited users from logging onto the system. As an administrative user, you can review the System Event Log for details about why the service didn´t respond.”

I looked up the error messages on google and fixed my desktop back to normal after a few reboots. But my theme still won´t go back to Vista and half the time my desktop is different than normal. I ran a Malware Bytes scan and removed a Trojan.Fraudpack and a Rogue.Antivirus. So then I try a reboot but the problem still persists. Sometimes when i log on the desktop has bigger icons and my settings are different and other times it works just like normal and all my settings are correct. I think it´s just not recognizing my user Account.

I viewed the System Event Log and found quite a few errors. The user profile service error was in there. It says the problem was: “The service didn´t respond to the start or control request in a timely fashion.” Anyone know how to fix this?

Answer:

Do you remember making any software/hardware changes after which the issue started? Try the steps below and check if it helps.

Step 1: Check if the issue persists in Safe Mode. If the issue doesn´t persists in safe mode the try a clean boot troubleshooting.

Start your computer in safe mode

Step 2: Place the computer in a clean boot state and troubleshoot the issue.

How to troubleshoot a problem by performing a clean boot in Windows Vista or in Windows 7

(Perform a clean boot)

If your issue is resolved after performing Clean Boot, then follow the steps mentioned in the following 929135-KB article to narrow down the exact source.

Also, see the section on how return your computer to a Normal startup mode by following the steps under “Reset the computer to start as usual”, after performing the clean boot troubleshooting.

Step 3: Create a new user account and check if it helps.

Appx1: How To Manually Start the User Profile Service in Windows Vista

A Windows service is a long-running executable that performs specific functions and is designed not to require user intervention. Windows services can be configured to start when the operating system is booted and run in the background as long as Windows is running, or they can be started manually when required. You must have administrator privileges to gain full functionality in the Services console.

The User Profile Service is responsible for loading and unloading user profiles. If the service is stopped or disabled, users will no longer be able to successfully LogOn or LogOff, applications may have problem getting to users´ data and components registered to receive profile event notifications will not receive them.

If the User Profile Service did not start, here is how to manually restart it. The steps for Windows 7 are the same or very similar.

  1. Click the Start Button , type services.msc at the search box to open the Services Console.
  2. Scroll all the way down, and click on the User Profile Service to open the dialog box.
  3. In the General tab make sure the the Startup type is set to Automatic. Also in the Service status: click the Start button then press OK. Note that even if the Service status: is displaying “Started”, you could click Stop button and then Start button and then press OK.

Appx2: How To Fix a Corrupted User Profile {Windows Vista/7}

Depending on you Operating System, follow the instructions in the references below.

Appx3: How To Create a User Account {Windows Vista/7}

User accounts make it so that several people can share a single computer. Each person can have a separate user account with unique settings and preferences. User accounts also control the files and programs you can access and what types of changes you can make to the computer.

Appx4: How To Start your Computer in Safe Mode {Windows Vista/7}

Safe mode is a troubleshooting option for Windows that starts your computer in a limited state. Only the basic files and drivers necessary to run Windows are started. The words “Safe Mode” appear in the corners of the display to identify which Windows mode you are using.

Appx5: How To Open Event Viewer {Windows Vista/7}

Event Viewer is an advanced tool that displays detailed information about significant events on your computer. It can be helpful when troubleshooting problems and errors with Windows and other programs.

Appx6: How To Manually Start the Themes Service {Windows Vista/7}

The Themes service provides user experience theme management. A Theme is a collection of visual elements and sounds for your computer desktop such as: appearance of menus, icons, wallpapers, screen savers, fonts, some computer sounds, mouse pointers, etc.

You must have administrator privileges to gain full functionality in the Services Console.

If you suspect that the Themes service did not start, here is how you manually restart it.

  • Scroll all the way down, and click on the Themes to open the dialog box.
  • In the General tab make sure the Startup type is set to Automatic. Also in the Service status: click the Start button then press OK. Note that even if the Service status: is displaying “Started”, you could click Stop button and then Start button and then press OK.
  • Appx7: How To Personalize Your Computer {Windows Vista/7}

    If your Windows theme looks unfamiliar to you, or is set back to windows classic theme, and you want to change it, here is what you need to do:

    Open Appearance Settings by clicking the Start button, clicking Control Panel, clicking Appearance and Personalization, clicking Personalization, and clicking Theme to open the Theme Settings dialog box. Under Theme, select the theme you want, and then click OK.

    Note: if you don´t see your theme as part of the Theme list, make sure that your Themes service has started first. Do Appx6 above, and then come back to this section.

    Conclusion

    I know that my solution to the Failed to Connect to a Windows Service – Windows could not connect to the User Profile Service Error is temporary and deals only with the symptom and not the root cause, but at least this solution works perfectly for me and gets my computer up and running every time and with very little effort. So If you ever have this problem and could not find a permanent fix, try my solution.

    How To Add WordPress Breadcrumbs Without a Plugin

    How To Add WordPress Breadcrumbs Without a Plugin

    Breadcrumbs or breadcrumb trail is a navigation aid used in a Website. It gives users a way to keep track of their locations within the Website. Breadcrumbs typically appear horizontally at the top of a Web page. Breadcrumbs provide a trail for the user to follow back to the starting or entry point.

    Breadcrumb trail is an important supplementary element of a Website´s navigation, especially for complex Websites. It improves usability, enhances user experience and it is better for SEO. Don´t take my word for it, Google recommends using Breadcrumbs in their SEO starter guide. Also Google is integrating breadcrumbs navigation within the Search Engine Results Pages.

    Breadcrumbs are especially useful for complex Websites containing many pages and sub-pages, and organized into many categories. On the other hand, breadcrumbs for simple Websites are not really necessary.

    The picture below shows examples of breadcrumb trails generated from this blog. This blog is using the breadcrumb code shown below, browse the various sections of this blog and see how it behaves.

    There is one disadvantage of using breadcrumbs, it increases the number of query requests to your database, and thus a slighter increase in load time. However, this could be neutralized with a caching mechanism implemented to your Website. Again, haven´t you read my previous post about the advantages of caching a dynamic Webiste? I believe that the benefits of breadcrumbs: better user experience, and making the Website friendlier for Search Engines, far outweighs its one disadvantage. Breadcrumb navigation is important for usability and for SEO, especially for complex Websites.

    My Breadcrumbs Code: Supported Features

    The code below display breadcrumb trail for:

    1. Single post listed in one category.
    2. Single post listed in multiple categories that are at the same level.
    3. Category and sub-category archives.
    4. Tag archive.
    5. Yearly archive.
    6. Monthly archive.
    7. Daily archive.
    8. Author archive.
    9. Search result page.
    10. Top-level pages (top-level menu).
    11. Multi-level sub-pages (multi-level sub-menus).
    12. 404 Not found Error page.

    The code below also features:

    1. Complete or shortened post titles.
    2. Two custom delimiters. Same level categories use a different delimiter.

    Also the code below works in both cases when:

    1. Your Website´s Front page displays your latest posts.
    2. Your Website´s Front page displays a static page and your posts are located somewhere else.

    To better explain: the default WordPress settings is shown below. If you choose the other option: “Front page displays -> a static page (select below)”, the breadcrumb code still works.

    My Breadcrumbs Code: NOT Supported Features

    The code below does not support:

    1. Adding a page number at the end of the trail.
    2. Attachments.
    3. Custom post types.
    4. Custom taxonomies.
    5. A single post listed in a top category AND in a subcategory (or subcategories). An unlikely case, where you get a mix up of delimiters.

    WordPress Breadcrumbs Function Code

    This is my version of the WordPress breadcrumbs code. Open the functions.php file located in your theme´s folder and add (copy and paste) the following function. Sorry for the long code, but I commented it so you understand better what´s going on.

    Note: To scroll within the code: You can also click on the code window and use your keyboard´s arrow keys.

    CODE-1:

    <?php
    function wp_bac_breadcrumb() {   
        //Variable (symbol >> encoded) and can be styled separately.
        //Use >> for different level categories (parent >> child >> grandchild)
                $delimiter = '<span class="delimiter"> &raquo; </span>'; 
        //Use bullets for same level categories ( parent . parent )
        $delimiter1 = '<span class="delimiter1"> &bull; </span>';
         
        //text link for the 'Home' page
                $main = 'Home';  
        //Display only the first 30 characters of the post title.
                $maxLength= 30;
         
        //variable for archived year 
        $arc_year = get_the_time('Y'); 
        //variable for archived month 
        $arc_month = get_the_time('F'); 
        //variables for archived day number + full
        $arc_day = get_the_time('d');
        $arc_day_full = get_the_time('l');  
         
        //variable for the URL for the Year
        $url_year = get_year_link($arc_year);
        //variable for the URL for the Month    
        $url_month = get_month_link($arc_year,$arc_month);
     
        /*is_front_page(): If the front of the site is displayed, whether it is posts or a Page. This is true 
        when the main blog page is being displayed and the 'Settings > Reading ->Front page displays' 
        is set to "Your latest posts", or when 'Settings > Reading ->Front page displays' is set to 
        "A static page" and the "Front Page" value is the current Page being displayed. In this case 
        no need to add breadcrumb navigation. is_home() is a subset of is_front_page() */
         
        //Check if NOT the front page (whether your latest posts or a static page) is displayed. Then add breadcrumb trail.
        if (!is_front_page()) {         
            //If Breadcrump exists, wrap it up in a div container for styling. 
            //You need to define the breadcrumb class in CSS file.
            echo '<div class="breadcrumb">';
             
            //global WordPress variable $post. Needed to display multi-page navigations. 
            global $post, $cat;         
            //A safe way of getting values for a named option from the options database table. 
            $homeLink = get_option('home'); //same as: $homeLink = get_bloginfo('url');
            //If you don't like "You are here:", just remove it.
            echo 'You are here: <a href="' . $homeLink . '">' . $main . '</a>' . $delimiter;    
             
            //Display breadcrumb for single post
            if (is_single()) { //check if any single post is being displayed.           
                //Returns an array of objects, one object for each category assigned to the post.
                //This code does not work well (wrong delimiters) if a single post is listed 
                //at the same time in a top category AND in a sub-category. But this is highly unlikely.
                $category = get_the_category();
                $num_cat = count($category); //counts the number of categories the post is listed in.
                 
                //If you have a single post assigned to one category.
                //If you don't set a post to a category, WordPress will assign it a default category.
                if ($num_cat <=1)  //I put less or equal than 1 just in case the variable is not set (a catch all).
                {
                    echo get_category_parents($category[0],  true,' ' . $delimiter . ' ');
                    //Display the full post title.
                    echo ' ' . get_the_title(); 
                }
                //then the post is listed in more than 1 category.  
                else { 
                    //Put bullets between categories, since they are at the same level in the hierarchy.
                    echo the_category( $delimiter1, multiple); 
                        //Display partial post title, in order to save space.
                        if (strlen(get_the_title()) >= $maxLength) { //If the title is long, then don't display it all.
                            echo ' ' . $delimiter . trim(substr(get_the_title(), 0, $maxLength)) . ' ...';
                        }                         
                        else { //the title is short, display all post title.
                            echo ' ' . $delimiter . get_the_title(); 
                        } 
                }           
            } 
            //Display breadcrumb for category and sub-category archive
            elseif (is_category()) { //Check if Category archive page is being displayed.
                //returns the category title for the current page. 
                //If it is a subcategory, it will display the full path to the subcategory. 
                //Returns the parent categories of the current category with links separated by '»'
                echo 'Archive Category: "' . get_category_parents($cat, true,' ' . $delimiter . ' ') . '"' ;
            }       
            //Display breadcrumb for tag archive        
            elseif ( is_tag() ) { //Check if a Tag archive page is being displayed.
                //returns the current tag title for the current page. 
                echo 'Posts Tagged: "' . single_tag_title("", false) . '"';
            }        
            //Display breadcrumb for calendar (day, month, year) archive
            elseif ( is_day()) { //Check if the page is a date (day) based archive page.
                echo '<a href="' . $url_year . '">' . $arc_year . '</a> ' . $delimiter . ' ';
                echo '<a href="' . $url_month . '">' . $arc_month . '</a> ' . $delimiter . $arc_day . ' (' . $arc_day_full . ')';
            } 
            elseif ( is_month() ) {  //Check if the page is a date (month) based archive page.
                echo '<a href="' . $url_year . '">' . $arc_year . '</a> ' . $delimiter . $arc_month;
            } 
            elseif ( is_year() ) {  //Check if the page is a date (year) based archive page.
                echo $arc_year;
            }       
            //Display breadcrumb for search result page
            elseif ( is_search() ) {  //Check if search result page archive is being displayed. 
                echo 'Search Results for: "' . get_search_query() . '"';
            }       
            //Display breadcrumb for top-level pages (top-level menu)
            elseif ( is_page() && !$post->post_parent ) { //Check if this is a top Level page being displayed.
                echo get_the_title();
            }           
            //Display breadcrumb trail for multi-level subpages (multi-level submenus)
            elseif ( is_page() && $post->post_parent ) {  //Check if this is a subpage (submenu) being displayed.
                //get the ancestor of the current page/post_id, with the numeric ID 
                //of the current post as the argument. 
                //get_post_ancestors() returns an indexed array containing the list of all the parent categories.                
                $post_array = get_post_ancestors($post);
                 
                //Sorts in descending order by key, since the array is from top category to bottom.
                krsort($post_array); 
                 
                //Loop through every post id which we pass as an argument to the get_post() function. 
                //$post_ids contains a lot of info about the post, but we only need the title. 
                foreach($post_array as $key=>$postid){
                    //returns the object $post_ids
                    $post_ids = get_post($postid);
                    //returns the name of the currently created objects 
                    $title = $post_ids->post_title; 
                    //Create the permalink of $post_ids
                    echo '<a href="' . get_permalink($post_ids) . '">' . $title . '</a>' . $delimiter;
                }
                the_title(); //returns the title of the current page.               
            }           
            //Display breadcrumb for author archive   
            elseif ( is_author() ) {//Check if an Author archive page is being displayed.
                global $author;
                //returns the user's data, where it can be retrieved using member variables. 
                $user_info = get_userdata($author);
                echo  'Archived Article(s) by Author: ' . $user_info->display_name ;
            }       
            //Display breadcrumb for 404 Error 
            elseif ( is_404() ) {//checks if 404 error is being displayed 
                echo  'Error 404 - Not Found.';
            }       
            else {
                //All other cases that I missed. No Breadcrumb trail.
            }
           echo '</div>';     
        }   
    }
    ?>

    After adding the above function in your functions.php file, copy and paste the code below in the header.php file located in your theme´s folder. Place the following code where you want the breadcrumb trail to appear.

    CODE-2:

    <?php 
        //function_exists() — Return TRUE if the given function has been defined.
        //Adding breadcrumb trail to the WordPress theme.
        if (function_exists('wp_bac_breadcrumb')) {wp_bac_breadcrumb();} 
    ?>

    The easiest way is to place the above code (CODE-2) in your theme´s header.php file. If you decide otherwise, then you need to place it in multiple files like: single.phparchive.phpsearch.phppage.php (custom-page.php if you have one) and probably in other files depending on your theme. Did you get the point that adding it to the header.php is simpler?

    Styling the Breadcrumbs

    Finally we need to style the breadcrumb trail with CSS. The following code is what I used to style the breadcrumb navigation for this blog. The code should be added to your theme´s CSS file (usually called style.css). Of course go ahead and change it to fit your design.

    .breadcrumb{
        width:645px;
        float:left;
        padding:0 0 0 47px;
        margin:9px 0 0 0;
        font-size:90%;
        clear:both;
    }
    .delimiter{
        color:#000;
        background-color:inherit;
    }
    .delimiter1{
        color: #627FC3;
        background-color:inherit;
    }

    You now have the breadcrumbs code that can be used on any WordPress Website.