<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Decrypt my World : WMI</title><link>http://blogs.msdn.com/alejacma/archive/tags/WMI/default.aspx</link><description>Tags: WMI</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>WMI Diag won't work well in non-English Windows</title><link>http://blogs.msdn.com/alejacma/archive/2008/06/10/wmi-diag-won-t-work-well-in-non-english-windows.aspx</link><pubDate>Tue, 10 Jun 2008 13:40:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8589699</guid><dc:creator>alejacma</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/alejacma/comments/8589699.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alejacma/commentrss.aspx?PostID=8589699</wfw:commentRss><description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;If you&amp;nbsp;ever use&amp;nbsp;&lt;STRONG&gt;WMI Diag script &lt;/STRONG&gt;(&lt;A class="" href="http://www.microsoft.com/downloads/details.aspx?familyid=d7ba3cd6-18d1-4d05-b11e-4c64192ae97d&amp;amp;displaylang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?familyid=d7ba3cd6-18d1-4d05-b11e-4c64192ae97d&amp;amp;displaylang=en"&gt;The WMI Diagnosis Utility -- Version 2.0&lt;/A&gt;) on a &lt;STRONG&gt;non-English&lt;/STRONG&gt; version of &lt;STRONG&gt;Windows&lt;/STRONG&gt; (i.e. &lt;STRONG&gt;Spanish&lt;/STRONG&gt;, French, Italian, German...), you will get tons of &lt;STRONG&gt;errors&lt;/STRONG&gt; when the script&amp;nbsp;checks out &lt;STRONG&gt;default permissions&lt;/STRONG&gt; on WMI namespaces or DCOM components related to WMI, for instance.&lt;/P&gt;
&lt;P&gt;The cause is simple: the script checks permissions for groups of users which name is language-dependant.&lt;/P&gt;
&lt;P&gt;If we use WMI Diag in i.e. a &lt;STRONG&gt;Spanish&lt;/STRONG&gt; Windows, we will have to edit the script and replace:&lt;/P&gt;
&lt;P&gt;- "BUILTIN\Administrators" with "BUILTIN\Administradores",&lt;/P&gt;
&lt;P&gt;- "Everyone"&amp;nbsp;with "Todos",&lt;/P&gt;
&lt;P&gt;- "NT AUTHORITY\NETWORK SERVICE" with "NT AUTHORITY\Servicio de red",&lt;/P&gt;
&lt;P&gt;- "NT AUTHORITY\LOCAL SERVICE" with "NT AUTHORITY\SERVICIO LOCAL",&lt;/P&gt;
&lt;P&gt;- "NT AUTHORITY\Authenticated Users" with "NT AUTHORITY\Usuarios autentificados",&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Now you can run the script and find out if your WMI is really broken.&lt;/P&gt;
&lt;P mce_keep="true"&gt;I hope this helps.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Cheers,&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Alex (Alejandro Campos Magencio)&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8589699" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alejacma/archive/tags/WMI/default.aspx">WMI</category></item><item><title>How to get Antivirus information with WMI (VBScript)</title><link>http://blogs.msdn.com/alejacma/archive/2008/05/12/how-to-get-antivirus-information-with-wmi-vbscript.aspx</link><pubDate>Mon, 12 May 2008 12:23:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8492893</guid><dc:creator>alejacma</dc:creator><slash:comments>17</slash:comments><comments>http://blogs.msdn.com/alejacma/comments/8492893.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alejacma/commentrss.aspx?PostID=8492893</wfw:commentRss><description>&lt;P&gt;Hi all, welcome back,&lt;/P&gt;
&lt;P&gt;As we read in &lt;A class="" href="http://www.microsoft.com/windowsxp/sp2/wscoverview.mspx" mce_href="http://www.microsoft.com/windowsxp/sp2/wscoverview.mspx"&gt;Windows Security Center – Managing the State of Security&lt;/A&gt;, the vast majority of &lt;STRONG&gt;antivirus&lt;/STRONG&gt; Independent Software Vendors (ISVs) support &lt;STRONG&gt;WMI&lt;/STRONG&gt; integration. Windows Security Center uses it to detect antivirus and firewall solutions.&lt;/P&gt;
&lt;P&gt;The following &lt;STRONG&gt;script&lt;/STRONG&gt; shows how to get some information from those solutions:&lt;BR&gt;&lt;BR&gt;&amp;nbsp; &lt;/P&gt;&lt;PRE&gt;strComputer = "."
    
Set oWMI = GetObject( _
  "winmgmts:{impersonationLevel=impersonate}!\\" &amp;amp; strComputer &amp;amp; "\root\SecurityCenter")
  
Set colItems = oWMI.ExecQuery("Select * from AntiVirusProduct")

For Each objItem in colItems
  With objItem
    WScript.Echo .companyName
    WScript.Echo .displayName
    WScript.Echo .instanceGuid
    WScript.Echo .onAccessScanningEnabled
    WScript.Echo .pathToSignedProductExe
    WScript.Echo .productHasNotifiedUser
    WScript.Echo .productState
    WScript.Echo .productUptoDate
    WScript.Echo .productWantsWscNotifications
    WScript.Echo .versionNumber  
  End With
Next

&lt;/PRE&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alex (Alejandro Campos Magencio)&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8492893" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alejacma/archive/tags/WMI/default.aspx">WMI</category><category domain="http://blogs.msdn.com/alejacma/archive/tags/VBScript/default.aspx">VBScript</category></item><item><title>Win32_Process.Create fails if user profile is not loaded</title><link>http://blogs.msdn.com/alejacma/archive/2008/04/09/win32-process-create-fails-if-user-profile-is-not-loaded.aspx</link><pubDate>Wed, 09 Apr 2008 14:03:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8372103</guid><dc:creator>alejacma</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/alejacma/comments/8372103.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alejacma/commentrss.aspx?PostID=8372103</wfw:commentRss><description>&lt;P&gt;Hi all, welcome back,&lt;/P&gt;
&lt;P&gt;The other day I worked on an issue which happened when&amp;nbsp;using &lt;STRONG&gt;WMI &lt;/STRONG&gt;method&amp;nbsp;&lt;A class="" href="http://msdn2.microsoft.com/en-us/library/aa389388(VS.85).aspx" mce_href="http://msdn2.microsoft.com/en-us/library/aa389388(VS.85).aspx"&gt;Win32_Process.Create&lt;/A&gt; to spawn a process from an &lt;STRONG&gt;ASP.NET&lt;/STRONG&gt; application. This method&amp;nbsp;was returning an &lt;STRONG&gt;ERROR_NOT_ENOUGH_MEMORY&lt;/STRONG&gt; (8) and the new process wasn't created. The application was running as Network Service and WMI was impersonating a special user when launching the new process.&lt;/P&gt;
&lt;P&gt;We could also reproduce the issue with a &lt;STRONG&gt;VBScript&lt;/STRONG&gt; that we launched as the special user with &lt;STRONG&gt;runas&lt;/STRONG&gt; command and its &lt;STRONG&gt;/noprofile &lt;/STRONG&gt;option.&amp;nbsp;When we used &lt;STRONG&gt;/profile &lt;/STRONG&gt;option instead, the script worked fine, and so did the ASP.NET app! So it seems that this WMI&amp;nbsp;method is dependant of the user profile being loaded.&lt;/P&gt;
&lt;P&gt;After some tests and some debugging, I confirmed this:&lt;/P&gt;
&lt;P&gt;Win32_Process.Create always tries to access the registry of the user which will launch the process (the one we are impersonating). This behavior is by design and can't be modified.&lt;/P&gt;
&lt;P&gt;If the user &lt;STRONG&gt;profile&lt;/STRONG&gt; is &lt;STRONG&gt;loaded&lt;/STRONG&gt;, there is no problem as Create can access the registry keys it needs. But if the profile is &lt;STRONG&gt;not loaded&lt;/STRONG&gt;, it will try to load the &lt;STRONG&gt;registry hive&lt;/STRONG&gt; of the user (&lt;STRONG&gt;NTUSER.DAT&lt;/STRONG&gt; file) into the registry. For doing that it uses &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms724889(VS.85).aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms724889(VS.85).aspx"&gt;RegLoadKey&lt;/A&gt; API, which in our case is failing with &lt;STRONG&gt;ERROR_PRIVILEGE_NOT_HELD&lt;/STRONG&gt; error. This internal error will cause the misleading ERROR_NOT_ENOUGH_MEMORY that we get from Create method.&lt;BR&gt;I verified the privileges this API requires in its documentation: "The calling process must have the &lt;STRONG&gt;SE_RESTORE_NAME&lt;/STRONG&gt; and &lt;STRONG&gt;SE_BACKUP_NAME&lt;/STRONG&gt; privileges on the computer in which the registry resides."&lt;/P&gt;
&lt;P&gt;Summing up, Win32_Process.Create will work if the user we are impersonating has SE_RESTORE_NAME (a.k.a. &lt;STRONG&gt;SeRestorePrivilege&lt;/STRONG&gt; a.k.a. "&lt;STRONG&gt;Restore files and directories&lt;/STRONG&gt;") and SE_BACKUP_NAME (a.k.a. &lt;STRONG&gt;SeBackupPrivilege&lt;/STRONG&gt; a.k.a."&lt;STRONG&gt;Backup files and directories&lt;/STRONG&gt;") privileges in the local machine where the WMI code is running. This way it can load the registry hive if the profile for that user is not loaded.&lt;/P&gt;
&lt;P&gt;An alternate solution may be to &lt;STRONG&gt;load the profile &lt;/STRONG&gt;before calling Create. &lt;STRONG&gt;IIS&lt;/STRONG&gt; won’t load it automatically, and WMI neither. We may load it by calling &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/bb762281(VS.85).aspx" mce_href="http://msdn2.microsoft.com/en-us/library/bb762281(VS.85).aspx"&gt;LoadUserProfile&lt;/A&gt; API, for instance. But the user calling this API needs high privileges. So if we know the user we are impersonating, we may have an easier way to load the profile: &lt;STRONG&gt;Service Control Manager&lt;/STRONG&gt; (&lt;STRONG&gt;SCM&lt;/STRONG&gt;) automatically loads the user profile of the user running a &lt;STRONG&gt;Windows service&lt;/STRONG&gt;. We may create a dummy service which does nothing but always stay alive and which runs as our special user, so its profile gets loaded. Once the profile of the user gets loaded by SCM, every other app which requires it will have access to it, like a web app or a web service.&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;I hope this helps.&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alex (Alejandro Campos Magencio)&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8372103" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alejacma/archive/tags/WMI/default.aspx">WMI</category></item><item><title>How to change the Security Descriptor of WMI objects</title><link>http://blogs.msdn.com/alejacma/archive/2008/03/14/how-to-change-the-security-descriptor-of-wmi-objects.aspx</link><pubDate>Fri, 14 Mar 2008 05:51:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8172662</guid><dc:creator>alejacma</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/alejacma/comments/8172662.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alejacma/commentrss.aspx?PostID=8172662</wfw:commentRss><description>&lt;P&gt;Hi all, welcome back,&lt;/P&gt;
&lt;P&gt;You may want to give users or groups &lt;STRONG&gt;access&lt;/STRONG&gt; to perform read/modify &lt;STRONG&gt;WMI operations&lt;/STRONG&gt; on &lt;STRONG&gt;WMI objects&lt;/STRONG&gt;, and for that you need to change the &lt;STRONG&gt;Security Descriptor&lt;/STRONG&gt; (&lt;STRONG&gt;SD&lt;/STRONG&gt;) for WMI objects. There are several ways to achieve this:&lt;/P&gt;
&lt;P&gt;1) &lt;STRONG&gt;Manually&lt;/STRONG&gt; with wmimgmt.msc: &lt;A class="" href="http://support.microsoft.com/default.aspx?scid=kb;EN-US;325353" mce_href="http://support.microsoft.com/default.aspx?scid=kb;EN-US;325353"&gt;325353&amp;nbsp;HOW TO: Set WMI Namespace Security in Windows Server 2003&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;2) Using &lt;STRONG&gt;third-party tools&lt;/STRONG&gt; like &lt;A class="" href="http://www.codeproject.com/cs/system/WmiSecurity.asp" mce_href="http://www.codeproject.com/cs/system/WmiSecurity.asp"&gt;WMI Namespace Security&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;3) &lt;STRONG&gt;Programmatically, the easy way&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P&gt;We could manually set the SD on one box, then save it to a text file with &lt;A class="" href="http://msdn2.microsoft.com/en-gb/library/aa394680(VS.85).aspx" mce_href="http://msdn2.microsoft.com/en-gb/library/aa394680(VS.85).aspx"&gt;GetSD method of the __SystemSecurity class&lt;/A&gt;, read the SD from the text file and reapply it to new boxes with &lt;A class="" href="http://msdn2.microsoft.com/en-gb/library/aa394682(VS.85).aspx" mce_href="http://msdn2.microsoft.com/en-gb/library/aa394682(VS.85).aspx"&gt;SetSD&lt;/A&gt; method.&lt;/P&gt;
&lt;P&gt;The following VBScript shows how to use GetSD to obtain the current SD for the Root\Cimv2 namespace and change it to the byte array shown in strDisplaySD.&lt;/P&gt;&lt;PRE&gt;' Connect to WMI and the root namespace.
'
Set objWMI = GetObject("winmgmts:root\cimv2")

