Friday, August 17, 2012

Windows update error 0x8024402F

I run yesterday into a weird error, for which I spent half of day to solve the problem. It’s unlikely you’d run into the same problem, so this is more for me to remember what I did to fix it in case I run into this again…

Yesterday I upgraded my laptop to Windows 8 Pro and installed Office 2013 Consumer Preview (upgrade from Win7 Ultimate/Office 2010). After the upgrade, when I tried to install latest Windows updates, I kept getting error 0x8024402F.

I tried the Help page on the error code, I launched the troubleshooter there (which claimed it could be a problem with the server connection, and claimed to have applied fixes), but all lead to nothing.

Knowing in the past I had trouble with Windows Update I searched my blog, which pointed out to problems related to UseWUServer set when I joined CorpNet. I left corp.microsoft.com domain and joined my home domain, but that only cost me 2 reboots and still didn’t fix anything.

I searched the the net for the error code, I found more KnowledgeBase pages with more FixIt installers which also did not fix the problem.

From http://support.microsoft.com/kb/836941 I found out the error code means WU_E_PT_ECP_SUCCEEDED_WITH_ERRORS. Further searches on the named error pointed to a WindowsUpdate.log file (instructions for reading it are at http://support.microsoft.com/kb/902093).

I looked in the log file and it contained more error details like this:

1060 15a8 PT WARNING: ECP: Failed to validate cab file digest downloaded from http://www.download.windowsupdate.com/msdownload/update/software/svpk/2008/06/1319061_d1590aa04b224974f0cf46ee7937bda90a815268.cab with error 0x80246003

Great, now I was looking for a different error code, 0x80246003. A search on the error number on Internet didn’t find any solution. The only thing I could find is a KB page http://support.microsoft.com/kb/938205 where I learned the error code 0x80246003 is WU_E_DM_UNKNOWNALGORITHM “A download manager operation could not be completed because the file metadata requested an unrecognized hash algorithm.”
Further searches on the named error lead nowhere. I tried re-registering the cryptographic providers dlls, comparing with other machines where things were working, all to no avail.

I run ProcMon searching for failures (when in doubt, run Process Monitor), but again this didn’t help.

I searched the internal Corpnet site for the error code or named error, but that also didn’t lead to a solutions.

Ultimately, I searched the source code. The error code is returned from only one place, from a failed test checking whether test keys are allowed. This had 2 parts:

- checking whether I had a file AUTest.cab in %windir%\SoftwareDistribution folder

- checking whether HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Test\AllowSHA1ContentHash = (dword)1

ProcMon should have shown these as well (at least the first one, to begin with), probably I just missed the line between so many other failures.  Anyway, I set easily the registry value, but I didn’t have the file on any other machine where things were working fine.

After more CorpNet searches I found on http://mswikis/wukipedia/Wiki%20Pages/What%20is%20autest.cab.aspx where to get this test cab file (I needed to obtain a latest version anyway, since the file is signed and expires every 2 weeks).

I copied it to SoftwareDistribution folder, stopped and restarted the Windows Update service (‘net stop wuauserv’/’net start wuauserv’), and next time I tried Windows Update the update finally succeeded! After that I deleted the test cab file, and after that the updates still seem to work fine.

I suspect some internal test qfe was installed on my laptop when I joined CorpNet a while ago (giving the old ‘svpk/2008/06’ date of the update, suggesting some Win7 pre-service pack timeframe), and it was causing trouble now.

Anyway, I’m glad the problem seems fixed, but just in case here is this article to remind me the solution in case I run into this ever again.

Thursday, August 9, 2012

How to Shut Down or Restart Windows 8 when connected via Remote Desktop

 

If you connect via Remote Desktop /Terminal Services to a machine running Windows 8 and have tried to shut it down or restart it, you may have hard times finding out how to shut it down.

Normally, a Windows 8 machine can be restarted by accessing the Settings screen by pressing WinKey+I (or by accessing Charms with WinKey+C and clicking the bottom Settings icon), then by clicking the Power button and selecting Restart / ShutDown from the menu that open.

However, when connected via Remote Desktop, Windows 8 offers in the menu only a “Disconnect” option…

CharmsSettings

Another way to access usually the restart options are to press Ctrl+Alt+Del , then click the Power button there and select Restart / Shut Down from the menu that opens. When connected via Remote Desktop, you can access the power button with Ctrl+Alt+End ( Ctrl+Alt+Del displays the lock screen on the host machine, not on the machine you’re connected to), but again Windows 8 offers there only the “”Disconnect” option (despite the tooltip on the button indicating Shut Down).

