none
WMI: Select with LIKE clause returns 0 results when it shoudl return 1? RRS feed

  • Question

  • I have a WQL query which should return 0-n results

    [code]
    ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope,
                    new ObjectQuery("select * from IIsWebVirtualDir where Name like '%CPSService%'"));[/code]

    However it returns none. 

    If i specifiy the full Name 

    [code]
     ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope,
                    new ObjectQuery(
                        string.Format("select * from IIsWebVirtualDir where Name='{0}'", W3SVCPath + "CPSService/1.1.0")));
    [/code]

    I get the result I expect. I want to select all of the ones so I can delete them before a new version is deployed, but as I get no rows if I use LIKE then I cant. If I just do "select * from IIsWebVirtualDir" I only get 1 result - the top level virtual directory, and not the one specified by the above WQL - I'd expect all results?!

    Any ideas?
    Tuesday, November 10, 2009 12:38 PM

Answers

  • Quick update. If I make the CPSService folder a Web directory then it seems to find the asp application.

    Is it a requirement that the application be "rooted"?

    So for example - in your example if Mov2 was just a simple directory, but Mov3 was a full fledged Wb Application, you could navigate to it in your browser, but not find Mov3 using WMI. At least in my configuration.

    Cheers
    • Marked as answer by Tim Li Thursday, November 12, 2009 9:32 AM
    • Unmarked as answer by Tim Li Thursday, November 12, 2009 9:32 AM
    • Marked as answer by thedo Friday, November 13, 2009 8:50 AM
    Wednesday, November 11, 2009 1:14 PM
  • Hi,

    After some research, it shows that IIsWebVirtualDir provider only returns the Virtual Dirtory of a website, and if the dirtory is physical and have not made any configuration change on this directory then we could not retrieve this directory from WMI or ADSI, because corresponding key in metabase hasn't been generated for the directory.

    If you could make some configuration change to this directory, we could retrieve it through IIsWebDirectory, using IIS WMI or ADSI provider cannot be of help.

    Thanks.


    Tim Li

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by thedo Friday, November 13, 2009 8:50 AM
    Friday, November 13, 2009 6:09 AM

All replies

  • Hello,

    Welcome to MSDN forums!

    I've ran a test for this question, and the result is not the same as yours, below is my code and environment, 

    Win7+Visual Studio 2008 SP1 +IIS7.0
               
                ManagementPath path = new ManagementPath(@"\\LZH-PC\ROOT\MicrosoftIISv2:IIsSetting");
                ManagementScope scope = new ManagementScope(path);
                scope.Connect();
                ObjectQuery oQuery = new ObjectQuery("select * from IIsWebVirtualDir");
                ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(scope, oQuery);
                ManagementObjectCollection col = oSearcher.Get();
               
                foreach (ManagementObject mo in col)
                {
                    Debug.Print(mo.ToString());
                }
    The result I got is :

    \\LZH-PC\ROOT\MicrosoftIISv2:IIsWebVirtualDir.Name="W3SVC/1/ROOT"
    \\LZH-PC\ROOT\MicrosoftIISv2:IIsWebVirtualDir.Name="W3SVC/1/ROOT/Movies"
    \\LZH-PC\ROOT\MicrosoftIISv2:IIsWebVirtualDir.Name="W3SVC/1/ROOT/Mov2"
    \\LZH-PC\ROOT\MicrosoftIISv2:IIsWebVirtualDir.Name="W3SVC/1/ROOT/Mov2/Mov3"

    If I change the query to :
    "select * from IIsWebVirtualDir where Name Like '%mo%'"

    The result will be:
    \\LZH-PC\ROOT\MicrosoftIISv2:IIsWebVirtualDir.Name="W3SVC/1/ROOT/Movies"
    \\LZH-PC\ROOT\MicrosoftIISv2:IIsWebVirtualDir.Name="W3SVC/1/ROOT/Mov2"
    \\LZH-PC\ROOT\MicrosoftIISv2:IIsWebVirtualDir.Name="W3SVC/1/ROOT/Mov2/Mov3"

    As the result shows, I'm wondering which SCOPE parameter did you have, and if your IIS version is different from mine. Would you follow up with more detailed code, it would hlep us to reproduce this issue and give out the solution faster.

    Looking forward to your feedback.

    Thanks.
     

    Tim Li

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Wednesday, November 11, 2009 11:57 AM
  • Hi - thanks for the reply.

    I'm running this code on a WinXP machine, which is pointing at a W2K3 server.

    My Scope is set up like this

    connection = new ConnectionOptions();
    connection.Username = Username;
    connection.Password = Password;
    connection.Authority = Domain;
    connection.Authentication = AuthenticationLevel.PacketPrivacy;
    connection.Impersonation = ImpersonationLevel.Impersonate;
    scope = new ManagementScope(string.Format(@"\\{0}\root\MicrosoftIISv2:IIsSetting", Server), connection);
    scope.Connect();
    base.Project.Log(Level.Info, "     [iisdeploy] Connected to {0}", Server);

    and my query is set up like this

    ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, new SelectQuery("IIsWebVirtualDir"));

    which will return only the 1 result (the Default Web site "root"). I have 1 "Web Site" (using the default name "Default Web Site"). This contains a folder called CPSService. In that folder is a WCF service in a folder under the version number. CPSService is just a regular folder - not a virtual directory, but it contains one (so the url would be like http://localhost/CPSService/6.1.1/service.svc).

    So our end goal is to be able to remove previous installs automatically when a breaking change to the service is made (as each time it is deployed it is deployed under its own version number). We can handle the removal, but we cant find the existing installs. 

    Any assistance appreciated.
    Wednesday, November 11, 2009 1:11 PM
  • Quick update. If I make the CPSService folder a Web directory then it seems to find the asp application.

    Is it a requirement that the application be "rooted"?

    So for example - in your example if Mov2 was just a simple directory, but Mov3 was a full fledged Wb Application, you could navigate to it in your browser, but not find Mov3 using WMI. At least in my configuration.

    Cheers
    • Marked as answer by Tim Li Thursday, November 12, 2009 9:32 AM
    • Unmarked as answer by Tim Li Thursday, November 12, 2009 9:32 AM
    • Marked as answer by thedo Friday, November 13, 2009 8:50 AM
    Wednesday, November 11, 2009 1:14 PM
  • Hi,

    After some research, it shows that IIsWebVirtualDir provider only returns the Virtual Dirtory of a website, and if the dirtory is physical and have not made any configuration change on this directory then we could not retrieve this directory from WMI or ADSI, because corresponding key in metabase hasn't been generated for the directory.

    If you could make some configuration change to this directory, we could retrieve it through IIsWebDirectory, using IIS WMI or ADSI provider cannot be of help.

    Thanks.


    Tim Li

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by thedo Friday, November 13, 2009 8:50 AM
    Friday, November 13, 2009 6:09 AM
  • Hi Tim,

    Thanks for the feedback. So in my example I have a folder setup like this

    c:\inetpub\wwwroot\CPSService\6.1.1

    In IIS the 6.1.1 is an application (so a virtual directory, with AppCreate3 run against it). However CPSService is just a plain old folder. 

    The metabase is clearly aware of the 6.1.1 application as if I select for it specifically I get the result, however if I search for all web virtual directories the 6.1.1 does not show. 

    In my case I have made CPSService a web virtual directory, as it doesnt really cause an issue - it just seems rather strange behaviour, that it can find it by name, but not by selecting "all".

    Thanks
    Friday, November 13, 2009 8:49 AM