Category Archives: windows

Pay and play: how the Silverlight .Net runtime is kept small

Silverlight 1.1, currently in Alpha, will include a cross-platform version of the .NET runtime. The desktop version of this runtime is over 22MB, yet Microsoft is promising to keep Silverlight at around 4MB. How is this size reduction achieved? In part by stripping down the libraries to a minimal core, but Microsoft is also using another technique which it calls pay and play. This means that further class libraries are downloaded as needed, increasing the effective range of available libraries without impacting the size of the core runtime. Sleight of hand perhaps, but it does make sense for online apps.

Developers coding for Silverlight will need to know which of the libraries available in desktop .NET are also in the Silverlight framework. Because of pay and play, some will be in the core, some will be available on demand, and others will never be available. Apparently Visual Studio will give you a visual indication of which is which.

How big will the Silverlight runtime be if you include all the pay and play libraries? Here at Mix07, Microsoft’s Joe Stegman would not say, but I got the impression it will be substantially larger. Of course this is still Alpha; everything can change, and final decisions about what is core and what is pay and play are yet to come. Stegman was also uncertain about some aspects of delivery. You would imagine that pay and play DLLs would be downloaded from Microsoft’s servers, and that once downloaded they would be persisted and shared so that other applications can use them without a further download. Stegman says this is probably what will happen, but there seems to be some doubt.

The Silverlight 1.1 runtime will not be as small as it first appears.

 

Technorati tags: , , ,

C# code to detect UAC elevation on Vista

A couple of days ago I posted about programmatically detecting whether UAC is enabled. I was proposing to read a registry entry. Thanks to the power of blogs, my post drew a comment from Andrei Belogortseff, who has posted C++ code that does this properly. His library has functions for detecting whether the current process is elevated, detecting whether UAC is enabled, and running new processes both elevated and non-elevated (the last of these is the hardest to do).

I liked the libary but wanted to use it from .NET. I compiled his code to a DLL and did a C# wrapper; then I considered the hassles of adding a dependency on the Visual C++ runtime libraries. I therefore did a quick C# implementation of the functions I cared about; I haven’t included the code for running new processes. Please go ahead and download the code, and let me know if you have any suggestions, or even if there is a much easier way to do this that I have missed. There is an app called UACElevationCheck, which calls functions in VistaTools.cs.

The code is only intended to be called from Vista and will throw an exception otherwise; of course you can modify it as you like.

I’ve included a function IsReallyVista that looks for a Vista-only API call, rather than relying on the reported version information. This is because the version information is unreliable if the app runs in a compatibility mode. On the other hand, IsReallyVista is a hack; if you don’t like it, use IsVista which uses the version information instead.

You may be able to do this using the System.Security namespace rather than PInvoke. I had a quick look but the PInvoke code seemed easier to me, especially since Belogortseff has already done the real work.

 

Technorati tags: , , , , , ,

More Windows Installer confusion: managed code custom actions a no-no

People who should know say not to use managed code custom actions in your Windows Installer setups. Like Rob Mensching of Wix fame who says:

…today the Windows Installer does not support managed code CustomActions and the general direction appears to be to try to reduce the need for CustomActions overall.

Read the blog entry for the reasons. The strange thing is, Visual Studio 2005 has specific support for managed code custom actions; there is an Installer class and an MSDN walkthrough on how to use it

Now, I have always avoided managed code custom actions anyway, but only from instinct. Windows Installer setups are problematic enough as it is; adding .NET Framework dependency seems unnecessary. Mensching’s post above explains why it is also error-prone. See also Aaron Stebner’s post from March 2005.

… in summary, I strongly encourage you to not use managed code in your product setup.  I realize that some teams do this here at Microsoft, but please don’t use our bad (in my opinion) examples to justify doing so in your own setup….

Presuming these guys are right, might it not be wise for the Visual Studio folk to remove support for managed code custom actions from the product? A point of confusion is that the managed installer class works with a utility called InstallUtil which is distinct from the Windows Installer; in fact, I believe that Visual Studio setup projects which include managed code custom actions actually call InstallUtil.

I suggest Delphi as a handy alternative, if you would rather avoid Visual C++.

