Windows7 Trigger Start Services – Part 2: Building a Trigger Start Optimized Service

In the last post Windows 7 Trigger Start Services – Part 1: Introduction, we introduced Windows7 Trigger Services as a great way to optimize your services to have better performance and improved security. In this post you will learn how to convert a standard automatic-start service to a trigger-start service that starts up only when a certain event occurs in the system. We’ll use a WPF application (obviously managed code) that registers and monitors a service (also implemented using .NET). To bridge between the .NET world and the native Win32 APIs that we saw in the previous post, we use a C++/CLI interoperability layer.

This sample application has 3 parts:

  • A C++/CLI interoperability layer that provides a regular and easy .NET API to the controller application
  • A WPF controller application that lets you register and run the service
  • A simple .NET service that looks for a USB storage device (disk on key) and on it, a specific folder named “ToCopy” from which to copy files to your local “C:\FromUSB” folder

The following image illustrates the solution structure.

image

Let’s start by reviewing the .NET Service code implementation. This is a simple Windows service written in C#. The purpose of this service is to copy pictures automatically to your local hard-drive- “c:\FromUSB” from the USB storage device that is plugged into your computer.

The service implementation can be found at USBService.cs. This class inherits the ServiceBase base class and overrides the OnStart and OnStop methods. This class has a DoWork method that actually does all the copying of images from the USB disk to your local drive. The DoWork method writes to a log file that we will be monitoring.

The real interesting part of the service implementation is the OnStart method. This method is called once the service is started. Notice that the first line of code checks whether the service is configured as a trigger start service. If the “if” statement returns false, we create a new instance of a timer and have it poll every 5 seconds. Before Windows7, this was the only way to implement such a service, that is, by regularly polling the system to check for a USB device. Therefore, the service needs to run 24x7 to poll the system. This is highly wasteful of resources and keeps the system from transitioning to a low-power state, increases the application attack surface, among other negative things.

But, with Windows7, you can configure such a service with a USB device arrival trigger. This means that the service will not run until a USB device arrives, specifically a USB generic disk device. We’ll get to that part of the solution in a second, but for now, if you look at the OnStart method, you will notice that we check whether the service is configured as a trigger start service; if it is, we simply call the DoWork method on another thread, as shown by the following code snippet. This should work just fine because the service is NOT running, and will start to run only when the trigger happens. And then it will not default to the timer, but rather use the thread pool to queue the work.

 protected override void OnStart(string[] args)
 {
   if (ServiceControl.IsServiceTriggerStart(ServiceName))
   {
      ThreadPool.QueueUserWorkItem(_ => DoWork());
   }
   else
   {
     _timer = new Timer(_ => DoWork());
     _timer.Change(0, 5000);
   }
 }

The ServiceControl namespace contains the C++/CLI interop layer. This layer uses C++/CLI as the binding element between the native API and the WPF application. The main ServiceControlInterop.cpp file contains all the functionality that we need and that is used by the WPF application. For example using the controller application we can use AddService(…) or RemoveService(…) to add or remove a service respectively. We can also configure the service as a trigger start service for either a USB device arrival or first available IP address by using SetServiceTriggerStartOnUSBArrival or SetServiceTriggerStartOnIPAddressArrival respectively. Reviewing both function implementations reveals that basically both are following identical paths. They:

  • First, use OpenSCManager to get a handle to the Service Control Manager (SCM)
  • Then use the SCM handle OpenService, to get an actual service handle that we wish to configure
  • Finally call ChangeServiceConfig2 to set the specific trigger