' Get the single __SystemSecurity object in this namespace.
'
Set objSecurity = objWMI.Get("__SystemSecurity=@")

' Get the namespace security.
'
nReturn = objSecurity.GetSD(arrSD)
If Err &amp;lt;&amp;gt; 0 Then
    WScript.Echo "Return value =  " &amp;amp; nReturn
Else
    ' Show it
    '
    strDisplaySD = "SD = {"
    For I = Lbound(arrSD) To Ubound(arrSD)
        strDisplaySD = strDisplaySD &amp;amp; arrSD(I)
        If I &amp;lt;&amp;gt; Ubound(arrSD) Then    
            strDisplaySD = DisplaySD &amp;amp; ","
        End If
    Next
    strDisplaySD = strDisplaySD &amp;amp; "}"
    WScript.Echo strDisplaySD
End If
&lt;/PRE&gt;
&lt;P&gt;The following script shows how to use SetSD to set the namespace SD for the root namespace and change it to the byte array shown in arrSD.&lt;/P&gt;&lt;PRE&gt;' Hard-coded security descriptor
'
arrSD = array( 1, 0, 4,129,72, 0, 0, 0, _ 
    88, 0, 0, 0, 0, 0, 0, 0, _
    20, 0, 0, 0, 2, 0,52, 0, _
    2, 0, 0, 0, 0, 2,24, 0, _
    63, 0, 6, 0, 1, 2, 0, 0, _
    0, 0, 0, 5,32, 0, 0, 0, _
    32, 2, 0, 0, 0, 2,20, 0, _
    63, 0, 6, 0, 1, 1, 0, 0, _
    0, 0, 0, 1, 0, 0, 0, 0, _
    1, 2, 0, 0, 0, 0, 0, 5, _
    32, 0, 0, 0,32, 2, 0, 0, _
    1, 2, 0, 0, 0, 0, 0, 5, _
    32, 0, 0, 0,32, 2, 0, 0)

