Sunday, August 12, 2012

Windows 8: View And Renew Developer License

Developer licenses are only valid for a given period of time e.g. one month. After expiration you may not run your own applications any more. Even the XAML-Designer in Visual Studio 2012 states that your developer license expired and you may not view any preview of your pages. Usually Visual Studio 2012 then pops up a dialog in which you can sign in with your LiveID and renew that developer license.

It happened to me that this dialog never showed up. So what to do?

There are three PowerShell Commandlets that can be used to view your current Windows 8 developer license and its validity, renew an expired license or return a license:

It is important to run the PowerShell as an Administrator to use those commands.

  1. View your current Developer license, its validity and expiration date:

    PS C:\WINDOWS\system32> Get-WindowsDeveloperLicense

    PowerShell: Get-WindowsDeveloperLicense showing the validity and expiration of the current developer license
  2. Renew a Developer license:
    This command pops up a dialog in which you can sign in to renew your developer license.

    PS C:\WINDOWS\system32> Show-WindowsDeveloperLicenseRegistration

    show registration dialog 1
    show registration dialog 2
  3. Unregister a Developer license:

    PS C:\WINDOWS\system32> Unregister-WindowsDeveloperLicense

Friday, August 10, 2012

Windows 8: Hide Virtual Keyboard Programmatically

The visibility of the virtual keyboard in Windows 8 Metro Style Apps depends on whether a text input enabled control is focused or not:

In the left image the user tapped into a TextBox control. This tap sets the focus on that TextBox and the virtual keyboard appeared. After having entered some Text the user taps the “OK” button and the virtual keyboard hides again due to the loss of focus (right image).

with keyboard       without keyboard copy

But sometimes there is no Button control to hit after having entered some text and thus the virtual keyboard does not hide and still might cover important parts of the UI. In order to hide the virtual keyboard no matter where the user taps outside the TextBox one could set the focus to a hidden button programmatically.

See the following example:

XAML Markup:

   1: <Grid>
   2:   <Button x:Name="hiddenButton" Opacity="0" />
   3:   <TextBox Width="300" Margin="50" 
   4:            LostFocus="TextBox_LostFocus" />
   5: </Grid>

C# Code Behind:



   1: private void TextBox_LostFocus(object sender, RoutedEventArgs e)
   2: {
   3:     this.hiddenButton.Focus(Windows.UI.Xaml.FocusState.Pointer);
   4: }

Friday, July 20, 2012

Windows Azure: Local User Account Expires

Symptom: mounted network drive missing

There was a scenario in which I needed a local user to perform actions in a Windows Azure Deployment. In this special scenario a local user named “fileshareuser” would mount a network drive K:\ when the role instance starts. This procedure worked pretty fine until suddenly the drive K:\ was missing.

Since one cannot logon as a local user via RDP to a Windows Azure instance it took me hours to find out what’s going wrong here. Finally I got this error message trying to mount the same network drive again using this impersonating model to execute C# code as that local “fileshareuser” user:

CommandLine error indicating that the local user account password has expired on windows azure

Problem: default local password policy

This led me to the problem: The password of the local user a”fileshareuser” had expired. But the account settings didn’t say anything about a password expiration. Further investigation let me find a local policy that makes all passwords expire after 42 days…

Windows Azure - Default Local Policy: Maximum password age is 42 days

Usually this policy never should have become effective, since the Windows Azure Controller updates all instances every month installing a new operating system and forcing my program to recreate the “fileshareuser” user.

After 42 days running the connection to the K:\ drive would still be there and grant the “fileshareuser” access to the files. But as soon as the instance is rebooted the policy prevents the local user from connecting to the network share.

Solution: deactivate local password policy with shell command

In order to prevent this scenario from happening again in the future I had to deactivate the local password policy on every Windows Azure instance. There are two ways to achieve this for the “fileshareuser”.

  1. Mark the local user account with flag “password never expires”

    Using the following command line the check box “Password never expires” will be checked for the user “fileshareuser”:

    WMIC USERACCOUNT WHERE "Name='fileshareuser'" SET PasswordExpires=FALSE

    Local Account set to Password never expires on Windows Azure
  2. Deactivate local password expiration policy

    This command will set the local password policy “maximum password age” to 0. No local user account will experience a password expiration again.

    net.exe accounts /maxpwage:unlimited

    image