CtrlAltEnd

 

So, how to restart Windows 8 when connected via Remote Desktop?

Since most of the time I have a Command Prompt window open (can easily open one with WinKey+R, type “cmd” and Enter), until now I’ve restarted the machine by typing “shutdown –r –f” in the command window, then agreeing with a notification that Windows will soon restart, or waiting ~30 seconds for the machine to restart automatically. If you just need to shut down the machine, don’t pass the “-r” argument.

ShutdownRF

Today I found out another way to restart the computer: you can access the desktop (e.g. by pressing WinKey+D = Desktop, or WinKey+M = MinimizeAll), then press Alt+F4.  This displays a Shut Down Windows dialog, where all the options are available! Ah, the good ol’ Desktop…

AltF4

And, finally if you are a mouse person and prefer a one-click solution, you can create a shortcut to shutdown.exe, then right click it and pin the shortcut to the StartMenu. From now on you’ll be able to shutdown the machine by double clicking the icon on the Start screen or on desktop.

ShutdownShortcut

Monday, August 6, 2012

How to implement a Quick Launch search provider for Visual Studio 2012


A new feature in Visual Studio 2012 is the Quick Launch which allows searching menu items, tools options, and various other things in VS. It drives its roots from a similar feature provided in Visual Studio 2012 part of the Productivity Power Pack under the Quick Access name.
QuickLaunch

The following article will tell you how to write a Visual Studio Search Provider integrating with Quick Launch and will demonstrate the functionality with a sample

Visual Studio 2012 comes with only 4 providers out of the box: menu item, tools options, open documents and most-recently used items. Additional providers can be implemented to extend Quick Launch searches. I believe Microsoft will provide more extension packages and samples but until it does, I’m providing here a primer for writing a new search provider and a sample implementing 2 providers: Fruits and Vegetables, providing their results from 2 hardcoded lists of items.
QLFruitsAndVeggies
While Quick Launch is the official feature name, the Visual Studio interfaces supporting the feature use GlobalSearch in the name. The QuickLaunch feature can be accessed from the SVsGlobalSearch service that implements IVsGlobalSeach and IVsGlobalSearchUI interfaces.
Providers for Quick Launch are objects implementing the IVsSearchProvider interface. They are identified by their unique id (GUID), and they also need to have a unique shortcut string (more on this later).
There are 2 ways to register a new provider for Quick Launch:
1) Dynamic: a loaded package can use IVsGlobalSearch.RegisterProvider interface and pass in the provider object. Dynamic providers can also be unregistered when no longer needed; static providers cannot be unregistered. The provider is available only after the package is loaded; packages may need to use auto-load feature in VS to make sure they get loaded before the user needs their search features. Due to an implementation detail, you can’t use in the same package both dynamic and static registered providers (at least in VS2012 RTM).
2) Static: This is the most common way. In the appid’s configuration hive, under the SearchProviders key, create a subkey with the provider’s Guid, and under it declare the Package Guid implementing the provider. The Name is optional, but is recommended to write one so the providers can be quickly identified at a glance in registry.
[HKCU\Software\Microsoft\VisualStudio\11.0_Config\SearchProviders\{9ba8f997-b098-41c9-b360-fecaa397c94f}]
“Name”=”Fruits search provider”
“Package”=”{0bdb8b31-2ee3-4cd9-893a-d0b11d335f06}”


When the providers are loaded, Visual Studio loads the package implementing the provider. The package must implement the IVsPackageExtensionProvider interface, and Visual Studio will call the CreateExtensionInstance with extensionPoint = IVsSearchProvider interface’s guid, and the interface = guid identifier of the search provider (as declared in registry). The package can then create an instance of the search provider and return the object.


When implementing managed search providers, all this extensibility hook-up can be automatically done by using classes from Microsoft.VisualStudio.Shell.11.0.dll.


1) First, make sure the class implementing the search provider is attributed with the Guid identifying the provider


image








2) Derive the package class from the ExtensionPackage class in Microsoft.VisualStudio.Shell namespace


3) Declare the search provider with ProvideSearchProvider registration attribute on the package class.


image


As mentioned before, search providers are identified by 2 things:


- the provider ID, a Guid


- the provider shortcut: this is a fixed string (in the sample case, “fruits” or “veg”) which allows performing searches only against this provider, e.g. “@fruits apple” will search for “apple” only in the fruits search provider


