Jason Bower's WebLog

  • Moving to Mobile Devices

    I may not be posting as many .NET related issues anymore. I am changing jobs at Microsoft and moving to the mobile devices group to design input features for the Pocket PC and Smartphone next week. This is a big change for me and gives me a chance to design core end user features. For everyone out there that loves there Smartphone, but hates one or more input issues let me know.

    Jason

  • .NET and Multilingual Operating Systems

    I ran into an interesting bug at work this week when discovered the .NET Framework SDK QuickStarts failed to setup up properly on German versions of Windows 2003 Server. The application that we use to setup up the sample databases with SQL grants the network service account access so that ASP.NET application will work properly. It turns out that on German versions of Windows 2003 Server the Network Service account is called NT-AUTORITÄT\NETZWERKDIENST. We had our code hardcoded to use NT Authority\NETWORK SERVICE. After some investigation on the development team it turns out that .NET provides an ENUM of well known OS accounts that you can access via managed code.

    System.Security.Principal.WellKnownSidType provides access to accounts like Network Service that can be renamed on localized operating systems.

    Way that you want to programmatically specify the NETWORK SERVICE account is to use some code like this:

     

    using System;
    using System.Security.Principal;
    namespace ConsoleApplication2
    {

       class Program
       {

          static void Main(string[] args)
          {

             SecurityIdentifier si = new SecurityIdentifier(WellKnownSidType.NetworkServiceSid, null);
             Console.WriteLine(si.Translate(typeof(NTAccount)).ToString());
             Console.Read();

          }

       }

    }

     

     

     

  • PInvoke Calls

    I was just pointed to a great website to help you write PInvoke calls. Http://www.pinvoke.net. It's a Wiki that has a bunch of PInvoke calls for common Win32 API's. I was only pointed to this site after my developer and I spent a number of days trying to debug an application crash that was caused by us corrupting memory by improperly marshaling objects between .NET and Win32.

    Question to the community:

    How could the SDK make it easier for you to write PInvoke calls from .NET?

    We have been bouncing around some ideas internally, but I'm curious how people figure out the proper way to write a PInvoke call and how Microsoft could make it easier for you?

     

  • Adventures in WMI using System.Management.

     

    Poorly documented code department

     

    I find it amazing sometimes how hard it is to figure out how to code something so seemingly simple. I am working with my developer to create a new setup wizard for the ASP.NET Quickstart samples that will automatically download, install, and configure SQL Server Express. The recommended way to check for SQL Express is to query WMI to find out if it is installed and running, etc.

     

    Well it turns out that writing .NET code to interact with WMI was not as easy as I expected. I found the System.Management namespace documentation and sample code to be pretty poor and I had to email someone on the WMI team to figure out how to make it work for me.

     

    The biggest problem that I found is that the SDK documentation does not provide any simple examples of how to query for a WMI object that exists outside of the default namespace, /root/cimv2. Since I’m looking for SQL Server Express I need to look for the \root\Microsoft\SQL Server\ComputerManagement\.

     

    Here is the easy way to do.

     

     

    ManagementObject SQLObj1 = new ManagementObject(

             "\\root\\Microsoft\\SQLServer\\ComputerManagement",

             "SInstance.InstanceName='SQLEXPRESS'",

             null);

     

                Console.WriteLine("'SInstance.Flags > {0}", SQLObj1["NumberOfFlags"]);

               

    The first parameter to the ManagementObject constructor, ManagementObject (String, String, ObjectGetOptions) is the WMI namespace that I am looking for.

     

    The second parameter is the used to find a particular class object in the namespace I specified.

     

     

    Okay so it took me some time to get the first part working. I could do that without the help of the WMI team, but it wasn’t as straight forward as it should have been. I’ll file a bug and get a new snippet.

     

    Now for the fun stuff:

     

    What I really wanted to get was the SQL Express SqlService object from the \root\Microsoft\SQLServer\ComputerManagement namespace. When I look at that the SqlService class in CimStudio I find that it has two properties that define the primary key. That means I can’t use the same query as above. I had to email the WMI team to find out that in order to define a path to a multikey property with the .NET WMI provider you need to separate the key properties with a comma. So to get what I want I had to do write the following code.

     

     

    ManagementObject SQLObj2 = new ManagementObject(

                      "\\root\\Microsoft\\SQLServer\\ComputerManagement",

                "SqlService.ServiceName='MSSQL$SQLEXPRESS',SQLServiceType=1",

                null);

     

                Console.WriteLine("'SqlService.State > {0}", SQLObj2["State"]);

     

     

    I’m going to try to get the docs updates to contain some details and code samples on this scenario incase anyone else can’t figure this out. In the mean time, this blog entry here to help out anyone else that is running into the same issue.

     

    Now it’s time to do some more coding. I need to figure out how to use System.Management to get a list of the SqlService class objects so that I can sort through them and find the one that I am interested in. I hope that is easier to figure out.

  • Framework SDK Tips

    This post is to provide some tips for people who may or may not have been using the .NET Framework SDK. Most of these tips apply to the .NET Framework SDK v2.0 Beta, but some will also work with previous versions.

    1. Most people do not know this, but the SDK is included with Visual Studio. Look at your start menu you will see a Microsoft .NET Framework SDK program group.

    2. Whidbey Tip: We have added a SDK command prompt that will set all of the environment variables you need to build basic .NET Framework applications. Once you start using the command line to do you work you will learn that you can't live without it.

    3. Debugger: The SDK includes a lightweight graphical debugger called DbgCLR. There is a shortcut to this in the SDK v2.0 Start menu. If you ever need to debug something, but don't want to install VS this is the way to go. Just install the SDK tools only and you have everything you need.

    4. C++ compilers. The .NET Framework SDK includes cl.exe, link.exe, and vcbuild so that you can build C++ applications.

    5. Mage.exe and PermCalc.exe. These are new tools that you can use to generate click once manifest files. Mage has a GUI that is pretty easy to use and will help you create the manifest files that click once needs. PermCalc.exe is a little bit hard to find. It's in the VS directory. Just type PermCalc in the SDK command prompt and you will get the details on it.

    6. ILDasm.exe. I had built .NET Framework applications before coming to work for Microsoft and never user Ildasm, but since someone on my team introduced me to this tool I have found it extremely useful. Run Ildasm and open up a managed assembly of exe. You can then browse through all of the namespaces, classes, properties, methods, etc. It is extremely helpful when you are dealing with poorly documented software.

    If you are an avid SDK user let me know. I'm looking for customers to gather feedback from, invite into beta programs, and recognize as MVP's.

     

  • .NET Framework SDK v2.0 Beta 1 is now available!

    The .NET Framework SDK v2.0 Beta is now available for download. Get it while it is hot. We have x86, IA64, and x64 versions for you. If you are running on 64bit platforms make sure you have the latest 64bit version of Windows installed.

    We've added a bunch of new samples including all new ASP.NET 2.0 Quickstarts.

    If you are an SDK user let me know and send me feedback on the Beta while there is still time to improve it. Please tell me what features you want samples for. I'll make no promises that I can code a up a sample, but I will take your feedback and try to make sure we ship samples for features you request by the time we RTM.

    FYI: The .NET Framework v2.0 Beta can be downloaded and installed here.

  • Single .NET Framework Redist or multiple

    If you had to choose between the following two options which would you choose and why?

    Option A

    A single 60 MB .NET Framework Redist Installation package that installs on all 32 and 64 bit platforms.

    Option B

    A 20 MB .NET Framework Redist that installs on x86
    A 40 MB .NET Framework Redist that installs on IA64
    A 40 MB .NET Framework Redist that installs on AMD64

    I'm curious as to what people think about this and why each option is preferable.


© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker