torsten's .NET blog In the end, everything is a gag [Ch. Chaplin]
# Friday, October 19, 2007
Get the local mapped network drives using WMI

Today I helped a coworker to get the local mapped network drives using WMI instead of COM Interop/native windows API. Just to keep the code as a reminder and help others with the same problem I provide it here.

The result of the code below is in general the same you will get if you hit the "net use" command at the windows command shell prompt. For further infos and reading I suggest http://msdn2.microsoft.com/en-us/library/aa394173.aspx (Win32_LogicalDisk; MSDN WMI Reference); for immediate results of query the WMI you should use Scriptomatic (download from http://www.microsoft.com/downloads/details.aspx?familyid=09DFC342-648B-4119-B7EB-783B0F7D1178&displaylang=en).

Little bit optimization is yet possible providing the drive type in the WQL as a where clause parameter, so here it is:

/// <summary>
/// Container for Share entries
/// </summary>
public struct SharePathEntry
{
  public string Name;
  public string Path;
  public SharePathEntry(string n, string p) {
    Name = n;
    Path = p;
  }
}

// for other types see: http://msdn2.microsoft.com/en-us/library/aa394173.aspx
const int NetworkDriveType = 4;

public static List<SharePathEntry> GetLocalShares()
{
  List<SharePathEntry> allLocalShares = new List<SharePathEntry>(); // a container

  WqlObjectQuery objectQuery = new WqlObjectQuery("select DriveType,DeviceID,ProviderName from Win32_LogicalDisk");
  ManagementScope scope = new ManagementScope(@"\\.\root\cimv2"); // local WMI namespace
  scope.Options.Impersonation = ImpersonationLevel.Impersonate;
  scope.Options.EnablePrivileges = true;
  ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, objectQuery);
  foreach (ManagementObject share in searcher.Get())
  {
    int driveType = Convert.ToInt32(share["DriveType"]);
    if (driveType == NetworkDriveType) {
      object objName = share["DeviceID"];
      object objPath = share["ProviderName"];
      if (null != objName && null != objPath)
      {
        allLocalShares.Add(new SharePathEntry(objName.ToString(), objPath.ToString()));
      }
    }
  }
  return allLocalShares;
}
Technorati tags:  |  | 
Friday, October 19, 2007 11:02:12 AM (W. Europe Daylight Time, UTC+02:00)    #  Comments [0]  | 
# Friday, September 21, 2007
We break the million: overall downloads

It seems we hit the high border some days ago: the overall download counter at SF is above one million for the favorite newsreader...

Thank you all, that love the project - you are the real motivation engine!

Technorati tags:
Friday, September 21, 2007 2:31:22 PM (W. Europe Daylight Time, UTC+02:00)    #  Comments [5]  | 
# Thursday, September 20, 2007
Project source browsing with FishEye

You may have noticed we released v1.5.0.17 of my favorite feed reader (and refreshed the installer meanwhile) - for the coding guys we now have even more: Project Supported by FishEye

Thanks to the folks at atlassian we are now have the comfortable source browsing tool running on the SF repositories (CVS with the CLR 1.1 code and SVN for CLR 2.0). Most I like the diffs view and RSS link in the top right - there the circle closes (subscribed).

Technorati tags:  |  | 
Thursday, September 20, 2007 8:23:26 AM (W. Europe Daylight Time, UTC+02:00)    #  Comments [0]  | 
# Thursday, August 02, 2007
Make use of it: the portable Bandit

Is I wrote recently, I worked to get RSS Bandit running as a portable application. Now it is time to test it: you can download the ShadowCat Beta 2 release installer, then read how you get it done.

Technorati tags:  |  | 
Thursday, August 02, 2007 3:17:27 PM (W. Europe Daylight Time, UTC+02:00)    #  Comments [4]  | 
# Sunday, July 01, 2007
The portable Bandit

I read about portable apps (applications, that are running from a stick without any further installation) in my favourite magazine and it just took a hour to set the sources to get RSS Bandit running from a stick:

The Portable.Bandit

There is at least one issue left: the .NET framework must be installed at the machine running the portable Bandit...

Tomorrow I will walk to different machines to get it more tested.

Technorati tags:  |  | 
Sunday, July 01, 2007 8:28:05 PM (W. Europe Daylight Time, UTC+02:00)    #  Comments [6]  | 
# Tuesday, June 19, 2007
Avoid this.Handle != IntPtr.Zero checks!

Just because requesting the Handle (IntPtr, see remarks section) will create the handle internally in case it is IntPtr.Zero and may cause issues on disposing or closing! How to get around? Just use the this.IsHandleCreated property...

Technorati tags:  | 
Tuesday, June 19, 2007 7:30:12 PM (W. Europe Daylight Time, UTC+02:00)    #  Comments [0]  | 
# Monday, June 18, 2007
Sudoku for geeks

I really like the two Sudoku games (one easy, one heavy) ever saturday in our local newspaper -  there are yet only three heavy games I could not solved over the last months and it is really fun. So maybe they are not really "heavy" - who knows.

But now I read this post about how to solve every Sudoku using XSLT (another variant), using SQL and regular expression. Ouch - where is the fun? If you know the algorithm to solve one, it can be expressed by every language poeple like to program. I would more like the algorithm to generate new Sudoku games...

Technorati tags:  |  | 
Monday, June 18, 2007 9:04:48 AM (W. Europe Daylight Time, UTC+02:00)    #  Comments [1]  | 
# Wednesday, March 07, 2007
RSS Bandit and the 100% CPU issue

Today I could track down an annoying issue: on some installations of the newer version of RSS Bandit (starting with the first betas of 1.5.0.x) it starts using 100% CPU time on a thread. As we started also to use lucene.NET with this new release I guessed it was a related issue, I was right. But as we run into multiple issues with lucene it was not obvious as a separate problem. So here it is:

We used a slightly modified version of lucene.NET to include the available language dependent analyzers and stopword filters. Before we released, I already fixed some obvious issues I got with e.g. french stemmer. Now we got more with the CJK (Japanese/Korean, bug report) and possibly Chinese analyzers. It looks like it get into a state it never returns. The attached debug callstack was very helpful to got the direction to search for! I found this: TextReader.Read(char[], int, int) was called and the return value checked against -1 only, not against 0 (zero). So I run over all analyzers to find all the places I have to change that code and here it is: the modified lucene.net.dll (zipped, 142K).

To all users that run into the problem: can you test the modification, please? Just download, unzip into the installation folder, restart Bandit. Please report here (or as comments to the bug reports mentioned above) if it help - so we can refresh the installer for the major public.

Technorati tags:  | 
Wednesday, March 07, 2007 12:59:08 PM (W. Europe Standard Time, UTC+01:00)    #  Comments [22]  | 
# Tuesday, February 20, 2007
.NET Issue with Vista icons

Today I stumbled over a wired issue in both VS.IDE 2003 and VS.IDE 2005: they did not compiled my project anymore! Error was:

Compiler Error CS1583 (CSC583.tmp is not a valid Win32 resource ...

I just refreshed the french resources, so my first thought was it also caused that error, but I'm wrong. Just before this change I fixed a issue with our Vista Icon - added more ico image resolutions - and also a 256x256 Vista compressed image. What I forgot: I did not compiled after the icon change! All the google'd answers did not matched my case. I simply removed the 256x256 icon image - then it compiled successfully!

So my question is: how do I compile a .NET application with a Vista compressed icon? Do I have to compile under Vista? But how about VS 2003?

Technorati tags:  |  | 
Tuesday, February 20, 2007 7:14:50 PM (W. Europe Standard Time, UTC+01:00)    #  Comments [4]  | 
# Friday, December 01, 2006
Strange XSL Transform Exception - figured out

Recently we migrated our software dev. to use CLR 2.0. One part of the migration was to rework the usage of XslTransform class to the new XslCompiledTransform class. Reading the "Migrating From the XslTransform class" MSDN paper, it was not much work, just minutes. But then I got this strange exception:

Cannot transform XML using stylesheet 'transform.xslt.'
Exception: Extension function parameters or return values which have Clr type 'ConcatString' are not supported.

This really took me a half day to track it down! First, I did the usual things like reading more carefully the MSDN docs (my wrong direction: security issues), google'd for it and found at least one topic about. This was the right direction to solve it, but I tried various other things to get around - inclusive a complete redesign of the transformation code not using any stylesheet scripts. At last I was more confused (introduced other errors) than as I started, so I reverted the most unrelated changes. After reading the more interesting post "Introducing XslCompiledTransform" and IM'ed with a OS project coworker it gets more clear to me what happens: the System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltResult(XmlQueryType xmlType, Object value) visible in the call stack try to make my <msxsl:script language="JScript" ...> functions to return strong types - but: only the top level functions called from XSL element! Here is the non-working stylesheet code sample:

<msxsl:script language="JScript" implements-prefix="local"><![CDATA[
   
    function fmtDate(val, fmtmask)
    {

   var s = "" + val; 
   ...
   return formatDate(new Date(s.substring(0,4),s.substring(4,6)-1,s.substring(6,8)), fmtmask);
    }
    function formatDate(varDate, bstrFormat)
    {
...
return "" + formattedDate;
}
]]></msxsl:script>

And this is the working one:

<msxsl:script language="JScript" implements-prefix="local"><![CDATA[
   
    function fmtDate(val, fmtmask)
    {

   var s = "" + val; 
   ...
   return "" + formatDate(new Date(s.substring(0,4),s.substring(4,6)-1,s.substring(6,8)), fmtmask);
    }
    function formatDate(varDate, bstrFormat)
    {
...
return "" + formattedDate;
}
]]></msxsl:script>

You notice the small but important difference? Now the stylesheet compiler consider my return value correctly as a string. Whoa...

Technorati tags:  | 
Friday, December 01, 2006 8:58:49 AM (W. Europe Standard Time, UTC+01:00)    #  Comments [1]  | 
Navigation

Like RSS Bandit? Make a donation to help support its development and maintenance. As little as 1€ will help.

Make payments with PayPal - it's fast, free and secure!
On this page....
<October 2007>
SunMonTueWedThuFriSat
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

SUBSCRIBE RSS GeoURL e-mail

Search
Categories
Blogroll

newtelligence dasBlog 2.3.9074.18820

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Join WebHost4Life.com