Finally, I hear many good things about Wix, the free XML-based authoring too for Windows Installer setups. If you are embarking on a new setup project it is worth a look.

 

Technorati tags: , , ,

Programmatically detecting whether UAC is enabled

An application may sometimes need to know whether or not the current user has administrative rights. This is complicated in Windows Vista by User Account Control (UAC) – the user may be in the Adminstrators group on the local machine, but nevertheless running with limited rights. When I came across this blog entry on COM elevation by Christoph Wille(thanks to Daniel Moth) I was interested to see the function he mentions called IsUACEnabledOS. I downloaded his code, but was disappointed to see this:

// a really simple check that does not account for possible UAC-disabledness via group policy
public static bool IsUACEnabledOS()
{
int majorVersion = Environment.OSVersion.Version.Major;
int minorVersion = Environment.OSVersion.Version.Minor;

return (majorVersion >= 6);
}

This just detects Vista or higher; in fact, it won’t always return the correct result, since Vista will lie about the version number if an application is running under compatibility settings. How then do we discover if UAC is enabled? The best I’ve come across so far is to query this registry entry:

HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA

If the entry does not exist or is 0, UAC is not enabled. Of course there is no guarantee that this always work, but it’s unlikely to change. I also haven’t checked that it is there in the base versions of Vista; again, it is probably the same.

Update: See the comments to this post for a better solution from Andrei Belogortseff, using the GetTokenInformation API call.  

I’ve now posted a C# implementation of Andrei’s code.

Technorati tags: ,

A bug in Vista’s UAC

Vista’s User Account Control (UAC) elevation prompt sometimes appears when it shouldn’t. Here is an example which works every time for me. I have a folder in Documents (within my home directory) called recordings, containing MP3 files. I double-click one of these files and it opens in Windows Media Player. Now let’s say I try to rename the recordings folder. I get a dialog saying I need to confirm this operation, complete with a UAC shield.

I click Continue and get the screen flash and the elvation prompt. It’s not enough though; I now get a dialog that says “Destination Folder Access Denied – You need permission to perform this action.” If I click Try Again, I get the same dialog, for ever.

It’s nonsense of course. I don’t need permission; I need to close the MP3 file. Indeed, if I close the file I can then rename the folder.

Oddly, if I try this with a Word document, Vista correctly reports that the folder in in use by Word. But if I try a second time, I get the inappropriate UAC prompt.

It’s possible that some Windows API call is returning an access denied error, when it should indicate a file or folder in use by another process, or there could be some other explanation. The end result is a poor user experience.

If Microsoft can’t always get this right, it illustrates how hard it is for developers to give users appropriate error messages when working with UAC on Vista.

 

Technorati tags: , ,

Official performance patch for Outlook 2007

Computerworld has drawn my attention to a new performance patch for Outlook 2007, issued on Friday. Here’s what Microsoft says:

This update fixes a problem in which a calendar item that is marked as private is opened if it is found by using the Search Desktop feature. The update also fixes performance issues that occur when you work with items in a large .pst file or .ost file.

The patch is welcome; there’s no doubting that Outlook 2007 has proved horribly slow for many users. But does it fix the problems? If you read through the comments to earlier postings on this subject you’ll notice that there are actually several performance issues. The main ones I’m aware of:

  1. Slow receive from POP3 mail servers. Sometimes caused by conflicts between Vista’s TCP optimization and certain routers – see comment 27 here for a fix.
  2. Add-ins, for example Dell Media Direct, Acrobat PDFMaker, Microsoft’s Business Contact Manager. See Tools – Trust Center – Add-ins and click Go by the “Com Add-ins” dropdown to manage these.
  3. Desktop search indexing. You can disable this (it’s an add-in) but it is a shame to do so, since it is one of the best new features.
  4. Large local mailbox – could be a standalone .PST (Personal Store), or an .OST (Offline Store) that is kept in synch with Exchange.

The published fix appears to address only the problem with large local mailboxes.

Does it work? I’ve applied it, and it seems to help a bit, though I reckon performance remains worse than Outlook 2003. My hunch is that the issues are too deep-rooted for a quick fix, especially if you keep desktop search enabled. I’ll be interested to see whether the patch fixes another Outlook 2007 annoyance: if you close down Windows while Search is still indexing Outlook, you almost always get a message saying “The data file ‘Mailbox …’ was not closed properly. The file is being checked for problems. Then, of course, you wait and wait.