One of the most important functions in a search provider is the CreateSearch function. Providers are called to create search tasks for the user’s input, then tasks are called on background threads to perform the actual search.  To implement a search task I recommend deriving from VsSearchTask in MPF which provides default implementations for IVsSearchTask interface, tracking search status, or notifying the global search manager about the task’s search progress. Usually, if you derive from the class you only have to override and implement the OnStartSearch method, which lets you focus on the important part – perform the actual match/search.


Search tasks have to perform very fast. The search manager will only display results that are returned in the first 1000ms, to avoid results and user’s selection ‘jumping’ in the pane after a certain time. If you don’t see any results from your search provider in the pane, it’s either you haven’t reported any results within 1s, or there are many search providers installed in the system and there wasn’t place in the popup to display results from your provider after displaying up to 3 items from other search providers that reported results faster, or from the built-in providers. When reporting search results resultant of slow operations (such as http:// queries to some online search service), it is advisable to query for only top 5-10 items that match, such that the web query return faster and you get to report at least 1 results in the first second.


Download the Quick Launch Sample



http://www.alinconstantin.net/download/Example.QuickLaunchSearchProvider.zip

Thursday, August 2, 2012

Command Window is not available in Visual Studio Express editions

 

As other users have noticed in posts like this one, Command Window is a toolwindow that isn’t available in Visual Studio editions to be explicitly displayed by the user.  The menu commands used to display the window are not available.

Fortunately, there are workarounds.

Immediate Window is another related toolwindow that can be used to display variables’ values, evaluate expressions, and to execute commands. The Immediate Window is automatically displayed when entering Debug mode. It can also be displayed on-demand by using the Debug/Windows/ImmediateWindow (Ctrl+D, I) menu item.

Command Window displays automatically a “>” prompt and the user only has to type command names. To execute commands in Immediate Window, the user has to explicitly type the commands by prefixing them with “>”. Full Intellisense support is available here, same as in Command Window. Pre-defined aliases also work fine (of course, trying to execute commands that don’t exist, aka forcing the display of CommandWindow won’t work).

image

A second workaround is to use the Find combobox.

First, make sure the Find combobox is displayed in the Standard toolbar (in Visual Studio 2012 this has been hidden with the command bar reduction work, so you’ll have to use the quick customize menus to bring it back)

image

Then, in the Find combo you can type commands by starting them with “>”, and the full functionality of Command Window will be available there (with Intellisense, aliases like “of”, etc).

image

The only Professional feature related to Command Window that can’t be workaround in Express editions is redirecting the output to a file. The Tools.LogCommandWindowOutput (“log” alias) and Tools.ImmediateMode (“immed” alias) are not available either. Anyway, you won’t need the last one since you are already in Immediate Window, can manually display the toolwindow or execute “>Debug.Immediate” instead from Find combo.

Monday, April 2, 2012

Bing reflection

In case you missed it, Bing home page had today an interesting effect: a reflection of the logo and search box on the water in the animated background image - and the reflections were waving with the water waves...



Bing used animated backgrounds before, but I think this is something new. I'm not sure if this was some sort of April's Fool or a new trend in Bing homepages, but I liked the idea.

Thursday, September 29, 2011

Have a Windows Phone 7? Here’s how to force a Mango update

Microsoft has released Windows Phone 7.5 Mango release, and carriers have already rolling out the update for most models (see list of phones for which Mango update is already rolling). Unfortunately, this roll-out is graduate and it may take weeks until the carrier provider notifies you to install it.

But, via FnPsychopath’s post in the above mentioned article, there is a way to force the Mango update on phones for which Mango has started rolling out:

Connect your Windows Phone to a PC and launch the Zune software
Click on Phone > Settings > Update. Allow the software to tell you whether an update is available. If so, skip this guide. If not continue to the next step.
Time to force the update. Click another button (any of the options above or below the word Update). Then click the Update button again, and this time disconnect your computer from the internet after 1-2 seconds. Do this by pulling out the Ethernet cable, disabling Wi-Fi, etc. If it says your phone is already up to date, you didn't disconnect quickly enough and need to try this step again.
Wait 30 seconds or so and Zune should display a notification that an update is available. This is 7392, the first Mango pre-update.
Now reconnect to the internet and continue with the update process through the Zune software.
After 7392 is fully installed, you may receive a notification that another update is available. If so, install it now. If not, proceed to the next step.
If the second update isn't popping up on its own, repeat steps 3-5, causing the 7403 update to appear.
Install 7403, brave reader. Speeding right along, isn't it? ;)
Mango time! At this point, Zune should automatically start installing the last update, 7720, aka Mango. If it doesn't happen automatically, force it like we did in previous steps.

Nice hack! It worked for me exactly as described. I’m not sure if this is a bug in Zune software or an intentional feature/workaround, but it sure is handy!

Thursday, August 25, 2011

<Strings> Element in VSCT files – ButtonText, CommandName, CanonicalName, MenuText, oh my!

 

If you ever added a Button definition in VSCT files for Visual Studio menus, you may have wondered what are all the ButtonText, MenuText, CommandName, etc. elements associated with the button.

When you create a new Visual Studio Extensibility project and tell it to create a menu item, accepting the default values, the result is a generated vsct file containing code like this:

      <Button guid="guidVSPackage1CmdSet" id="cmdidMyCommand" priority="0x0100" type="Button">
        <Parent guid="guidVSPackage1CmdSet" id="MyMenuGroup" />
        <Icon guid="guidImages" id="bmpPic1" />
        <Strings>
          <CommandName>cmdidMyCommand</CommandName>
          <ButtonText>My Command name</ButtonText>
        </Strings>
      </Button>


I’m going to tell you upfront it’s indicated to change the format of the <CommandName> element – the project template generator gets it wrong how the value should look like.



So,  where do these values appear in UI?  There is a MSDN article for the Strings Element description, but is a bit confusing, and as writing this article, it contains a couple of mistakes.



To better exemplify where all these elements appear, let’s start by defining a Button command with each child element specified, like so:



VSCT





Now let’s build the project and see where these strings appear in Visual Studio.



Let’s start with ButtonText. This is a mandatory string, and, if any other strings are omitted, this string will be used to generate the other optional values. This means this string can appear in all places 



As the MSDN page describes, ButtonText is used in UI when the button is placed in a menu controller (such as the dropdown menu of the NewProject button):



MenuControllers



However, the same ButtonText string is used when the button is placed:



- in the Visual Studio’s Main Menu



- in a toolbar (e.g. in the Standard toolbar)



MenuToolbars



In the same picture, notice also that when the button is placed in a menu (e.g. under the File menu), a different string is used – this time MenuText is used.



A button can be easily added to other menus and toolbars by using the Tools/Customize dialog. However, using the dialog it may be a bit confusing because it displays a different string. Neither ButtonText nor MenuText will appear in this dialog, despite the dialog mimicking the looks of menus and toolbars. Here, in the Controls list, is used the CommandName string.



Customize



The CommandName also appears in the Add Command dialog that can be invoked from the Customize dialog, in the Commands list.



CustomizeAdd



Now you may see why it’s recommended to change the format of the CommandName generated by the project wizard. It may be hard for users to figure out that cmdidMyCommand is actually related to what the user usually sees in the UI for that command, more like “Command Name”. Use a descriptive string for your command names, use spaces and no funky “cmdid” prefixes. Or simply don’t define at all this string, and let the shell display instead the ButtonText string – this is probably what you’ll want in most cases.







The MSDN article indicates CommandName is also used in the Tools/Options dialog in the Keyboard page. This is incorrect. The Keyboard dialog displays the LocCanonicalName string (or in it’s absence, the ButtonText string), after stripping unwanted characters such as spaces, ellipses, ampersands, etc.



Keyboard



The LocCanonicalName string  is also displayed in the Command tool window, in the Intellisense/autocomplete popups.



CommandWindow



Again, the MSDN page is a bit misleading here, as it seem to suggest that CanonicalName string appears in the Command Window (after being stripped of ampersands, spaces, etc).



While the autocomplete popup only displays the LocCanonicalName string,  both CanonicalName and LocCanonicalName can be used for command execution, but you have to type the canonical name string. Notice that execution succeeded no matter which of these strings was typed, whereas trying to execute an inexistent command displayed an error message.



CommandWindow2



Again, if one of these strings (or both) is omitted from the button’s definition, the ButtonText is used instead to generate a canonical name for command execution and/or the autocomplete popup.



And finally, the ToolTipText string is used for the button’s tooltip, when the button is placed:



- in the Visual Studio’s main menu, as a top-level button



- in a toolbar (in this case the keyboard shortcut, if any, is also displayed in the tooltip)



The tooltip is not displayed when the button is placed as a menu item (e.g. in the File menu) as the MSDN page indicates.



TooltipText