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


Friday, December 30, 2011

Allow Silverlight to access clipboard after having clicked “NO” before

Silverlight applications can put information into the computer’s clipboard. But only when the user grants the application access to it.

So while using Silverlight apps online you might have come across this dialog:


I accidentally clicked “no” once and had lots of trouble to reverse this step because I haven’t been prompted this question again.

Even google was no help in this case. Neither was re-installing Silverlight.

Finally a heroic search in the registry gave a solution. There is a place in the registry where Silverlight places the information about clipboard access.

Inside that Key is a subfolder for each Silverlight application that has prompted this question. If you delete the proper folder, you will be prompted again the next time.


Monday, November 14, 2011

Setting environment variables on Windows Azure: easy way

A few hours after writing the last post, I discovered that one can specify environment variables in the .csdef file:

    <Variable name="a" value="b" />


Don't know yet, if this does the same as my code in the last post. I might investigate on that...

Setting environment variables in Windows Azure

At the latest when you want to run java applications on Windows Azure you need to set several environment variables. Since there are startup tasks you may perform before your Role is being started, this obviously is the place where to set these variables. But there are some difficulties:

Setting environment variables Intentional-Style

Setting environment variables using the well known set command line tool works on Windows Azure like on premise:

set MYPATH=C:\Directory\


  • This only works for one command shell session

  • This only works for the current user

The variables set should be available all time and for all users. So they need to be set as system variables. And system variables may only be set by an administrator.

Setting environment variables correctly

  1. Make sure your startup script is run with elevated permissions.
    Check your .csdef file to look similar to this:
      <Task commandLine="Startup.cmd" 
            taskType="simple" />

  2. Use the setx command line tool with the /M parameter to set system variables:
    setx MYPATH C:\Directory\ /M

  3. If you need the variables set to use them in your startup script, you need to set them with the set command again.
    - set works for the current session (the startup script)
    - setx
    works for all session started after setting the variables


How to use the setx command:

Tuesday, October 25, 2011

Sending e-mails using IIS SMTP Server on Windows Azure

If you want to send emails from a Windows Azure Role, there’s the possibility to use the built-in SMTP Server of IIS 6.0. Here is a guide how to use startup scripts and PowerShell commands to set up a SMTP server in the cloud.

Before you start make sure that you’re running a Windows 2008 Server R2 in the cloud by setting the osFamily Attribute to osFamily=2 in the ServiceConfiguration.cscfg file.

Setup the SMTP

Here is a guide that shows how to set up the SMTP server manually. Those are the same steps we’re going to do here using scripts. It helped me to understand what’s necessary to do. Just deploy any Azure Project to the Cloud, RDP in, install the SMTP-Server feature and do the steps described in that guide.

But now to the automated setup scripts:

1. Create a new startup task in the ServiceDefinition.csdef

  <Task commandLine="Startup.cmd" executionContext="elevated" taskType="simple" />

2. The startup file first needs to install the SMTP-Server feature automatically. To gain this it uses the PowerShell 2.0. After that it calls a VBScript that configures the SMTP-Server.

The Startup.cmd:

powershell -command "Set-ExecutionPolicy Unrestricted"

powershell .\InstallSmtp.ps1

cscript ConfigSmtp.vbs

The InstallSmtp.ps1 PowerShell script:

Import-Module Servermanager
Add-WindowsFeature SMTP-Server

3. Now we need to create the VBScript that configures the SMTP server: We need to add all IP addresses that are allowed to send mails through this SMTP server to the grant list. Assuming only applications running on the same server are allowed to send emails we’re going to add to that list.

The ConfigSmtp.vbs

Option Explicit
Dim smtpServer, relayIpList
' Get the default instance of the SMTP server
Set smtpServer = GetObject("IIS://localhost/smtpsvc/1")
' Get the IPList
Set relayIpList = smtpServer.Get("RelayIpList")
' Add localhost to that list
relayIpList.GrantByDefault = false
relayIpList.IpGrant = ""
' Save changes
smtpServer.Put "RelayIpList",relayIpList

4. Deploy to the cloud

Use the SMTP from C# code

To use the local SMTP server from within your C# code use the following lines:

var client = new System.Net.Mail.SmtpClient("localhost");
            "This is my subject",
            "Hello, this is a mail from the cloud!");

Don’t get blacklisted

Even Steve Marx recommended not to use the SMTP server feature on Windows Azure instances because they soon would be blacklisted. To avoid getting on a blacklist you could use a smart host to deliver your emails with.

If you want to use a smart host in your deployment, you need to extend the ConfigSmtp.vbs:

' set the outbound connector to a smart host
smtpServer.SmartHostType = 2
smtpServer.SmartHost = "smtp.mysmarthost.tld"
' use basic authentication
smtpServer.RouteAction = 264
smtpServer.RouteUserName = "myName"
smtpServer.RoutePassword = "myPassword"
' save changes

In this case I have been using the SMTP relay services offered by which worked just fine. Depending on what service you’re about to use, the settings might differ.