Is it our fault for having large mailboxes? Here’s a comment from Microsoft’s Jessica Arnold, quoted in the Computerworld article referenced above:

Outlook wasn’t designed to be a file dump, it was meant to be a communications tool,” she said. “There is that fine line, but we don’t necessarily want to optimize the software for people that store their e-mail in the same .PST file for ten years.”

A fair point; yet quick, indexed access to email archives is important to many of us. Archiving to a PST is hazardous, especially since by default Outlook archives to the local machine, not to the server; and in many organizations local documents are not backed up. Running a large mailbox may not be a good solution, but what is better?

Perhaps the answer is Gmail, if you are always online and can cope with the privacy issues. Note the first selling point which Google claims for its service:

Fast search
Use Google search to find the exact message you want, no matter when it was sent or received.

Apparently Google understands that users want to be able to find old messages. Surely a desktop application should be at least as good for finding these, as an internet mailbox that might be thousands of miles away?

Update: I still get “The data file ‘Mailbox …’ was not closed properly.” Not fixed.

See also http://blogs.msdn.com/willkennedy/archive/2007/04/17/outlook-performance-update.aspx where a member of the Outlook team further describes the patch.

 

120 days with Vista

Is there any more to say about Vista? Probably not; yet after reading 30 days with Vista I can’t resist a few comments.

The author, Brian Boyko, says:

On two separate computers I had major stability problems which resulted in loss of data. This is an unforgivable sin …. Additionally, Vista claims backwards compatibility, but I’ve had major and minor problems alike with many of my games, more than a few third-party applications, my peripherals, and, in short, I encountered problems that actively prevented me from getting my work done. Based on my personal experiences with Vista over a 30 day period, I found it to be a dangerously unstable operating system, which has caused me to lose data.

As for me, I installed Vista RTM on four computers shortly after it was released to manufacturing in November last year. Two plain desktops, one media center, one laptop. Just for the record, my experience is dull by comparison with Boyko’s. No lost data; all my important apps run fine; I am not plagued by UAC prompts; the OS is stable.

Have there been hassles? Yes. Tortoise SVN crashes Explorer from time to time; a perfectly good Umax scanner has no driver; Vista on the laptop had severe resume problems which only recently seem to have been fixed by a BIOS update. And Creative’s X-Fi drivers for Vista are terrible. There are also annoyances, like Vista’s habit of thinking your documents are music.

At the same time, I’ve seen nothing to change my opinion that the majority of Vista’s problems are driver-related. Overall I like it better than XP; it doesn’t get in the way of my work and I would hate to go back.

When I do use XP, some of the things I miss are the search box in the Start menu (the Vista Start menu is miles better in other ways as well); the thumbnail previews in the task bar and in alt-tab switching; and copy and paste which doesn’t give up at the first hurdle. I also miss Vista’s more Unix-like Home directories, sensibly organized under Users rather than buried in Documents and Settings.

Security-wise, I consider both User Account Control and IE’s protected mode to be important improvements.

Forget the “Wow”. This is just the latest version of Windows; and it’s not as good as it should be, five years on from XP.

Nevertheless, it is a real improvement, and I’ve been happy with it over the last four months.

 

Technorati tags: ,

Don’t call your Windows app UpdateAnything

I wrote a little Windows utility that updates a file. It’s safe and harmless; it just modifies a file which is in my user documents folder. I called the utility UpdateMSI. Under Vista with UAC enabled, running this app throws up a dialog:

An unidentified program wants access to your computer

But why? Simple: Vista inspects the name of the executable, notes that it includes the word “update”, and concludes that it needs local administrator rights.

On the face of it, this is silly. First of all, Vista is wrong: my app does not need admin rights. Second, it is infuriating that I am not given any choice in the matter. The UAC dialog says “Cancel” or “Allow”. It does not include the option to run with my normal user rights.

Microsoft did this in an effort to detect setup applications; the word “setup” has the same effect. It will trigger if the word is anywhere in the executable name. I tried it with WorldCupDatePicker.exe – same result.