' Connect to WMI and the root namespace.
'
Set objWMI = GetObject("winmgmts:root\cimv2")

' Get the single __SystemSecurity object in this namespace.
'
Set objSecurity = objWMI.Get("__SystemSecurity=@")

' Change the namespace security.
'
nReturn = objSecurity.SetSD(arrSD)
WScript.Echo "Return value = " &amp;amp; nReturn
&lt;/PRE&gt;
&lt;P&gt;4) &lt;STRONG&gt;Programmatically, the hard way&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P&gt;We can write our own WMI script using the following sample found at &lt;A href="http://www.lissware.net/"&gt;http://www.lissware.net/&lt;/A&gt;: &lt;/P&gt;
&lt;P&gt;&lt;A class="" href="http://www.lissware.net/wmibooks/Volume_2_ScriptKits.zip" mce_href="http://www.lissware.net/wmibooks/Volume_2_ScriptKits.zip"&gt;vol 2, Sample 4.02 to 4.13 - WMIManageSD.Wsf&lt;/A&gt;, using a series of subfunctions:&lt;BR&gt;&amp;nbsp;&lt;BR&gt;Sample 4.02 to 4.13 - WMIManageSD.Wsf&lt;BR&gt;Sample 4.14 to 4.24 - GetSDFunction.vbs&lt;BR&gt;Sample 4.25 - CreateDefaultSDFunction.vbs&lt;BR&gt;Sample 4.26 to 4.27 - ADSIHelper.exp&lt;BR&gt;Sample 4.28 - DecipherWMISDFunction.vbs&lt;BR&gt;Sample 4.29 - DecipherADSISDFunction.vbs&lt;BR&gt;Sample 4.30 - DecipherSDControlFlagsFunction.vbs&lt;BR&gt;Sample 4.31 - CalculateSDControlFlagsFunction.vbs&lt;BR&gt;Sample 4.32 to 4.40 - ActiveDirectory.CMD&lt;BR&gt;Sample 4.41 - SetSDOwnerFunction.vbs&lt;BR&gt;Sample 4.42 - CreateTrusteeFunction.vbs&lt;BR&gt;Sample 4.43 - SetSDGroupFunction.vbs&lt;BR&gt;Sample 4.44 - SetSDControlFlagsFunction.vbs&lt;BR&gt;Sample 4.45 to 4.46 - AddACEFunction.vbs&lt;BR&gt;Sample 4.47 to 4.48 - DelACEFunction.vbs&lt;BR&gt;Sample 4.49 to 4.50 - ReOrderACEFunction.vbs&lt;BR&gt;Sample 4.51 to 4.61 - SetSDFunction.vbs&lt;BR&gt;&amp;nbsp;&lt;BR&gt;The script actually reads the binary SD with __SystemSecurity class and converts it with Sample 4.14 to 4.24 - GetSDFunction.vbs at line 283.&lt;BR&gt;The object used to convert the SD is defined at line 189 in Sample 4.02 to 4.13 - WMIManageSD.Wsf.&lt;BR&gt;Under XP and 2003, it uses the IADsSecurityUtility::ConvertSecurityDescriptor.&lt;BR&gt;Before XP, it uses a COM component especially written for the purpose of the bin array conversion to an ADSI SD representation (located in the resources folder coming with the ZIP that must be REGSVR32).&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;The sample given there manages the security not only on WMI namespaces, but also on Files, Folders, Shares, AD objects, Exchange Mailboxes and Registry keys.&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;Everything is explained in greater details in the book related to this sample as&amp;nbsp;the full coverage of the details for the management of all SD supported above required 220 pages of texts and tables.&lt;BR&gt;This is not a trivial task even if it is fairly achievable.&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps.&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alex (Alejandro Campos Magencio)&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8172662" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alejacma/archive/tags/WMI/default.aspx">WMI</category><category domain="http://blogs.msdn.com/alejacma/archive/tags/VBScript/default.aspx">VBScript</category></item></channel></rss>