All this was explained in detail in the last post (Windows7 Trigger Start Services – Part 1: Introduction

You can download the code sample for this application. Note that you will have to run Visual Studio as administrator (see image below) because you will need to register, start, and stop services. . You will also need to Windows 7 SDK to compile the C++ part of the solution.

image

When compiling and running the default solution (the WPF application) you will see the following image.

image

This is the main WPF controller application. From here, you can create the service by clicking the Create Manual button.

Next, open the Services Window by typing “Services” in the Start Menu search box. You should see the Service window. Locate the USBCopyService; it should appear as in the following image.

image

Click the Run button and then the Refresh button in the Services window, or just press F5. You will not notice a great deal of change, but the USBCopyService changed from Manual to Started, as shown in the following image.

image

 

A second look at the actual application reveals the service activity in the log file. As you can see in the following image, the services awaken every 5 seconds and poll the system, looking for USB devices:

image

Click the Stop button to stop the service and then click the Delete Service to delete it. Now click the Trigger Start button to register and configure the service as a trigger start service that is triggered once a USB Generic disk arrives. If you check the Service window, you will see the USBCopyService listed as “manual” where in reality it is configured as triggered start service (there is just no graphical representation of that).

If you plug in a USB disk with a “ToCopy” folder the service will kick into action and copy the files to c:\FromUSB. Not the best implementation, but hey, it is only a demo. The following image shows a single line in the log file because the service actually ran only once; it executed the DoWork method and then quit. It didn’t run and poll the system every 5 seconds and didn’t waste resources or become a security liability.

image

To conclude

Developing a service with Windows 7 trigger start service in mind might be a little more difficult than a regular “auto-run” service that just runs in idle from boot to shutdown. But in practice, all it takes is only a few lines of code, no more. And these few lines of code can have a very big affect in terms of resource consumption and security. So the next time you build a new Windows Service, try to incorporate triggers.

You can learn about Windows 7 using the Windows 7 Training Kit for Developers or by viewing Windows 7 videos on Channel 9.

You can also get hands-on experience for Windows 7 Trigger Start Services using the Windows 7 Online training that is part of the Channel 9 Learning Center


Windows7 Trigger Start Services – Part 1: Introduction

We introduced Service 0 Isolation a few weeks ago as an application compatibility topic. It is only natural that we continue our conversation about services in the context of Windows 7. But this time, we will talk about some of the benefits to service optimization that are available in Windows 7. This post focuses on a new feature in Windows 7 called Trigger Start Services. But before we jump into the API, let’s provide some background about services.

What Are Services?

A service is an integral mechanism built into Microsoft Windows operating systems. You can think of services as “special applications” that run with no regard to the current user context. Services are different from “regular” user applications because you can configure a service to run from the time a system starts up (boots) until it shuts down, without requiring an active user to be present – that is, services can run even though no users are logged on.

We like to think about services as running tasks for us in the background without interfering with user operations. Services on Windows are responsible for all kinds of background activity that do not involve the user, ranging from the Remote Procedure Call (RPC) service, through Printer Spoolers, to the Network Location Awareness service.

Over the years, Windows has grown and with it the number background services. But to be honest, background services in Windows are a pain – the operating system ships with a lot of them in the box. On top of that, ISVs and their applications add even more services, like software updates to name only one. With that said, some of these services are critical and are required during boot sequences, some are required later when a specific user logs on, while others don’t need to execute until they are called upon. Nonetheless, when you look at the currently running services, you see a lot of services that really don’t need to run 24x7.

What’s Wrong with Services Running 24x7?

There are several issues with having services run 24x7:

First, why have something run (even in the background) when there is no need for it to run? Any running process (services included) uses valuable memory and CPU resources that could be used by other applications and services. If you total up all the services that are running at any given time, they add up to quite a lot of memory, handles, threads, and plenty of CPU usage. All of these “wasted” resources reduce the overall computer performance, decrease its responsiveness, and make users think their computers are sluggish and slow. Also, since most of the running services are configured as Auto-Start (start running upon system log-on), these services have an impact on the computer's boot time.

Second, these wasted resources, have a direct impact on power consumption. The more demands we place on the CPU, the more power our computer uses. This can be critical for laptops, and could reduce battery life from four hours to three hours.

Third, having non-productive software run all the time may lead to memory leaks and overall system instability. This can lead to application crashes and ultimately computer crashes.

Last, but not least, if a service is running 24x7, and this services is well known (any popular application might have one – like the PDF Reader), it provides a larger attack surface. A hacker might use the knowledge that a certain popular application installs a service that runs 24x7, and try to hack into that service to gain privileged access to the computer.

Given all of the above, it makes you wonder why so many developers configure their services to run all the time when there are other options. Even before Windows 7, there were several service start-up options:

  • Disabled completely disables the service and prevents it and its dependencies from running—this means that the user must start the service manually from the Control Panel or the command line
  • Manual starts a service as required (defined by dependencies to other services) or when called from an application using the relevant API as shown later in this post
  • Automatic starts the services at system logon
  • Automatic Delayed is a newer startup type introduced in Windows Vista that starts the service after the system has finished booting and after initial demanding operations have completed, so that the system boots up faster

Unfortunately, many ISVs (Microsoft included) still choose to configure their services to Automatic (or Automatic Delayed) because it is the easy solution for everyone. A service simply runs 24x7 and is always available, eliminating the need to check any dependencies or verify that the service is running.

There are many examples of existing services that can become more resource friendly and more secure by not running 24x7. For example, think of an update service that checks for new application updates. If the computer is not connected to a network and has no IP available, why should the update service run? It can't reach anywhere, so why run a program that does nothing? Think about a policy management service that is invoked when a group policy changes or when the computer joins or leaves a domain, but right now the computer is connected to my home network and again the service works in vain.

Introducing Windows 7 Trigger Start Services

The solution for the above problems is to move the service out of its “forever running state” into other types of background activity, such as scheduled tasks or trigger-start services. This post focuses on Windows 7 Trigger Start Services. Windows 7 Scheduled Tasks include a lot of valuable information that we will describe in another post.

Trigger-start services are new to Windows7. A trigger-start service is a regular service that you can configure to run (or stop running) only when it is triggered, that is, only when certain criteria and conditions that you define are met (for example, when the first network IP address becomes available, or when the last network IP is lost). Here is a list of the available triggers that you can use to configure the Start-Up mode of a given service:

  • Device interface arrival or departure
  • Joining or leaving a domain
  • Opening or closing a firewall port
  • Group policy change
  • First IP address available/ last IP address leaving
  • Custom event – Event Tracing for Windows (ETW)

The last item in the list represents the extendibility point. As a developer, you can configure any ETW event as a trigger for services, which gives you a very good tool to fine-tune your control over starting and stopping services from your application.

So what exactly is a trigger?

A trigger consists of:

  • A trigger event type
  • A trigger event subtype
  • The action to be taken in response to the trigger event
  • One or more trigger-specific data items (for certain trigger event types)

The subtype and the trigger-specific data items together specify the conditions for notifying the service of the event. The format of a data item depends on the trigger event type; a data item can be made up of binary data, a string, or a multistring.

Working with Trigger Start Services

Unfortunately, Windows 7 Services MMC UI does not include a graphical representation of the trigger start services. However, you have two options. You can still use the old and good sc.exe (Service Configuration command line tool), or you can use the WIN32 ChangeServiceConfig2 method to configure the service start option programmatically as demonstrated in this post.

Using SC.exe to Query Service Trigger Information

It's time to start have some fun. First, let’s start with just extracting some configuration information from a few services. The generic form for using the service configuration is:

sc <server> [command] [service name] <option1> <option2>...
Where server is optional and by default you work with the local computer:
  • command is the operation you wish to perform like querying trigger information
  • service name is the name of the service you wish to work with
  • options are the different values (options) you can pass to configure the service

Let’s start by querying a specific service for its trigger start configuration. To do so you need to launch a Windows Shell window:

  1. Open the start menu.
  2. Type CMD in the search box.
  3. Choose cmd.exe.
    This will open a Windows Shell window.
  4. Type sc qtriggerinfo w32time and press enter

This is how it should look:

image

As you can see, we queried the trigger information of the W32time service, which is configured to start when the computer is joined to a domain and stop when the computer leaves the domain.

Microsoft updated the sc.exe command-line tool for Windows 7 to support configuring and querying a service for supported triggers. Type sc triggerinfo in the Windows shell window and press enter. The result looks like the box below, and lists all the different triggers and how to configure a service to use trigger start services.

C:\>sc triggerinfo
DESCRIPTION:
        Changes the trigger parameters of a service.
USAGE:
        sc <server> triggerinfo [service name] <option1> <option2>...
OPTIONS:
 start/device/UUID/HwId1/... <Start the service on arrival of the
                             specified device interface class UUID
                             string with one or more hardware ID
                             strings and/or compatible ID strings>
 start/custom/UUID/data0/.. <Start the service on arrival of an
                             event from the specified custom ETW
                             provider UUID string with one or more
                             binary data items as hexadecimal
                             string format such as ABCDABCD to
                             set 4 byte data>
 stop/custom/UUID/data0/... <Stop the service on arrival of an
                             event from the specified custom ETW
                             provider UUID string with one or more
                             binary data items as hexadecimal
                             string format such as ABCDABCD to
                             set 4 byte data>
 start/strcustom/UUID/data0/.. <Start the service on arrival of an
                             event from the specified custom ETW
                             provider UUID string with one or more
                             optional string data items>
 stop/strcustom/UUID/data0/.. <Stop the service on arrival of an
                             event from the specified custom ETW
                             provider UUID string with one or more
                             optional string data items>
 start/networkon             <Start the service on first IP address>
 stop/networkoff             <Stop the service on zero IP addresses>
 start/domainjoin            <Start the service on domain join>
 stop/domainleave            <Stop the service on domain leave>
 delete                      <Delete the existing trigger parameters>

For example, to configure a service to start when the first IP address becomes available, all you need to do is type sc triggerinfo [your service name] start/networkon, where “your service name” is replaced with the name of the service that you wish to configure.

Configuring Trigger Start Services Programmatically Using ChanceServiceConfig2

The more interesting aspect, from a developer's point of view, is writing services that are trigger aware and using code to configure a service. In Windows 7, you can use the ChangeServiceConfig2 function to configure service trigger information and the QueryServiceConfig2 function to query it.

Service trigger registration is performed by calling ChangeServiceConfig2, passing SERVICE_CONFIG_TRIGGER_INFO for the dwInfoLevel parameter, and providing the trigger registration information in a SERVICE_TRIGGER_INFO structure through the lpInfo parameter. In addition, one or more trigger-specific data items can be specified. The following is an example of a service installer function that creates a USB device trigger for a service that is named MyService:

define SERVICE_NAME L"MyService"
//set the device guid
static const GUID GUID_USBDevice = {
0x53f56307, 0xb6bf, 0x11d0,
{0x94, 0xf2, 0x00, 0xa0, 0xc9,
0x1e, 0xfb, 0x8b }};

BOOL _SetServiceToStartOnDeviceTrigger()
{
BOOL fResult = FALSE;

SC_HANDLE hScm = OpenSCManager(
NULL, //local machine
NULL, //active database
SC_MANAGER_CONNECT);

if(hScm != NULL)
{
SC_HANDLE hService = OpenService(
hScm,
SERVICE_NAME,
SERVICE_ALL_ACCESS);

If( hService != NULL)
{

LPCWSTR lpszDeviceString = L"USBSTOR\\GenDisk";
SERVICE_TRIGGER_SPECIFIC_DATA_ITEM deviceData = {0};
deviceData.dwDataType = SERVICE_TRIGGER_DATA_TYPE_STRING;
deviceData.cbData =
(wcslen(lpszDeviceString)+1) * sizeof(WCHAR);
deviceData.pData = (PBYTE)lpszDeviceString;



SERVICE_TRIGGER st;
st.dwTriggerType =
SERVICE_TRIGGER_TYPE_DEVICE_INTERFACE_ARRIVAL;
st.dwAction = SERVICE_TRIGGER_ACTION_SERVICE_START;
st.pTriggerSubtype = (GUID *) &GUID_USBDevice;
st.cDataItems = 1;
st.pDataItems = &deviceData;


SERVICE_TRIGGER_INFO sti;
sti.cTriggers = 1;
sti.pTriggers = &st;
sti.pReserved = 0;

fResult = ChangeServiceConfig2(
hService,
SERVICE_CONFIG_TRIGGER_INFO,
&sti);
}
CloseServiceHandle (hService);
}
CloseServiceHandle (hScm);

if(!fResult)
{
printf("Service trigger registration failed (%d)\n",
GetLastError());
}
return fResult;
}
Note: all services are controlled by the Service Control Manager (SCM), which we’ll touch on in a different post.

In the above code snippet, you can see that first we get a handle (hScm) to the SCM by calling openSCManager. Next, we call openService and pass the handle to the SCM- hscm,and the service name – SERVICE_NAME that we wish access. The last parameter, SERVICE_ALL_ACCESS, indicates that we have complete access to the services. Assuming we got a valid handle to the service, we now start to build the specific structure that we’ll soon use to configure the service.

SERVICE_TRIGGER_SPECIFIC_DATA_ITEM defines the trigger event type. It contains trigger-specific data for the service trigger event. In our case we define the string that represents a USB gen disk arrival.

Next we define the SERVICE_TRIGGER structure, which represents a service trigger event. Note that this is where we define the trigger type (device arrival), the action (start the service), and the trigger sub type (the specific family of the USB device). Then we define one device that will trigger the service. Note that you can define an array of devices and their GUIDs. You should also note that we don’t want the service to be triggered upon just any USB device arrival like a mouse or a camera. We want the service to start only when a USB disk arrives.

Finally, we define the SERVICE_TRIGGER_INFO structure, which contains trigger event information for a service. This structure simply points to the SERVICE_TRIGGER struct that we defined previously, and the number of triggers that, in this case, is one.

Now we can call the ChanceServiceConfig2 function and pass the handle to the service we wish to configure, a SERVICE_CONFIG_TRIGGER_INFO parameter that indicates that we wish to configure the service trigger, and a null.

That is all there is to it. If we are successful, then our service will run after we insert a USB hard drive.

In the next post, we'll review how to write a simple implementation of a .NET service that we’ll program to start upon arrival of a USB generic disk.

You can learn about Windows 7 using the Windows 7 Training Kit for Developers or by viewing Windows 7 videos on Channel 9.

You can also get hands-on experience for Windows 7 Trigger Start Services using the Windows 7 Online training that is part of the Channel 9 Learning Center


Windows 7 GA – Time for Some New Windows 7 Developer Resources

Windows 7 is now available to the public and anyone can buy and install Windows 7, whether for a new computer or an existing one. Soon, people from around the world will run your applications on Windows 7. They will expect the application to work and to feel as though it is a native Windows 7 application that takes advantage of new Windows 7 features and technologies like the Taskbar, libraries, touch, and sensors.

As Windows 7 approached GA, we continued to release new developer content to help you get up to speed with the new operating system. Now that it's here, Windows 7 GA is a great “excuse” for us to give you a quick update on all the Windows 7 developer content that is available to help you learn how to write a great Windows 7 application.

Below is a list of locations where you can find Windows 7 developer content.

Updated Windows 7 Training Kit – (Download it now)

image To help you get your application onto Windows 7 as soon as possible, we updated the Windows 7 Training Kit for Developers. You can still find all the previous topics such as Taskbar, Sensor and Location, Libraries and Shell, Multitouch, Ribbon, etc. New to the kit are labs that work with VS2010 and use the new MFC improvements in VS2010 (download VS2010). We also added VB to all of our managed solutions – truly, no developer is left behind.

 

Windows 7 Online Training on Channel 9 Learning Center

Let’s assume you are interested in learning about Windows 7 libraries, or how to add some cool Taskbar functionality to your application, but you don’t want to download the entire training kit. Well with the Windows 7 Online Training Kit located on the Channel 9 Learning Center, you have immediate access to all Windows 7 learning units individually. Each learning unit (like the Taskbar) includes a few hands-on-labs and related videos. This gives you quick and easy access to most of our training material. For the rest of the content, like PowerPoint presentations and additional demos, you will have to download the Windows 7 Training Kit for Developers. The following image shows part of the managed code hands-on-lab for the Taskbar.

image

As always, the Windows 7 Topic Area on Channel 9 still features specific Windows 7 videos and screencasts. Over the past few weeks, we created new videos that I am sure you will find exciting and helpful, including a new Mark Russinovich video. As a friendly reminder, the last video Mark did, “Mark Russinovich: Inside Windows 7, was a Channel 9 blockbuster. If you haven't already viewed it, I highly recommend it, and make sure you see Mark’s new video Mark Russinovich: Inside Windows 7 Redux. Don’t forget to stay up-to-date with other topics:

  • Using Windows 7 – Contains consumer- and user-related videos such as how to install Windows 7 and how to set up a home group network
  • Programming Windows 7 – I don’t really need to explain what goes here, right?
  • Last but not least, “Under the Hood” –Covers deep architectural Windows concepts

MSDN Developer Center

The MSDN Developer Center also received a “Windows 7 GA refresh” and now sports a new look and much improved functionality. The MSDN Developer Center includes a lot of Windows 7 material that extends the training content on available on Channel 9. You can think of the MSDN Developer Center as a hub for the Windows 7 content that will give you a great head start as you develop applications that will shine on Windows 7. You can find information about specific topics, review different programming models, learn about the developer tools that you can use, watch videos, and read blogs.

image

A New Book for Windows 7 Developers

Among the other things that you will find on the MSDN Developer Center, is a list of recommended Windows 7 books for developers. It turns out that over the past few months, I’ve been busy writing a Windows 7 book with three amazing co-authors: Laurence Moroney, Sasha Goldshtein, and Alon Fliess. Together, we wrote Introducing Windows 7 for Developers. It covers most of the exciting Windows 7 features like the Taskbar, Libraries, Sensor and Location, Multitouch (including new WPF 4 support with VS2010), and even Silverlight out of image

browser (including touch :). As far as I know, this is the first Windows 7 developer book, and I hope you will find it useful. Mark Russinovich found this book helpful while integrating Windows 7 features with the Sysinternals tools and he wrote the foreword for this book.

I hope this list will help get you on your way to writing amazing Windows 7 applications.


Windows 7 Labs @ PDC

PDC 2009 takes place at the LA Convention Center on November 17th, 18th, and 19th. As I wrote before, The Professional Developers Conference is the one event each developer has to attend. Windows 7 will become generally available (GA) to the public on October 22nd. With the pre-release veil of secrecy lifted, during this year's PDC we can dive deep (very deep) into Windows 7 to extend our understanding of how Windows 7 works and, even more importantly, how developers can take advantage of all the great new improvements and features Windows 7 has to offer.

Just in case you missed my previous announcement, there is a FREE Windows 7 (seminar) Boot Camp led by top Microsoft Windows experts like Mark Russinovich, Landy Wang, and Arun Kishan. Then, during the PDC proper, we’ll have several deep-dive Windows 7 sessions.

During this year's PDC, we’ll host the Windows 7 Developer Center. The Windows 7 Developer Center gives you the opportunity to test your application on Windows 7, identify and solve problems with a group of consultants, and eventually get your application Logo-certified. Applications can be loaded onto a secure Windows 7 test platform in a private developer lab environment for Logo testing and submission. Our Windows Applications Developer Consultants can also help with Windows Compatibility questions or offer specific guidance for how you can make your application shine on Windows 7. You can pre-book a time slot right away, book a time when you get to the PDC, or just stop by Room 504/505. And guess what? It is all free; all you need to do is register.

Registration

You can pre-register for a 1-hour timeslot in the lab as outlined below. You can also register upon arrival at PDC09 by signing up at the reception station located in Room 504/505, or just stop by to talk about developing applications for Windows 7.

Monday 11/16

10:00 am

11:00 am

1:00 pm

2:00 pm

3:00 pm

4:00 pm

Tuesday 11/17

11:00 am

1:00 pm

2:00 pm

3:00 pm

4:00 pm

5:00 pm

Wednesday 11/18

11:00 am

1:00 pm

2:00 pm

3:00 pm

4:00 pm

5:00 pm

Thursday 11/19

8:30 am

9:30 am

10:30 am

11:30 am

1:30 pm

2:30 pm

 

Getting Started

Logo Test - To help maximize your time in the lab at PDC, we are asking that you run the Logo test and submit the .xml result report to our team for review prior to the event. Our consultants will analyze your results and prepare a report to review with you on-site at PDC.

VeriSign & WinQual IDs – In order to submit your product for Windows 7 Logo, you will need to obtain both of these credentials. Once obtained, you will be able to work directly with a Microsoft consultant through the submission process while on-site at PDC. (More info here - https://winqual.microsoft.com/.)

Follow these simple steps to register and prepare for PDC 2009:

1. Email srglabs@microsoft.com with 3 timeslots in order of preference from those listed above.

2. Download the Logo toolkit from MS Connect and follow the instructions for testing.

3. Send the .xml result report generated by the Logo toolkit to srglabs@microsoft.com for analysis.

4. Sign up for VeriSign & WinQual IDs that will be required for Logo submission by visiting https://winqual.microsoft.com/.

Additional Resources

• For general questions contact srglabs@microsoft.com

• For questions and more details about the Windows 7 Logo Program visit MS Connect

This is a great opportunity to prepare your applications for Windows 7, but there is limited availability so be sure to register early to get your preferred time slot.

You can learn about Windows 7 using the Windows 7 Training Kit for Developers or by viewing Windows 7 videos on Channel 9


Windows 7 At PDC09

The Professional Developers Conference (PDC) is the one event that all developers who use any Microsoft technologies must attend at least once in their professional careers. It’s the flagship event for developers, offering the most comprehensive, future-looking, technically deep, densely-packed set of sessions from Microsoft speakers you can find anywhere. This year’s PDC is no exception and you can expect it to be a very exciting event.

My first PDC was PDC08, held last November at the LA Convention Center. As one of the people at Microsoft who work on Windows 7, I was fortunate enough to be in the loop regarding Windows 7 @ PDC08, and was able to contribute (even if only in a small way) to one of the keynote. During the Day 2 keynote,

image

Steven Sinofsky presented Windows 7 to the world and for the first time people outside of Microsoft saw the new Taskbar, the Windows Ribbon, and witnessed a live multitouch demo. Attendees received a 160G hard drive (makes you wonder what they'll get this year…) with Windows 7 build 6800 (does anyone remember this build number?). The Windows team presented a lot of its technologies in a series of impressive sessions. And since then, through the different versions of Windows--Beta, RC, and RTM--we continued to push new content to help developers ramp up and get ready for Windows 7.

Windows 7 will become “Generally Available” (GA) to the public on October 22nd, exactly two weeks from today, and this year’s PDC takes place right after Windows 7 GA. With the pre-release veil of secrecy lifted, during this year's PDC we can dive deep (very deep) into Windows 7 to extend our understanding of how Windows 7 works and, even more importantly, how developers can take advantage of all the great new improvements and features Windows 7 has to offer.

To start with, on the day before PDC09 starts, there is a FREE Windows 7 (seminar) Boot Camp led by top Microsoft Windows experts like Mark Russinovich, Landy Wang, and Arun Kishan. Then, during the PDC proper, we’ll have several deep-dive Windows 7 sessions.

So here is the first set of Windows 7 sessions that we are announcing:

This first one is probably my favorite topic (I am a geek, what can I say). What could be more important than performance, especially as it relates to Windows 7 and applications running on Windows 7? This has to be a MUST Attend session for any developer who writes any software (native or .NET) for Windows (and not just Windows 7) – this is truly a unique opportunity.

Optimizing for Performance with the Windows Performance Toolkit

The Windows team uses the Windows Performance Toolkit (WPT) to optimize the Windows OS. Come and see how the Windows Performance team used the WPT throughout the Windows 7 development cycle to optimize for customer scenarios and how you can leverage many of its features and capabilities to help you build faster applications on Windows. This session will present case studies that demonstrate how you can use the toolkit to pinpoint areas for improvement in your application and provide you with some best practices to follow in order to create applications with optimum performance.

The next two sessions are also personal favorites (you can’t blame me for loving Windows 7), as I think these technologies represent new levels of user interaction and adaptive user interfaces:

Building Sensor- and Location-aware Applications with Windows 7 and .NET

How many times have you thought to yourself, “My application would be so much better if it knew where the user was?” With Windows 7 and.NET Framework 4.0, you now have the tools at your fingertips to location-enable your applications. Based on the new Location platform for Windows 7, the location API in .NET Framework 4.0 provides a single, consistent API to get you your latitude and longitude regardless of the underlying technology that acquired it—allowing you to focus on creating exciting, differentiated location-aware applications.

Windows Touch Deep Dive

Windows provides applications with a default experience for gestures and touch interaction. This provides applications that you want to go beyond that basic experience with a powerful platform to build upon. This session is targeted at developers interested in building touch-optimized experiences. We’ll look closely at some of the more powerful portions of the Touch platform, like manipulation and inertia processors, as well as cover real-world problems that developers have encountered and overcome. Come help build the next generation of user experiences!

Another highly recommended session is the Windows Ribbon session. Before you dismiss the Ribbon, I suggest you take a second look and read between the lines of the Windows Ribbon native API. There is a lot of very interesting software architecture in the current API that provides a glimpse into tomorrow’s “commanding framework.”

Windows Ribbon Technical Deep Dive

This talk will cover some of the more subtle and complex aspects of ribbon implementation, like designing a great gallery (a critical task for any ribbon), adding an outspace MRU, etc. We will draw from specific experiences with Windows Live and other partners and spread the learning that those teams amassed as Windows Ribbon guinea pigs.

A lot has been said about the update to the Windows 7 graphics stack. This stack plays a major role in the performance improvements Windows 7 offers. You, as a developer, can tap into that user experience and start enjoying a rich and modern graphic framework that pushes GPUs to their limits.

Modern 3D Graphics Using Windows 7 & Direct3D 11 Hardware

Dig deep into the capabilities of Direct3D 11 and Windows 7to gain practical knowledge that will help you push graphics to the limit. Learn about the new tessellation stage in Direct3D 11, which enables an unprecedented level of rendering quality by dynamically generating geometry on the GPU. In addition, see how the multi-core improvements in the Direct3D 11 runtime can help you scale your application to take full advantage of all of the cores on a machine. Finally, take a peek at the power of DirectCompute (the hardware-accelerated general purpose computing technology) in a graphics application context.

Advanced Graphics Functionality Using DirectX

The number of PC configurations is exploding. With both netbooks and high-end desktop systems using the latest in graphics hardware, creating an application that can target all of these systems is getting harder every year. Join us as we explore the many options available in Windows 7 to facilitate graphics development across all kinds of hardware configurations, from low-end integrated GPUs to top of the line discrete GPUs. Learn about Direct3D 10 Level 9, which enables Direct3D 10 applications to run on pretty much every computer in the market today. Check out WARP, our new software rasterizer that lets your application use high-quality graphics even when there’s no graphics card. Finally, learn about Direct2D, DirectWrite, WIC, and the interoperability of Windows 7 technologies for making slick, high-quality graphics for your applications of the future.

The last session for today’s post, but most certainly not the least, is about the Windows API Code Pack for the Microsoft .NET framework. This is a framework that I have a personal interest in and I often blog about. With Visual Studio 2010 and .NET 4, .NET developers have an easier life. Nonetheless, there are still a great number of valuable Windows APIs that are NOT in the framework. This Open Source library provides a good intermediate solution.

Developing with the Windows API Code Pack for .NET Framework

The Windows API Code Pack for Microsoft .NET Framework provides a source code library that you can use to access some new Windows 7 features (and some existing features of older versions of the Windows operating system) from managed code. These Windows features are not available to developers today in the .NET Framework. This session will show you how to access features like taskbar integration, JumpLists, libraries, the sensor platform, Direct2D, and more.


Free Windows 7 Seminar with Mark Russinovich (and Friends)

Have you ever wondered how Windows 7 resumes from sleep in less than 2 seconds? Or how Windows 7 can scale up to 256 cores? Or maybe you just want to want to learn about any Kernel improvements that will make your application run faster with no extra effort from you?

PDC_Win_bootcamp

Well, guess what? On Monday, November 16th, the day before PDC 2009 starts, we are running a FREE Windows 7 Workshop AKA Windows 7 Developer Boot Camp. That is  right, it's FREE for anyone who wants to attend. Windows 7 is one of the most exciting pivotal releases of the year. As part of the wave of activity surrounding the product launch, we're opening up this workshop to anyone who wants to attend - even if you're not able to join the rest of the conference. So, if you live LA, its surroundings, or even the Bay Area, you can attend this workshop for FREE!

Wait a minute! By now, you must be thinking to yourself, “If it is free, it can’t be that good.” Well it turns out that this Windows 7 Developers Boot Camp will include top Microsoft Windows experts like Mark Russinovich, Landy Wang, and Arun Kishan. These are the guys who are behind a large number of the amazing performance improvements in Windows 7, and this is your onetime chance to meet them in person for an intense, deep, and high-quality session. Mark, Landy, and Arun will start by talking about Kernel and architectural improvements, for example, the Kernel Dispatcher Lock, new and even more efficient Windows Memory Management, and Trigger Start Services, among many other topics.

Next, they’ll take a dive deep into the different APIs, paying special attention to the new shell integration points in Windows 7 such as the taskbar, libraries, and search. Right after that, they’ll give some tips for getting the most out of today’s hardware using the Sensor & Location platform, multitouch, and the new graphics libraries (Direct2D, DirectX 11) that take advantage of the GPU.

Regardless of whether you’re a C++, C#, or Visual Basic developer, if you're building a Windows application and you want your application to have the best possible performance, experience, and look-and-feel while running on Windows 7, this event is for you! I know I will be there; what about you?

Register for the PDC Workshop or read more info about the Windows 7 Boot Camp.


Session 0 Isolation

It has been a while since the last blog posting, Windows 7 RTM – Go Get It, and we have a lot of catching up to do.

The Windows 7 GA data is still October 22nd, less than a month away, which means your application should be almost ready for Windows 7. As you prepare your applications for Window 7, be sure to verify that you don’t have any issues with version checking and UAC Data Redirection. This post topic, Session 0 Isolation, is another application compatibility topic that requires our special attention, especially if your applications include services. If your services are working on Windows Vista, most likely they will continue to work on Windows 7 (still you need to test your application fully on Windows 7). However, if you didn’t run the proper compatibility testing on Windows Vista, you might want to take few moments to read this post.

Let’s start with a better understanding of what services are.

What are services?

A service is an integral mechanism built into Microsoft Windows operating systems. You can think of services as “special applications” that run with no regard to the current user context. Services are different from “regular” user applications because you can configure a service to run from the time a system starts up (boots) until it shuts down, without requiring an active user to be present – that is, services can run without having any users logged on.

We like to think about services as running “tasks” for us in the background without interfering with user operations. Services on Windows are responsible for all kinds of background activity that do not involve the user, ranging from the Remote Procedure Call (RPC) service, through Printer Spoolers, to the Network Location Awareness service.

What’s the problem?

Some services may attempt to display user interface dialogs or communicate with user applications. Such functionality is “typical” of Windows XP services, mainly because it is easy to do so. If you happen to own a service that attempts to display some user interface objects, like a dialog box, or tries to communicate with applications you might run into trouble running on Windows 7.

When running a service that is trying to display a dialog box on Windows 7, instead of the desired dialog box, you will see an annoying flashing icon on the taskbar. And, if you press on that flashing icon, you will see a dialog box. To be more specific, when running on Windows 7, your service may experiences one or more of the following symptoms. The service:

  • Is running, but cannot do what it is supposed to do, and just eats CPU cycles and memory
  • Is running, but other processes can't communicate with it and it cannot communicate with the user, or other applications / services
  • Is trying to communicate with user applications through window messages, but the window messages are not reaching their destination
  • Displays a flashing icon on the taskbar indicating the service wants to interact with the desktop

All the above symptoms point to the conclusion that your service is experiencing Session 0 Isolation of Windows 7 Services, that is, the “physical” separation between services and user applications, but more about that in just a bit. First, let’s define the two “buckets of issues” your services may experience when running on Windows 7:

  • The service fails to display a UI or it displays a mitigation UI (or annoying flashing dialog box): When a service attempts to show any user interface element (even if it is allowed to interact with the desktop), a mitigation layer prompts the user with the Interactive services dialog detection dialog box, as shown in the next image. This notification dialog appears on the user’s desktop.  If the user clicks to see “the message”, the display switches to a secure desktop. The user may opt in to see the service UI dialog, but the interruption in workflow makes this a serious application compatibility issue. Furthermore, some users may not react very well to a dialog that blocks your services / application from getting the user input and breaking the flow of the application.

image

  • Objects shared by services and applications become invisible or inaccessible: When an object created by a service is accessed by a standard application (running with standard user privileges), the object cannot be found in the global namespace (that is, it is private to session 0). This means that other applications will not be able to access the so-called “shared object” from the global namespace, and most certainly, not directly from session 0. Additionally, security changes might warrant a situation where even if the object is visible, it is not accessible. This may affect other processes (such as standard user applications) from interacting with your service, again breaking the application flow.

Clearly, Session 0 Isolation has the potential of being a serious compatibility pain. Well, this post should provide you with enough information to identify if your service is at “risk” -- and how to solve the problem. However, I have to remind you that the main reason for isolating services from user application is making it harder for malicious software to run with elevated privileges, which enables them to do far more harm than running as standard user as explained in the following section, thus making Windows much more secure operating system. 

The Reason: Session 0 Isolation of Windows 7 Services

In Windows XP, Windows Server 2003, and earlier versions of the Windows operating system, services and applications run in the same session as the one started by the first user who logs onto the console. This session is called Session 0, and as shown in the following image, prior to Windows Vista, Session 0 included both services and standard user applications.

imageImage source: http://www.microsoft.com/whdc/system/vista/services.mspx

Running services and user applications together in Session 0 poses a security risk because services run with elevated privileges, while user applications run with user privileges (most of which are not admin).This makes the services targets for malicious agents that are looking for mechanisms to elevate their own privilege levels by “hijacking” the services.

Starting with Windows Vista, only services are hosted in Session 0. User applications are isolated from services, and run in subsequent sessions created when users log onto the system: Session 1 for the first logged on user, Session 2 for the second, and so on, as shown in the following image.

imageImage source: http://www.microsoft.com/whdc/system/vista/services.mspx

Entities (applications or services) running in different sessions cannot send each other messages, share UI elements, or share kernel objects without explicitly qualifying them to the global namespace and providing the appropriate access control settings. The following image illustrates this:

image

You can find additional valuable information about this in Impact of Session 0 Isolation on Services and Drivers in Windows Vista (http://www.microsoft.com/whdc/system/vista/services.mspx), an article that is equally applicable to Windows 7.

How can you detect whether your service might experience some of the above-mentioned problems?

So far, we have presented the symptoms associated with Session 0 isolation of Windows services, explained what service isolation is, and how it may affect your services and applications. Below are tests and other actions you can take in order to pinpoint your real problem and start resolving it.

Test #1 – Verifying service (or any other process) session assignment

  1. Launch Process Explorer.
    1. To download or learn more about Process Explorer, see the Process Explorer Web site on Microsoft TechNet.
  2. Ensure that Process Explorer displays all processes:
    1. Click File.
    2. Choose Show Details from All Processes.
  3. Locate the first csrss.exe process, which is a service found under the System Idle Process (see next image), and inspect its properties:
    1. Right-click the process.
    2. Select Properties.
    3. Navigate to the Security tab.
    4. Note the session in which the service runs (typically Session 0) and its integrity level.
  4. Locate the second csrss.exe process, found under the Wininit.exe (see next image), and inspect its properties as you did in step #3:

imageThe left image shows the process properties for the csrss.exe instance that runs at the system integrity level - session 0, while the image on the right shows the process properties for the csrss.exe instance that runs also with System integrity level but in a different session - session 1:

image

If your service is running under Session 0 and under a System integrity level, it will be unable to display UI directly. It is also likely that you will experience problems when sharing kernel objects or files with the service.

Test #2 – Ensuring object accessibility

  1. Launch Process Explorer.
  2. Ensure that Process Explorer displays all processes:
    1. Click File.
    2. Choose Show Details from All Processes.
  3. Locate the suspected service.
  4. If the service contains objects that you know are shared with user applications, inspect their handles in the Handles lower pane (press CTRL+H to see it, or access it from the View menu).
    1. Right-click each suspected handle and select Properties.
    2. Switch to the Security tab to see the users and groups that are allowed to access the object referenced by this handle.

The following image shows an example of a shared object that everyone can access (for the “Synchronize” right) even though it is opened in a system service that runs in session 0

imageThe following image displays an example of a shared object that only administrators and the SYSTEM group can access:

image

Now that you know what the problems could be, what about fixing them?

You've already done the hard part, knowing and understanding that you have a session 0 issue; solving these problems is easy.

Here are some ideas on how to solve the above mentioned problems:

  • If a service needs to interact with the user by sending a message, use the WTSSendMessage function. It is almost identical in functionality to a MessageBox. This will provide an adequate and simple solution to services that do not require an elaborate UI, and is secure because the displayed message box cannot be used to take control of the underlying service.
  • If your service requires a more elaborate UI, use the CreateProcessAsUser function to create a process in the requesting user’s desktop Note that you will still need to communicate between the newly created process and the original services, which is where the next bullet point kicks in.
  • If two-way interaction is required, use Windows Communication Foundation (WCF), .NET remoting, named pipes, or any other interprocess communication (IPC) mechanism (excluding window messages) to communicate across sessions. WCF and Remoting have a better security enforcement that will prompt the user (assuming UAC not shut-off) to elevate if needed.
  • Ensure that kernel objects meant to be shared across sessions have names prefixed with the Global\ string, indicating that they belong in a session-global namespace.

Additional Resources

You can find more-detailed information about this topic in the Windows 7 Training Kit for Developers, including a detailed whitepaper and hands-on-lab. If you want, you can download just the Session 0 Isolation hands-on-lab directly.

Here is some basic information about the tools used in this post:

Process Explorer – a monitoring tool for Windows processes that is able to display process integrity levels and object security information.

 

You can get much more information about this topic and others in Windows 7 topic page on channel 9.

For more Windows 7 Technical content and hands-on experience download the - Windows 7 Training Kit for Developers is also a great place to learn more about this topic


Windows 7 RTM – Go Get It

This is it people. Windows 7 RTM is available for download from MSDN & TechNet sites! If you have a MSDN subscription you can get Windows 7 RTM in English. On October 1st, the remaining languages will be released, for more information read - Windows 7 RTM Available Today for MSDN & TechNet Subscribers. You can also get the Windows 7 SDK  and the RTM version of the Windows API Code Pack for .NET Framework.

Make sure you get them all today to start testing your applications, and to make sure your applications are ready for Windows 7 RTM! Now is the time to work on your applications to make sure they are Windows 7 compatible. On top of that, you can use new Windows 7 features such as the Sensor and Location Platform, Taskbar, Libraries, Multi-Touch, the new Graphics APIs, the Windows Ribbon, and many other important and exciting Windows 7 technologies to make your application shine on Windows 7.

New Windows 7 Training Kit for Developers - Get it NOW!

To help you get your application on Windows 7 as soon as possible, we updated the Windows 7 Training Kit for Developers for the RTM version and gave it a new look and better functionality. You can still find all existing topics such as: Taskbar, Sensor and Location, Libraries and Shell, DirectX, Multi-touch, Ribbon, etc. No dev was left behind! The kit is built for both native Win32 Windows7TrainingKit

C++ developers and .NET developers, so now most topics have multiple labs.We also added 6 new Application Compatibility labs: Version Checking, Data Redirection, UIPI, Installer Detection, Session 0 Isolation, and High DPI, to help you get over the most common application compatibility issues. All the topics in the training kit include additional information like whitepapers, links to MSDN, and links to videos from Channel 9.

 Updated Windows Topic Area on Channel 9

We also gave the Windows topic area on Channel 9 a brand new look and functionality to help you to better choose the right Windows 7 content you need. In the new Windows topic area for Channel 9, you can choose from three main topic areas:

NewC9

While we hope you find all this helpful, this is only the start! We are working on more new and exciting content that will be shipped in the following weeks, so stay tuned.

In the meantime, here is some additional useful information:

  • The Windows page on MSDN is the one-stop shop for Windows client developers
  • At Develop for Windows 7, you can find all the information you need about specific technologies like Direct2D, Taskbar, Sensor and Location, Power Shell 2, Windows Ribbon, and many more
  • Windows Application Compatibility is the one page you want to visit to make sure your application runs properly on Windows 7; it includes content and tools to test and fix many application compatibility issues. Directly accessible from that page, is the Windows 7 Application Quality Cookbook
  • Also still very relevant, is the Windows Vista Application Compatibility Cookbook--most Windows 7 compatibility issues are the direct result of the changes introduced in the Windows Vista timeframe, and are included as topics in this Cookbook (UAC, Session 0 Service Isolation, IE Protected Mode, etc.), which is a great starting point for addressing these issues
  • New Windows 7 videos on the Channel 9 Windows page explore specific features and technologies, and are great “windows” to the Windows engineering team
  • As always, the E7 blog is an amazing source of the engineering back story behind Windows 7
  • Last, but not least, for IT-Pro, we have our SPRINGBOARD SERIES, and edge on TechNet

And, of course, continue to watch for new posts.


Version Checking (Just Don’t Do It)

Version checking is probably one of the most common Application Compatibility issues that both developers and users are facing. This is another post in a series of posts about Getting Ready for Windows 7.

As said, this is probably the most common application compatibility issue that users as well as developers face is when an application fails upon checking the operating system version. A lot can go wrong when version checking is misused. A user might experience a “silent fail” where the application simply fails to load and nothing happens. Or, a user might see a dialog box indicating something to the effect of “you must be running Microsoft Windows XP or later” when in fact, the computer is running Windows 7. Many other consequences to poor version checking can inconvenience users as well.

Applications fail due to version checking for two main reasons:

  • A flaw (bug) in the version checking code, which fails if the minor version is decreased, even if the major version is increased, for example, changing versions from 5.1(Windows XP) to 6.0 (Windows Vista), or if the expected service pack (SP) is not installed, even if you're running a newer operating system (for example, changing versions from Windows XP SP 2 to Windows Vista SP 1). We recommend that you check functionality rather then checking version, as you can read in this post.
  • An intentional blocking that prevents the application from running on operating system versions not tested by its developers. We recommend that you do not block applications from running on future operating systems.

When an application runs on an "incompatible" (due to poor version checking) version of Windows, it will generally display an error message, but it may also exit silently or behave erratically. Often, if we work around the version checking, the application will run well. End-users and IT professionals may apply a fix to let the application think it is running on an older version of Windows.

Working Around The Problem (not really solving the bug)

Compatibility mode: Designed for end users (not for developers to not fix their bugs), compatibility mode is an easy way to work around compatibility issues. When enabled, it applies a set of compatibility fixes that provide a runtime environment more compatible with applications written for older versions of Windows. One of those fixes is the "version lie," which makes the version query functions return the operating system version the user chose in the Compatibility tab of the Properties dialog box instead of the actual Windows version.

To enable compatibility mode:

  • Right-click the executable or shortcut to the executable.
  • Click Properties.
  • Click the Compatibility tab.
  • Enable Run this program in compatibility mode for: and select the operating system version you think the application should be able to run on.
    Some applications consist of several executables. You may need to apply this fix to each one.

image

  • Click OK to close the dialog box.
  • Run the application.

Checking for Features Rather Than Version

As mentioned previously, checking the operating system version is not the best way to confirm that a specific operating system feature is available. This is because the operating system may have had new features added in a redistributable DLL. Rather than using GetVersionEx to determine the operating system platform or version number, it is more effective to test for the presence of the feature itself. For example, we plan to make the Direct2D and DirectWrite APIs and the Ribbon API available in Windows Vista, so there is no need to block your application from using these APIs when running on Windows Vista. You just need to check if these features are available on the Operation System that you are running. If possible, your application should still run if the feature is unavailable, though with reduced functionality or performance.

You can use one of the following techniques to find out if a specific features is available on the given OS.

For Win32 developers:

  • Use LoadLibrary() to load a library which is not yet loaded into your application. If you are interested in a new function of a DLL which is already loaded (for example, kernel32.dll), then call GetModuleHandle() to obtain the module handle. If either of these functions return NULL, then this indicates an error.
  • Use GetProcAddress() to obtain a function pointer. If GetProcAddress() returns NULL, then the function may not exist. Cast the pointer to a function pointer of an appropriate prototype. Some functions, although they exist may actually be stubs that return a "not implemented" error. Be such to check for such errors.

Windows 7 introduces a new timer API - SetWaitableTimerEXProc, which adds one more input variable to the regular SetWaitableTimerProc. The TolerableDelay lets you specific a time tolerance window in which the timer can expire. This is a new in Windows 7, that we will use to demonstrate how to check for feature.

      // define function pointer type
    typedef BOOL (WINAPI *SetWaitableTimerExProc)(
      __in  HANDLE hTimer,
      __in  const LARGE_INTEGER *lpDueTime,
      __in  LONG lPeriod,
      __in  PTIMERAPCROUTINE pfnCompletionRoutine,
      __in  LPVOID lpArgToCompletionRoutine,
      __in  PREASON_CONTEXT WakeContext,
      __in  ULONG TolerableDelay
    );

    LARGE_INTEGER liDueTime;
    liDueTime.QuadPart = 0;
    nt period = 1000;
    unsigned int tolerance = 1000;
    HANDLE hTimer = // Get timer handle

    REASON_CONTEXT reasonContext = {0};
    reasonContext.Version = 0;
    reasonContext.Flags = POWER_REQUEST_CONTEXT_SIMPLE_STRING;
    reasonContext.Reason.SimpleReasonString = L"MyTimer";

    // Get module handle to a module which is already loaded
    HMODULE hKernel32Module = GetModuleHandle(_T("kernel32.dll"));
    if (hKernel32Module == NULL)
        return FALSE;

    // Get Address of function
    SetWaitableTimerExProc pFnSetWaitableTimerEx =
    (SetWaitableTimerExProc) ::GetProcAddress(hKernel32Module,     
        "SetWaitableTimerEx");

    // Check if the function exists    
    if (pFnSetWaitableTimerEx == NULL)
        return FALSE;

    // Call function
    if (!pFnSetWaitableTimerEx(hTimer, &liDueTime, period, NULL, NULL,
            &reasonContext, tolerance)
    { // handle error }

Alternatively, you may use DLL delayed loading and call functions in a __try...__except block. (For more information, see Linker Support for Delay-Loaded DLLs.)

For COM APIs, handle errors returned by CoCreateInstance and QueryInterface.NET framework applications that call Win32 APIs via P/Invoke should handle EntryPointNotFoundException and DllNotFoundException exceptions.

 

If You Must Check OS Version Number

Identifying the current operating system is not the best way to determine whether a particular operating system feature is present. However, if you can’t design your application to check for specific feature availability and the only way to ensure compatibility is through version checking, then please consider the following.

For native applications, you will need to ensure your application's logic will work with newer versions of Windows. Please DO NOT BLOCK on version change! The following is a Win32 code example that uses GetVersionEx. If the major version is greater than 5 (Windows Vista, Windows® Server 2008 R2 and Windows 7), the check passes. If it equals 5, then the minor version should be 1 or greater (Windows XP or Windows Server 2003).

#include <windows.h>
#include <stdio.h>

void main()
{
    OSVERSIONINFO osvi;
    BOOL bIsWindowsXPorLater;

    ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

    GetVersionEx(&osvi);

    bIsWindowsXPorLater = 
 ( (osvi.dwMajorVersion > 5) ||
       ( (osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion >= 1) ));

    if(bIsWindowsXPorLater)
  printf("The system meets the requirements.\n");
    else printf("The system does not meet the requirements.\n");
}

However there is a better way to verify the minimum OS version required using VerifiyVersionInfo(). This function compares a set of operating system version requirements to the corresponding values for the currently running version of the system. The following code example uses VerifyVersionInfo to check the operating system version against minimal requirements (Windows XP SP2):

#include <windows.h>
BOOL Is_WinXP_SP2_or_Later () 
{
   OSVERSIONINFOEX osvi;
   DWORDLONG dwlConditionMask = 0;
   int op=VER_GREATER_EQUAL;

   // Initialize the OSVERSIONINFOEX structure.

   ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
   osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
   osvi.dwMajorVersion = 5;
   osvi.dwMinorVersion = 1;
   osvi.wServicePackMajor = 2;
   osvi.wServicePackMinor = 0;

   // Initialize the condition mask.

   VER_SET_CONDITION( dwlConditionMask, VER_MAJORVERSION, op );
   VER_SET_CONDITION( dwlConditionMask, VER_MINORVERSION, op );
   VER_SET_CONDITION( dwlConditionMask, VER_SERVICEPACKMAJOR, op );
   VER_SET_CONDITION( dwlConditionMask, VER_SERVICEPACKMINOR, op );

   // Perform the test.

   return VerifyVersionInfo(
      &osvi, 
      VER_MAJORVERSION | VER_MINORVERSION | 
      VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
      dwlConditionMask);
}

In this code you can see how we use the VerifyVersion with a set of conditions to return TRUE incase we run on any OS grater than Windows XP Service Pack 2.

 

For .NET Framework developers, use the ==, !=, <=, <, >, >= operators of the Version object returned by Environment.OSVersion.Version:

// This code checks if the OS is at least Windows XP
  if (Environment.OSVersion.Version < new Version(5, 1))
  {
        MessageBox.Show("Windows XP or later required.",
         "Incompatible Operating System", MessageBoxButtons.OK,
                MessageBoxIcon.Error);
        return;
  }

It is highly recommended that you don’t check for version at all and try looking to work with features. It will prove valuable for the future…

Just incase you want to read more, here are some useful links

You can also download a HOL and code sample for this topic.


User Account Control Data Redirection

To making sure your application is ready (compatible) for Windows 7, I am going to start providing additional information about the few compatibility topics we introduced in the “Is Your Application Ready for Windows 7 RTM?” post. This post focuses UAC Virtualization or more known as Data Redirection.

What Are You Talking About?

Today, many applications are still designed to write files to the Program Files, Windows directories, or system root (typically the C drive) folders. Some applications are designed to update Microsoft® Windows registry values, specifically values in HKLM/Software. But there is one problem: the files or registry values are not created or updated. You may ask, “What’s going on? My application goes through the code and does not report an error. So where are my files?”

To be specific, you may experience one or more of the following symptoms:

  • Your application writes to Program Files, Windows directories, or the system root (typically the C drive) folders, but you can't find your files in these locations
  • Your application writes to the Windows registry, specifically to HKLM/Software, but you can't see the registry updates
  • You switch to another user account, and your application is unable to find files that were written to Program Files, Windows directories, or the system root (typically the C drive) folders, or it finds older versions of these files
  • After turning User Account Control (UAC) on or off, your application is unable to find files in the Program Files or Windows directories

If this happens to your application, it is experiencing UAC Virtualization (AKA Data Redirection). The following information provides you with everything you need to know in order to detect this application compatibility problem, offers some solutions, and provides additional information about the specific nature of the compatibility problem.

The Real Issue: UAC Virtualization

Prior to Windows Vista, administrators typically ran applications. As a result, applications could freely read and write system files and registry keys. If standard users ran these applications, they would fail due to insufficient access. Windows Vista improved application compatibility for standard users by redirecting writes (and subsequent file or registry operations) to a per-user location within the user’s profile.

For example, if an application attempts to write to C:\Program Files\Contoso\Settings.ini, and the user does not have permissions to write to that directory (the Program Files), the write operation will be redirected to C:\Users\Username\AppData\Local\VirtualStore\Program Files\Contoso\settings.ini. If an application attempts to write to HKEY_LOCAL_MACHINE\Software\Contoso\ in the registry, it will automatically be redirected to HKEY_CURRENT_USER\Software\Classes\VirtualStore\MACHINE\Software\Contoso or HKEY_USERS\UserSID_Classes\VirtualStore\Machine\Software\Contoso.

The following figure illustrates the two components of the Windows Virtualization process: file virtualization and registry virtualization:

image To learn more about UAC virtualization and new UAC technologies, see “New UAC Technologies for Windows Vista” at http://msdn.microsoft.com/en-us/library/bb756960.aspx.

Solution

Virtualization is intended only to assist in application compatibility with existing programs. New applications designed for Microsoft Windows 7 should NOT perform write operations to sensitive system areas, nor should they rely on virtualization to provide redress for incorrect application behavior. Always develop applications for use with standard user privileges and don’t count on the application running under administrator privileges. Test your application with standard user privileges and not administrator privileges.

If you are experiencing UAC virtualization with applications developed prior to Windows 7, re-design your applications to write files to the appropriate locations. When updating existing code to run on Windows 7, you should:

  • Ensure that during run-time, applications store data only in per-user locations or in computer locations within %alluserprofile% that have properly set access control list (ACL) settings. For more information about ACLs, see Access Control Lists.
  • Determine the known folder to which you want to write the data files. Generic data used by all users should be written to a global public location that is shared by all users. All other data should be written to a per-user location.
    • Generic data files can include, but are not limited to log files, settings files (INI/XML), saved state applications such as saved games, and so on
    • User documents are different; they should be saved to the Documents folder (or to a location the user specifies)
  • Ensure that you do not hard-code paths once you have determined the appropriate locations. Instead, use one of the following programming models and APIs to retrieve the correct paths of specific Windows known folders:
    • C/C++ native applications: Use the SHGetKnownFolderPath function that retrieves the full path of a known folder identified by the folder's KNOWNFOLDERID, a GUID parameter indicating the known location you would like to obtain:
      • FOLDERID_ProgramData – Shared program data directory for all users
      • FOLDERID_LocalAppData – Per-user program data directory (non-roaming)
      • FOLDERID_RoamingAppData – Per-user program data directory (roaming)
    • Managed Code: Use the System.Environment.GetFolderPath function. GetFolderPath takes a parameter indicating the Known Location you would like to obtain
      • Environment.SpecialFolder.CommonApplicationData – Shared program data directory for all users
      • Environment.SpecialFolder.LocalApplicationData – Per-user program data directory (non-roaming)
      • Environment.SpecialFolder.ApplicationData – Per-user program data directory (roaming)
    • If none of the above-mentioned options are available, use the environment variable:
      • %ALLUSERSPROFILE% – Shared program data directory for all users
      • %LOCALAPPDATA% – Per-user program data directory (non-roaming) - Windows Vista or later
      • %APPDATA% – Per-user program data directory (roaming) - Windows Vista or later

Steps to Determine the Most Appropriate Solution

So far, we have presented the symptoms associated with UAC virtualization, explained why redirection is taking place, and suggested a solution. This section contains tests and procedures you should perform in order to pinpoint the real problem and plot a way to resolve it.

Test #1:

  • Launch the application with standard user privileges
  • Run through the scenario that results in a write operation to any given protected folder such as the Program Files or system root (C:\) directories
  • Expected results: The application “succeeds” in writing the file to the protected folder; however, you can't find the file in the expected location
  • Conclusion: This suggests that UAC data virtualization is redirecting the file to a different location

Test #2:

  • Using Windows Explorer, search for your files in the VirtualStore folder
    • The VirtualStore folder is a folder in your profile which stores redirected files
    • The VirtualStore folder’s name and location are subject to change in later versions of Windows
  • First, attempt to find it under %localappdata%\VirtualStore
  • If you are unable to find it there, try issuing dir %userprofile%\yourfile.dat /s /a at a command line (usually found C:\Users\<user name>\AppData\Local\VirtualStore)
  • Expected results: You should find your file at the virtual store folder or sub folders
  • Conclusion: This is proof that UAC virtualization is taking place

Test #3

  • Log in as an administrator and launch your application with administrator privileges.
    • To launch the application with administrator privileges, right-click the file executable and select Run as Administrator
    • When an application runs with administrator privileges, virtualization is turned off, and the application now has sufficient privileges to write to the protected folders
  • Do not rely on permanently marking your application to require administrator privileges as a way to bypass virtualization, as doing so will leave the system more vulnerable to attack, will prevent the application from running with limited or standard user privileges, and will needlessly annoy users with a UAC prompt
  • Expected results: The application succeeds in writing the file to the protected folder, and you can find the file at the expected location
  • Conclusion: Running the application with administrator privileges turns off virtualization and grants privileges

Test #4

  • Launch Process Monitor (ProcMon)
  • Configure filtering to show only file operations and only those operations performed by your process
    • When you launch Process Monitor, the Process Monitor Filter dialog box appears
  • Add the following entry to the filter: "Column=Process Name, Relation=is, Value=YourApp.exe, Action=Include"image
  • To invoke the Process Monitor Filter dialog box again, click this toolbar button image
  • After clicking OK, configure Process Monitor to log only file events by enabling the following toolbar buttons as shown: image
  • Press CTRL-X to clear the log; press CTRL-E to toggle logging on/off
  • Expected results: You will see file operations whose results are REPARSE; the next line (with result SUCCESS) will usually be the redirected operation:

image

 

 

  • Double-click the line representing the operation with REPARSE as the result and click the Stack tab to show the call stack at the time of the operation:

image

  • The pink K and blue U letters on the left of each stack frame show whether the stack frame is in kernel mode (K) or in user mode (U);in this case, we are interested only in user-mode stack frames
  • In this example, the SaveFile function (at frame 21) in BrokenAppNative.exe is the one performing the operation which will be redirected
  • You should configure symbols for a more meaningful display' for more information about configuring symbols, refer to the Debugging Tools for Windows Web site
  • Conclusion: This test proves that UAC Virtualization did take place and shows you what operations in your application need to be corrected

Task #5

  • Add a manifest to your application which contains a UAC directive
    • This will mark your application as UAC-aware and will disable UAC virtualization
    • A manifest is an XML document that developers embed as a resource in a DLL or .exe file, but can be a standalone file named YourApp.exe.manifest or YourDLL.dll.manifest
    • Manifests can contain a variety of information that usually pertains to application compatibility, such as the exact version of Visual C++ runtime to load, the version of Common Controls Library to load, as well as UAC settings
    • Read more about UAC settings in the manifest in the Windows Vista Developer Story: Create and Embed an Application Manifest (UAC)
  • Expected results: The application now fails to write to any of the protected folders, returning an “access denied” error
    • This is a GOOD result, because the UAC data virtualization didn’t kick into action
    • As the developer, you should be able to recognize this (because you marked the application as UAC-aware in the manifest) and avoid writing to any of the protected areas
  • Conclusion: Windows enables virtualization because the application isn’t marked as UAC-aware. Marking your application as UAC-aware disables virtualization. If your app tries to write to protected store while marked as UAC-aware, you will get an access denied exception

Hands On Labs and Additional Material

you can download this doc, a presentation describing UAC Virtualization, and two full hands on labs on this topic, one for managed code and one for native, from here.

Tools

In order to detect UAC virtualization we use the following tools:

  • Process Monitor, a free and advanced Microsoft tool that monitors and logs file system, registry, network, and process activity
  • Standard User Analyzer, part of the Microsoft Application Compatibility Toolkit, is a free tool that monitors resource (file, registry, and others) usage of a given application and reports activity that is responsible for Standard User problems

Additional Resources


Windows 7 Taskbar Dynamic Overlay Icons and Progress Bars

We covered the basics of the Windows 7 Taskbar in Developing for the Windows 7 Taskbar – Application ID, and how you can create a Jump List for your application in Developing for the Windows 7 Taskbar – Jump into Jump Lists – Part 1, Part 2, and Part 3). In this post, we will explore how you can leverage the cool Taskbar functionality of dynamic overlay icons and multi-state progress bars.

A central Windows 7 tenet is that the "User Is in Control"; that is, we empower users to take ownership of their desktop looks and functionality. From little things, like allowing users to arrange their Taskbar icons as they see fit, to enabling users to control the number of icons on the Taskbar. Windows 7 “removed” the System Tray Icon area. By default, almost all the tray icons are concealed. Consequently, it is safe to assume that large number of the notification balloons will also not be visible and most users will not see them. You can read more about the updates to the Notification Area here. To compensate for this lack of notification, Windows 7 Taskbar offers Overlay Icons and Progress Bars. By using overlay icons and progress bars, your application can provide contextual status information to the user in spite of the lack of a System Tray Icon area and even if the application’s window does not display. The user doesn’t even have to look at the thumbnail or the live preview of your app – the Taskbar button itself can reveal whether you have any interesting status updates. This functionality is part of our commitment to provide users with easily accessible information about an application's status without any extra clicking.

Overlay Icons

The ITaskbarList4 interface, specifically its SetOverlayIcon function, exposes the native overlay functionality. The function takes a window handle, an icon handle, and optional description text, as you can see in the following code snippet.

HICON hIcon = NULL; // for IDM_OVERLAY_CLEAR
hIcon = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_OVERLAY1));
// Set the window's overlay icon, possibly NULL value
g_pTaskbarList->SetOverlayIcon(hWnd, hIcon, NULL);
if (hIcon) {
// need to clean up the icon as we no longer need it
DestroyIcon(hIcon);
}

Make sure you obtain ITaskbarList3 *g_pTaskbarList = NULL;as we did before, and CoCreate it:

CoCreateInstance(
CLSID_TaskbarList,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&g_pTaskbarList));
When running the above code in the proper context (you can download the application) the result looks like the following pictures. On the left, you see the application without any overlay icons, and on the right you can see the application with a red icon overlay.

image The managed wrapper for this feature resides in the Taskbar class that is part of the Windows API Code Pack for the .NET Framework. All that you need to do is use the OverlayImage property (Taskbar.OverlayImage). Simply call:

Taskbar.OverlayImage = 
new OverlayImage(TaskbarDemo.Properties.Resources.Red, "Red");

Doing so allows you to provide an OverlayImage for the taskbar button. The TaskbarDemo project is a WinForms demo, and you can find the above code in the TaskbarDemoMainForm.cs.

It’s equally easy to provide an extension method that does this to a WPF Window. Note that the only thing that you need to do is get the right icon, which is easy using .NET resources.

Progress Bars

If you already use a standard progress bar in your application’s top level window, the DMW will pick it up and, by default, display its progress as an overlay on top of your application. However, you can programmatically control the progress bar behavior on your application’s icon.

The native functionality is again found in the ITaskbarList3 interface, this time in the SetProgressState and SetProgressValue functions. The functions are quite self-explanatory. You can set the progress bar’s state (SetProgressState) to, for example, indeterminate or error, and use SetProgressValue to set the progress value. The following code snippet illustrates how to use these functions:

case WM_TIMER:
g_nProgress++;
if (g_nProgress == 1)
{
// First time through, so we'll set our progress state
// to be indeterminate - this simulates a background
// computation to figure out how much progress we'll need.
g_pTaskbarList->SetProgressState(hWnd, TBPF_INDETERMINATE);
}
else if (g_nProgress == MAX_PROGRESS_IND)
{
// Now set the progress state to indicate we have some
// normal progress to show.
g_pTaskbarList->SetProgressValue(hWnd, 0, MAX_PROGRESS_NORMAL);
g_pTaskbarList->SetProgressState(hWnd, TBPF_NORMAL);
}
else if (g_nProgress > MAX_PROGRESS_IND)
{
if (g_nProgress - MAX_PROGRESS_IND <= MAX_PROGRESS_NORMAL)
{
// Now show normal progress to simulate a background
// operation
g_pTaskbarList->SetProgressValue(
hWnd,
g_nProgress - MAX_PROGRESS_IND,
MAX_PROGRESS_NORMAL);
}
else
{
// Progress is done, stop the timer and reset progress
// state
KillTimer(hWnd, g_nTimerId);
g_nTimerId = 0;
g_pTaskbarList->SetProgressState(hWnd, TBPF_NOPROGRESS);
MessageBox(hWnd, L"Done!", L"Progress Complete", MB_OK);
}
}
break;

Note that on the first timer tick, we set the progress bar to TBPF_INDETERMINATE, and only after that did we set it to TBPF_NORMAL, which set the progress indicator to grow in size from left to right in proportion to the estimated amount of the operation completed.

For managed code, we use the Windows Code Pack API. Much like the native progress bar, the managed code Taskbar class includes a progress bar property (it is in its own a class), which allows you to set current value, max value, and statethe progress bar state. The progress bar states (found in the TaskbarButtonProgressState class) are:

  • NoProgress –equal to the TBPF_NOPROGRESS native state
  • Indeterminate –equal to the TBPF_INDETERMINATE native state
  • Normal –equal to the TBPF_NORMAL native state
  • Error –equal to the TBPF_ERROR native state
  • Paused –equal to the TBPF_PAUSED native state

You can find a WinForms demo in the TaskbarDemo project and in the TaskbarDemoMainForm.cs, you can find the UpdateProgressBar function that is called by a timer to update the progress bar.

Taskbar.ProgressBar.State = 
(TaskbarButtonProgressState)Enum.Parse(
typeof(TaskbarButtonProgressState),
(string)comboBoxProgressBarStates.SelectedItem);

if (Taskbar.ProgressBar.State != TaskbarButtonProgressState.Indeterminate)
Taskbar.ProgressBar.CurrentValue = progressBar1.Value;

As you can see, the code enables you to choose the state of the progress bar. Changing it to the error state turns the color of the progress bar on the Taskbar Icon to red.

The icing on the Taskbar progress bar "cake" is that you get this functionality FOR FREE if you use the standard progress dialog for file operations. (As we advance in this series, you’ll see that you get lots of functionality for free if you follow the standard guidelines of Windows programming.) For example, if you invoke a file operation using the SHFileOperation API or IFileOperation interface, the Taskbar button progress bar automatically displays the progress information (including errors) of that operation. This is what Windows Explorer does with great success.

Original post from Sasha Goldstein



Is Your Application Ready for Windows 7 RTM?

Yesterday Windows 7 completed a major milestone--release to manufacturing (RTM)! And in three months time – on October 22nd – Windows 7 will be available for everyone to enjoy. Excitement about the upcoming public release of Windows 7 has been growing for months and expectations are for a much quicker adoption rate than what we saw with the previous Windows version.

As we approach October 22nd you need to ask yourself: Is your application ready for Windows 7? What will happen when end users install your application on Windows 7? Will your application run? Will your application behave like a Windows 7 first class citizen? Will users see any difference when running applications on Windows 7 versus Windows Vista or XP? October 22nd is just around the corner and we are here to help you answer, “YES!” to these questions and be able to state with confidence that, “Absolutely, my application rocks on Windows 7.” We want to help your users get the best possible Windows 7 experience from your application starting on Day 1.

All this sounds great, but what steps do you need to take in order to be able to say: “Yes my application is a first-class Windows citizen”? Is there a check list? You bet!

You need to do three things to ensure a smooth transition:

  1. Make sure your application is Windows 7 compatible
  2. Optimize your application experience and performance for Windows 7
  3. Provide new and exciting user experiences with Windows 7 

    Make sure your application is Windows 7 compatible

    Before considering using any new Windows 7 features, make sure your application is compatible with Windows 7. There is no escape from this; it is essential that you make sure that your application runs well on Windows 7. There is nothing worse for an end user than to be excited about the new Windows 7 operating system just to discover that a favorite application doesn’t perform properly. A bad user experience hurts everyone--which is why you have to make sure your application installs and runs on all Windows 7 versions (including E - Windows 7 E Best Practices for ISVs) and supports both 32- and 64-bit versions.

    If your application is compatible with Windows Vista you are in a good shape! We expect most applications that run on Windows Vista to run on Windows 7. Obviously, you can’t take this for granted and must check (and double check) that your application truly is compatible with Windows 7. There are a few differences between Windows Vista and Windows 7 that can affect specific application functions, so if you haven’t checked the Windows 7 Quality Cookbook lately, we highly recommend that you do so.

    If your application was designed for Windows XP (or earlier Windows versions), and you haven't confirmed its compatibility with Windows Vista, there are a few areas (for example, UAC), that you should especially note. It is important to keep in mind that there is no one silver bullet for application compatibility issues. Each application comes with its own set of issues that are dependent on specific implementation details. The Windows Vista Application Compatibility Cookbook is still very relevant for Windows 7, as 99% of its topics apply to Windows 7. With that said, a few topics rise above the others. The following seven areas represent about a large number of the reported application compatibility problems.

    • Version Checking – by far the top application compatibility problem. Ever get a message from an application saying, “Requires Windows XP or higher” when you are running on Windows 7? If so, you hit a version checking issue. You can read more about this topic - Application Compatibility: Operating System Versioning
    • Data Redirection – beginning with Windows Vista, standard users have restricted access to certain files, folders, and registry keys. When an application is trying to write to these locations, it gets redirected to somewhere else. Most of the time this is transparent to both users and application developers, but sometimes it is not and that lead to some very interesting results. You can read about this topic - Common file and registry virtualization issues in Windows Vista
    • IE Protected Mode – starting with Windows Vista, by default IE runs with lower privileges. This usually means that some ActiveX controls that work on Windows XP don’t work on Windows Vista and Windows 7. Need more information, you can read Protected Mode in Vista IE7 (and yes this is still applicable for IE8.)
    • Session 0 Isolation - in Windows Vista, services run in their own session (session 0) and not in the user session(s) (session 1 and above). This security boundary protects the system from many vicious attack vectors and is absolutely necessary. However, it also introduces communication problems between services and application like blocking your messages! You can read more about this topic -  Modifying the Mandatory Integrity Level for a Securable Object in Windows Vista
    • Installer Detection – starting with Windows Vista, the OS automatically tries to detect if a given application is an installer application, which usually means that the application requires elevation to administrator privileges. However, sometimes these heuristics can cause problems. Interested in additional information, read about The Windows Vista and Windows Server® 2008 Developer Story
    • User Interface Privilege Isolation – this prevents an application (process) from sending messages to another process with higher privileges even if running under the same user's account. While this protects from shatter attacks, it can also break some applications.
    • High DPI –during install, Windows 7 automatically detects whether your screen supports High DPI. If it does, Windows 7 automatically sets the screen resolution to High DPI. If your application is not High DPI aware, this may cause some display issues (like text clipping). Read more about Ensuring your application displays properly on High-DPI Displays

    In the following weeks, we will address in detail each of the above topics to help you get ready for Windows 7.

    Optimize your application experience and performance for Windows 7

    After verifying that your application can install and run on Windows 7 without any problems, it is time to step up and optimize your application’s user experiences and performance while running on Windows 7. Do this by taking advantage of the great new features offered with Windows 7. These include new user interface innovations like the Taskbar and Libraries, to more fundamental features like Trigger Start Services or the new Troubleshooting platform. By optimizing your application for Windows 7, you can make sure that your end user's experiences when running your application on Windows 7 surpasses their expectations. Users will expect applications to work properly with the Taskbar (just one example); but if your application is not optimized for the new Windows 7 Taskbar experience, end users might just notice that.

    When you're ready to optimize your application for Windows 7, you might consider using one or more of the following features:

    • Taskbar – The new Taskbar in Windows 7 provides more information to the user in more intuitive ways, with features like Jump Lists that helps users quickly “jump” into where they want to go. You can read more Developing for the Windows 7 Taskbar – Application ID.
    • Libraries Libraries are the primary entry points to user data in Windows 7. A Windows 7 Library is a user-defined collection of content that represents the user’s data independently from the folder hierarchy. Users can unify and flatten the folder hierarchy by aggregating any number of physical locations (on their local machine or on remote machines) into a single view – which is the library. You can read more - Windows 7 Programming Guide – Libraries.

    image 
    • Trigger Start Services – The Windows 7 Service Control Manager has been extended so that a service can be automatically started and stopped when a specific system event, or trigger, occurs on the system. Trigger-start capabilities remove the need for services to start up automatically at computer startup and then poll or wait for an event to occur, such as a device arrival. More about this topic – Service Trigger Events.
    • Power Optimization – Windows 7 provides the infrastructure and tools that make it easy for developers to determine the energy impact of their applications. A set of event callbacks enable applications to reduce their activity when the system is on battery power and automatically scale up when the system is on AC power.
    • Troubleshooting Platform – Windows 7 delivers a comprehensive and extensible Troubleshooting Platform that uses a PowerShell-based mechanism to troubleshoot and resolve problems. The Troubleshooting Platform seamlessly integrates with the Windows 7 PC Solution Center, enabling other applications to execute diagnostics in a similar manner as part of their PC management regimen. Read more about Windows Troubleshooting Platform.

    image

    • Windows Error Reporting - Windows Error Reporting (WER) is a set of Windows technologies that capture software crash data and support end-user reporting of crash information. Through Winqual services, software and hardware vendors can access reports in order to analyze and respond to these problems. This set of tools provides amazing real-time information about the quality of your software and can help facilitate software updates and patches. Get Started with Windows Error Reporting.
    • I/O Optimization – I/O prioritization improves the responsiveness of the system without significantly decreasing the throughput of the system. If you have any I/O-bound long services that you can run in the background, the user will be thankful. Non-I/O optimized applications tend to hug the I/O and put an extra burden on the system. If your application optimizes the I/O for non critical application services, it can dramatically improve the overall system behavior.
    • Restart Manager – This technology allows automatic post-crash restarts as well as application and operating system updates without rebooting the entire machine. When you implement this functionality, you get a second chance to save critical information if your application crashes. Windows will automatically restart your application and try to reload the information the user just used. This same technology facilitates updating most applications and the operating system without the need to reboot. If a reboot is needed, then Windows will make sure your application restarts and returns to its latest state

    Provide new and exciting user experiences with Windows 7

    Once your application has passed the first two steps, you can really differentiate your it by creating new and exciting user experiences. Windows 7 enables developers to create distinctive and intuitive applications that significantly enhance discoverability, usability, and sheer enjoyment. New methods of desktop integration put application functionality right at the user’s fingertips. New Touch APIs enable natural interactions through multitouch and finger-panning gestures. Rapid advances in hardware and software technology are also driving higher-fidelity user experiences. Windows 7 brings these advances under developer control with new and flexible APIs that take full advantage of the technology, while making it even easier to develop compelling applications.

    Windows 7 includes many new features that can make your application shine, raising it above the competition. When you think about creating new and exciting user experiences, consider using one or more of the following features:

    • Ribbon – Windows 7 features the Ribbon interface from Office 2007 throughout the operating system, enabling improved user interface development on the platform. This means that developers can eliminate much of the drudgery of Win32 UI development and deliver a rich, graphical, animated, and highly familiar user interface by using the markup-based UI and a small, high-performance, native code runtime.

    image 

    • Multitouch & Ink – Windows 7 features improved touch and gesture support, empowering developers to quickly and easily create unique application experiences that go beyond simple mouse pointing, clicking, and dragging. The new multi-touch APIs support rich gestures, such as pan, zoom, and rotate. All gestures provide direct visual feedback, and interact with underlying content in a natural and intuitive manner.
    • Sensor and Location Platform - Windows 7 has changed how developers use sensors. It includes native support for sensors, expanded by a new development platform for working with sensors, including location sensors (such as GPS devices) and sensors (such as an ambient light sensor or a temperature gauge), to create environmental awareness in Windows applications. Location sensors can unlock new opportunities for location-based services.
    • New Graphics Stack – Windows 7 puts new graphics capability into the hands of application developers through a new set of DirectX APIs. Win32 developers can take advantage of the latest innovations in GPUs to add fast, scalable, high-quality, 2D and 3D graphics, text, and images to their applications.

    image

    • Media Platform – Media Foundation and DirectShow® provide the basis for media support in Windows. Media Foundation was introduced in Windows Vista as the replacement for DirectShow. In Windows 7, Media Foundation has been enhanced to provide better format support, including:
      • MPEG-4,
      • Support for video capture devices and hardware codecs, including H.264 video, MJPEG, and MP3
      • New sources for MP4, 3GP, MPEG2-TS, and AVI
      • New file sinks for MP4, 3GP, and MP3

    And for developers Windows 7 adds new high-level APIs that make it much simpler to write media applications.

  1. Federated Search – Windows 7 supports searching for documents beyond the user’s own PC. Developers and IT professionals can enable their search engines, document repositories, Web applications, and proprietary data stores to be searched from Windows 7 without needing to write and deploy client code. This enables end users to search their corporate intranet or the Web as easily as they can search their local files—all from within the same familiar Windows interface.
  2. Device Stage Integration – Windows 7 combines software and services to create exciting new experiences for mobile phones, portable media players, cameras, and printers. Windows 7 makes it easier to use these devices directly from the Windows desktop. It also provides device makers with prominent placement on the Windows desktop, with branding opportunities and a simple interface for presenting the functionality and services that the device supports.

    I hope this post give you enough to start work with, making sure your application rocks on Windows 7!


  3. 7 Ways to Get Free Tickets to PDC 2009 Plus up to $17,777

    Do you want to win a free trip to Los Angeles and a free ticket to PDC 2009? Do you think you have what it takes to win $17,777? Do you think you can write an amazing Windows 7 application?

    Well, if your answer to any of the above question is "Yes!" then say hello to the Code7 Contest. The Code7 contest is where your application design ingenuity gives you the opportunity to get millions of eyes on your work, plus a trip to LA for PDC09, and up to $17,777 in cash!

    clip_image002

    Code7 is a special coding contest for developers. It is a great opportunity to show the world your creativity and coding powers. It is a way for you to cash in on your knowledge and skills.

    This is not just another standard code contest; this contest gives the finalists the opportunity to present their application at PDC 2009 in LA. The first prize is a real gem: $17,777 in cash, the opportunity to present the application to Microsoft executives at PDC 2009, plus worldwide interest in your application including a massive “marketing bump” for your application.

    To enter, you must:

    Build an original, consumer-oriented client application prototype that runs natively on Windows 7 (for example Win32, WPF, MFC or WinForms – not an Air application or just a gadget) and addresses one or more of the following topic categories:

    • Simplify My Life
    • More Media, More Places
    • Gaming
    • Work From Anywhere
    • Safeguard Your Work
    • Applications for a Better Tomorrow

    The application must use at least one of the following Windows 7 technology features; however, judging will give more weight to entries that take advantage of more than one of these features:

    • Libraries
    • Windows Touch
    • Shell Integration
    • DX11 (DirectX 11)
    • Sensor and Location Platform

    So if you have being following my blog you have some advantage.

    The contest has several stages and few rules you need to be aware of:

    • To enter this contest you must create and submit a video in which you describe and demonstrate your application.
    • The first qualifying round starts at 12:00 a.m. Pacific Time (PT) on July 13, 2009, and ends at 11:59 p.m. PT on October 10, 2009 (“Entry Period”). You will be able to able to submit your video until midnight October 10, 2009. Your entry will be included in a pool with all eligible entries based on your geographical region.
    • Entries received by 11:59 p.m. PT on August 15, 2009, will be eligible to win an “Early Bird” prize described in the Winner Determination section below.
    • Following the close of the first qualifications, a panel of judges will select two runner-up winners and one Finalist from each Region.
    • Following judging, Microsoft will notify all winners and finalists and provide instructions for submitting their applications for evaluation.
    • Finalists will be invited to present their applications to a panel of judges at the Microsoft Partner Developer Conference 2009 (PDC09) in Los Angeles, CA, USA.

    For the complete contest rules and legal notice, please refer to the “RULES” section on the Code7 Contest Web site - https://www.code7contest.com/.

    So, what are you waiting for? Get going and start working on your Windows 7 application!


    Windows 7 E Best Practices for ISVs

    We are intent on providing people with the best possible experience using their PCs with Windows. Building on that important principle, we will ship the same version of Windows 7 in Europe as in rest of the world on the  worldwide launch date of 22 October, 2009. This version of Windows 7 includes Windows Internet Explorer 8 to help people get the most from their PCs and the Internet.

    We will not ship E editions of Windows 7, which would not have included Internet Explorer.  Customers who pre-order Windows 7 will receive versions of the product that include Internet Explorer. Customers participating in the Windows Upgrade Option available with select new PCs running Windows Vista will also receive versions of Windows 7 that include Internet Explorer.  Customers in Europe will also be able to choose between upgrade and full versions of Windows 7.

    I asked Giorgio Sardo, to write about the E editions for Windows 7 and the changes developers need to be aware of. Since the E edition for Windows 7 will ship without  Internet Explorer 8. Giorgio is the Technical Evangelist working on IE and other web technologies.

    Yochay

    In a previous post, we explained how Microsoft is working to fulfill our legal obligations in Europe for Windows 7. In the meantime, we received some questions about what the E editions of Windows 7 will mean for ISVs and developers.

    I took the most common questions and posed them to Arik Cohen, a Program Manager who is working on the E editions of Windows 7. If you have other questions about how this could affect your applications, please add your comments to the post to let us know and we’ll work to get your questions answered.

    Q: What are the differences between standard editions of Windows 7 and E editions of Windows 7?

    A: The only functional difference is that the Internet Explorer 8 component is not available. This is the same component that your users can turn off in the “Turn Windows features on and off” control panel in the Windows 7 RC build. The Internet Web Platform components (for example, WebOC) are still installed and available on all editions of Windows 7, since they are part of the Windows core.

    image

    Q: How should I test my application to ensure that it will work without IE?

    A: To get the same functional behavior as a clean install of the E editions of Windows 7, go to “Turn Windows features on and off” dialog and uncheck Internet Explorer 8. We recommend testing your application both without a browser installed and with a browser installed (remember to set the installed browser as the default).

    Q: What happens if I try to open a link without a browser installed?

    A: You will get an “Application not found” exception.

    image

    Q: What general impacts of Windows 7 E editions have you seen on applications – especially ones that rely on the WebOC?

    A: During our application compatibility testing, we’ve found that the vast majority of applications work on Windows 7 E editions without any changes. This includes applications that use many of the Internet Web Platform embedding methods (including WebBrowser control, hosting Trident, and HTML Help).

    For instance, the following screenshot shows a .NET application that embeds the WebBrowser control running correctly on the E edition of Windows 7.

    image

    Q: My Windows application (WPF, Win Forms, Java, etc.) uses the Web Browser control. Is there any compatibility issue?

    A: Everything should work as expected. However, we’ve seen some issues when applications depend directly on a specific browser. In particular, if while using the Web Browser control, you allow the application to open new windows that do not respect the user’s default browser choice, you may see some issues.

    Q: What are the most common issues that you have found in your testing of applications? And what do you recommend ISVs do about them?

    A: I have seen applications encounter three classes of issues on E editions of Windows 7:

    1. The application has hard coded dependencies to launch Internet Explorer when starting a browser to access the net. This is normally done by explicitly launching “iexplore.exe http://contoso.com” rather than running a ShellExecute on http://contoso.com. This generates an exception on a Windows 7 system without IE installed and enabled. There are times when this is intentional (for example, the Web site you are opening is only supported on IE), in which case you probably want to check for IE availability and provide a good error message to the user if it’s not available.

      We’ve seen this many times, especially in instances where the desired behavior is to open the application in the user’s default browser. You will need to switch to using the more generic case for these scenarios.

    2. The application allows launching a new window from within the WebBrowser control (for example, user accesses “Open in New Window” via the content menu, the page does a window.open() call, etc.).

      These links would always have opened in IE (regardless of the default browser on the system). If you designed your application to open in the default browser, you will need to provide a function that allows that.

      The recommended way to implement custom behavior when opening a new window is to use the NewWindow3 event. Sample code to hook this up in a C# .NET application would look like the following examples.

      In the form initialization code:

      webBrowser1.Navigate("about:blank");
      SHDocVw.WebBrowser web1 =
      (SHDocVw.WebBrowser)webBrowser1.ActiveXInstance;

      web1.NewWindow3 +=
      new SHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(web1_NewWindow3);
      
      

      And the handler:

      void web1_NewWindow3(
      ref object ppDisp,
      ref bool Cancel,
      uint dwFlags,
      string bstrUrlContext,
      string bstrUrl )
      {
      Process.Start(bstrUrl);
      Cancel = true;
      }
      
      
       
    3. Applications don’t handle cases where no browser is installed on the system. We have seen applications that don’t handle this failure case when executing a URL.

      These tend to occur when users don’t have a default browser on their systems and then try to click a “go online for more information” link. We think this is going to be an extremely narrow case – even so, applications should handle these failures gracefully.

    Q: How do I identify the user’s default browser?

    A: Use the IApplicationAssociationRegistration::QueryCurrentDefault API to determine the registered browser by checking QueryCurrentDefault(“http”, AT_URLPROTOCOL,  AL_EFFECTIVE, out progID).

    Q: My app needs to open the browser. What are the best practices?

    A: Run shellexecute() without hard-coding the name of the browser. Respect the user’s choice of default browser and gracefully handle cases where no browser is installed on the system.

    Q: How can I check if I’m running in one of the E edition for Windows 7?

    A: The GetProductInfo() API (introduced in Windows Vista) is how to tell exactly what edition of Windows you are running. The new constant values for the E editions of Windows 7 will be available in the Windows 7 SDK.

    Example of code to determine if you are running on Home Premium vs. Ultimate:

    [DllImport("Kernel32.dll")]
    internal static extern bool GetProductInfo(
    int osMajorVersion,
    int osMinorVersion,
    int spMajorVersion,
    int spMinorVersion,
    out uint edition);


    private void CheckEdition()
    {
    uint edition;
    GetProductInfo(6, 1, 0, 0, out edition);

    switch ((ProductEditions)(edition))
    {

    case ProductEditions.HOMEPREMIUM :
    case ProductEditions.HOMEPREMIUME:
    case ProductEditions.HOMEPREMIUMN:

    MessageBox.Show("Running on a Home Premium edition");
    break;

    case ProductEditions.ULTIMATE :
    case ProductEditions.ULTIMATEE:
    case ProductEditions.ULTIMATEN:
    MessageBox.Show("Running on an Ultimate edition");
    break;

    }
    }
    
    

     

    Q: Are the E editions of Windows 7 going to be available on MSDN? If so, when?

    A: Yes, both the E editions of Windows 7 and the standard editions will be available on MSDN at the same time.

    Q: What about the Internet Explorer 8 Feature Pack for Windows 7 E? If and when will Microsoft release it to the public?

    A: Yes, the Internet Explorer 8 Feature Pack for Windows 7 E will be available on the Microsoft Download Center soon after Windows 7 becomes generally available.

    Giorgio Sardo

    IE Technical Evangelist – Microsoft Corp


    Developing for the Windows 7 Taskbar – Jump into Jump Lists – Part 3

    So far, you have seen how you can opt into the Windows 7 Taskbar Jump List experience by creating a Jump List for your application (in the Developing for the Windows 7 Taskbar – Jump into Jump Lists – Part 2 post.) You have also seen the Windows 7 default support for listing “Recent” or “Frequent” destinations as well as how to create your own custom categories. In this post, we will explore more of the Jump List features and discover how easy it is to add Tasks to your application's Jump List.

    User tasks are customized tasks that get their own Tasks category. As a developer, you can set the title of the displayed task, the icon on the left and, more important, and the “application” that is launched once you activate this task. You can view user’s tasks as shortcuts to the functionality our applications can provide. As you might remember, user tasks are the verbs in our vocabulary; for example, Windows Media Player provides a “Resume last playlist” task and Sticky Notes provides a “New note” task.

    A user task is usually an IShellLink object that launches any given application (your application or any other one you choose) with specific command line parameters. While you cannot categorize tasks, you can separate them using a special separator object. Here’s an example of a Jump List that uses a separator to split three tasks into a group of two plus an additional task:

    image

    So what does it take to add tasks to a Jump List? Well, not that much. Basically it is a single call to the AddUserTasks function in an interface that we are already familiar with, the ICustomDestinationList (ICustomDestinationList::AddUserTasks(IObjectArray) Method). Looking at the code, you will see a single line of code, hr = pcdl->AddUserTasks(poa);. However, as always, someone needs to create and build that poa, IObjectArray, and parameter and fill it with relevant information. Let’s review that process now.

    We are going to create a collection of IShellLinks. This collection will be later cast to the required IObjectArray parameter. The following code is the beginning of that process.

    IObjectCollection *poc;
    HRESULT hr = CoCreateInstance(
    D_EnumerableObjectCollection, NULL, CLSCTX_INPROC, IID_PPV_ARGS(&poc));
    if (SUCCEEDED(hr))
    {
    IShellLink * psl;
    hr = _CreateShellLink(L"/Task1", L"Task 1", &psl);
    if (SUCCEEDED(hr))
    {
    hr = poc->AddObject(psl);
    psl->Release();
    }
    }

    Here you can see that we used COM (again) and CoCreate and IObjectCollection, poc. Next, we call to a helper function called CreateShellLink that receives three parameters:

    • The first parameter is the command line argument to the task
    • The second parameter is the title that will be displayed
    • The last parameter is a pointer to IShellLink

    The object is then filed according to the relevant information.

    Last, we add the recently created IShellLink to the object collection. You may ask yourself where the parameter that provides the path to the executable that we plan to launch is. Well that is a good question. For simplicity, we have hard-coded that information as shown in the following code snippet:

    if (SUCCEEDED(hr))
    {
    hr = _CreateShellLink2(
    L"C:\\Users\\<my user>\\Documents\\new text file.txt",
    L"NotePad",
    &psl);

    if (SUCCEEDED(hr))
    {
    hr = poc->AddObject(psl);
    psl->Release();
    }
    }

    Here you can see we call to a hard-coded _CreateShellLink2 function. This receives a path to a text file as one of its parameters and, as you can see, we are launching Notepad.

    Here is the code for the CreateShellLink2 function:

    HRESULT _CreateShellLink2(
    PCWSTR pszArguments, PCWSTR pszTitle,
    IShellLink **ppsl)
    {
    IShellLink *psl;
    HRESULT hr = CoCreateInstance(
    CLSID_ShellLink,
    NULL,
    CLSCTX_INPROC_SERVER,
    IID_PPV_ARGS(&psl));
    if (SUCCEEDED(hr))
    {
    hr = psl->SetPath(c_szNotePadExecPath);
    if (SUCCEEDED(hr))
    {
    hr = psl->SetArguments(pszArguments);
    if (SUCCEEDED(hr))
    {
    // The title property is required on Jump List items
    // provided as an IShellLink instance. This value is used
    // as the display name in the Jump List.
    IPropertyStore *pps;
    hr = psl->QueryInterface(IID_PPV_ARGS(&pps));
    if (SUCCEEDED(hr))
    {
    PROPVARIANT propvar;
    hr = InitPropVariantFromString(pszTitle, &propvar);
    if (SUCCEEDED(hr))
    {
    hr = pps->SetValue(PKEY_Title, propvar);
    if (SUCCEEDED(hr))
    {
    hr = pps->Commit();
    if (SUCCEEDED(hr))
    {
    hr = psl->QueryInterface
    (IID_PPV_ARGS(ppsl));
    }
    }
    PropVariantClear(&propvar);
    }
    pps->Release();
    }
    }
    }
    else
    {
    hr = HRESULT_FROM_WIN32(GetLastError());
    }
    psl->Release();
    }
    return hr;
    }

    To start with, again we need to use COM and CoCreate to create an IShellLink COM object. A quick look at the SDK reveals that the IShellLink object has many functions. Here are few that we will use:

    • GetPath Gets the path and file name of a Shell link object, that is the path to the executable
    • GetShowCmd Gets the show command for a Shell link object, the executable name
    • SetArguments Sets the command-line arguments for a Shell link object
    • SetDescription Sets the description for a Shell link object; the description can be any application-defined string
    • SetIconLocation Sets the location (path and index) of the icon for a Shell link object SetPath Sets the path and file name of a Shell link object
    • SetWorkingDirectory Sets the name of the working directory for a Shell link object

    As you can see, for each parameter we must get and set appropriate methods. There are additional parameters; take a look at the SDK - IShellLink if you want to learn more.

    In the above example, we set the path to Notepad (by default in the Windows 7 installation, c:\windows\notepad.exe). We also passed a hard-coded (not a good practice) command line argument pointing to a text file in my private document folder (C:\Users\<my user>\Documents\new text file.txt.) The rest of the code sets the title property that is required on Jump List items.

    We call the CreateShellLink2 and CreateShellLink a few more times to add all three shortcuts as shown in the above screen capture.

    Now let’s add a separator.

    To add a separator to our Task List, we need to create an IShellLink, and set the PKEY_AppUserModel_IsDestListSeparator property using the COM property variant as shown in the following code snippet:

    // The Tasks category of Jump Lists supports separator items. 
    // These are simply IShellLink instances that have the
    // PKEY_AppUserModel_IsDestListSeparator property set to TRUE.
    // All other values are ignored when this property is set.
    HRESULT _CreateSeparatorLink(IShellLink **ppsl)
    {
    IPropertyStore *pps;
    HRESULT hr = CoCreateInstance(
    CLSID_ShellLink,
    NULL,
    CLSCTX_INPROC_SERVER,
    IID_PPV_ARGS(&pps));
    if (SUCCEEDED(hr))
    {
    PROPVARIANT propvar;
    hr = InitPropVariantFromBoolean(TRUE, &propvar);
    if (SUCCEEDED(hr))
    {
    hr = pps->SetValue(PKEY_AppUserModel_IsDestListSeparator, propvar);
    if (SUCCEEDED(hr))
    {
    hr = pps->Commit();
    if (SUCCEEDED(hr))
    {
    hr = pps->QueryInterface(IID_PPV_ARGS(ppsl));
    }
    }
    PropVariantClear(&propvar);
    }
    pps->Release();
    }
    return hr;
    }

    Here you can see that we used CoCreate to create an IShellLink object. Next, we set a PROPVARIANT, propvar, to true and set the IShellLink object PKEY_AppUserModel_IsDestListSeparator property to true. This will instruct the OS to render this IShellLink as a separator and not just as regular IShellLink.

    OK, that was long. Now let’s look at the short version, using .NET. For that we are going to use the Windows API Code pack for the .NET Framework.

    As we can expect from .NET, we get abstraction from most of the “COM code behind” that is required. The Microsoft.WindowsAPICodePack.Shell.Taskbar namespace includes a JumpListLink object that extends the ShellLink object and implements IJumpListTasks.

    The JumpList class contains the UserTasks collection of IJumpListTasks to which you can simple add new JumpListLink objects as shown in the following code snippet:

    // Path to Windows system folder
    string systemFolder =
    Environment.GetFolderPath(Environment.SpecialFolder.System);

    jumpList.UserTasks.Add(new JumpListLink
    {
    Title = "Open Notepad",
    Path = Path.Combine(systemFolder, "notepad.exe"),
    IconReference = new IconReference(
    (systemFolder, "notepad.exe"), 0)
    });

    Using the C# 3.0 syntax, we initialize a new JumpListLink object and add it to the UserTasks collection. As you can see, the managed code JumpListLink has very similar properties to the native one (which makes perfect sense). We also added an icon to the Notepad shortcut to the above code, but didn't provide any command line parameters.

    You want to add a separator? Well, that is also very easy: just add a JumpListSeperator object to the UserTasks collection.

    jumpList.UserTasks.Add(new JumpListSeparator());
    Please note that, as always, when working with the Windows Code pack API Taskbar, you have to call the “refresh” function in order to commit the changes, as we explained in the previous post.
    Taskbar.JumpList.RefreshTaskbarList();

    After the refresh, the Jump List looks as follows:

    image

    I’ve compiled a version of a native example from the Windows 7 SDK. You can get a copy of that code from here

    You can download the Windows API Code Pack that includes the manage code example we used in this post.

    This concludes our Jump List discussion. Our next Taskbar topic is Icon Overlay.


    • Page:
    • 1
    • 2
    • 3