Surely it would not have been too hard to give the user a say in this? Just a checkbox that says “Let me run this how I want on my computer”? You can disable UAC of course; but I’m not going to do that; overall it’s a good feature.

If you wrote the app, there is a fix. You have to embed a UAC manifest in your application. There are simple instructions here, though note that these explain how to force the UAC prompt, not how to suppress it. If you don’t want to run as admin, modify the line:

<requestedExecutionLevel level=”requireAdministrator”/> 

to read instead:

<requestedExecutionLevel level=”asInvoker”/>

Bottom line: always include a manifest.

Technorati tags: , ,

Automating development: Software factories for Visual Studio

The Register has my piece on software factories, based on an interview with Jack Greenfield, a Microsoft software architect. Greenfield talks about a 40% – 80% productivity gain.

If you’re not familiar with this stuff, a bit of orientation may help. When Greenfield talks about software factories, he means both factory instances, which automate the building and customization of specific types of application, and also factory-making tools, which let you create or adapt factories to suit your specific needs. And when Greenfield talks about the factory “runtime”, he means the infrastructure in Visual Studio and its SDK that lets you put your factory to work.

You can actually play with this stuff now. The runtime is called the Guidance Automation Extensions and the authoring tool is the Guidance Automation Toolkit; perhaps one should add the Domain-Specific Language tools. All can be downloaded. You can also download the first four software factory instances. If anyone has tried these and has comments, I’d love to hear from you.

I was intrigued by the internal debates Greenfield mentions. He says it was a mistake to ship the “White Horse” modeling tools in Visual Studio 2005 (Design for Deployment) as a fixed set which are used only occasionally. He is now focused on shipping tools to make and customize tools, a strategy which he believes has more future.

We will always need tools; improvements are welcome. That said, I am also reflecting on the lesson from Qcon: the human factor counts most.

 

Visual Studio 6 on Vista

Why would you want to run Visual Studio 6 on Vista? Two reasons. First, because it includes Visual Basic 6.0, the last version not based on .NET. Second, because Visual C++ 6.0 is still widely used to avoid issues with the C runtime library. There is little point in installing the other products in Visual Studio 6.0.

Visual Basic 6.0 is supported on Vista, but Visual Studio 6 is not. One reason is that it includes the Microsoft Java Virtual Machine which Microsoft promised Sun it would withdraw. This is the stated reason why Visual Studio 6.0 is no longer available for download, even for MSDN Universal subscribers. Fortunately I still have some old MSDN DVDs, so I dug these out and ran setup for the Enterprise edition of Visual Studio 6.0, installing on Vista Professional.

I can’t pretend it went smoothly. First there were compatibility warnings, which I ignored. I deselected applications other then Visual C++ and Visual Basic. Then setup appeared to hang on the screen where it detects installation components, and Vista popped up its “Program not responding” dialog. I believe this is just a matter of patience. My tip is to run task manager and see if the ACMSETUP process is taking up CPU time. If it is, give it more time.

So setup completed, but with an error towards the end:

RegCreateKey failed for \Interface\OLEViewerIViewerCLSID. Access is denied

followed by a DLLREgisterServer failure. I was informed that setup had failed, but nevertheless VB 6 and VC++ were installed and seemed to run OK.

Naturally I wanted to apply the service pack – SP5 or SP6. This is where I had the biggest problems. I could run SETUPSP6.EXE, but the install always failed. If I logged the install, I found this entertaining error:

Do not ship. Error message to log function that detects what VS products are installed in what language unable to function.

Hmmm. I Googled to no avail, though I found this thread where several others report the same problem. Then I tried removing Visual Studio 6.0 for a reinstall, but got the same error from add/remove programs. I finally twigged. The problem was that the first install never completed. Although the product was mostly installed, some part of the Microsoft Installer database had not been updated. The error message actually makes sense: the products were not installed.

Therefore I re-ran the original setup. This time I went into the Tools part of custom setup, clicked Change Option, and deselected the OLE/COM object viewer. Setup now completed without error; so too did SP6. Success.

The apps seem to work OK too – so far so good, though I’m resigned to having to use Run as administrator.

Try this at your own risk; as I mentioned above, Visual C++ 6.0 is not supported on Vista; in fact, I don’t think it is supported at all.