5

ログオン時の WMI の可用性に問題があります。

再起動直後に、cmd を開き、Python インタープリターを使用します。

>>> import wmi
>>> c = wmi.WMI()
>>> c.Win32_OperatingSystem()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\wmi.py", line 1147, in __getattr__
    return getattr (self._namespace, attribute)
  File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 516, in
__getattr__
    raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: winmgmts:.Win32_OperatingSystem
>>>

5 分後、別のcmd と python インタープリターを開きます。

Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wmi
>>> c = wmi.WMI()
>>> c.Win32_OperatingSystem()
[<_wmi_object: \\W520-ALEX-WIN7\root\cimv2:Win32_OperatingSystem=@>]
>>>

注: 最初の cmd は、 5 分後でもAttributeErrorを言い続けます。

注2:ログアウトしてログインすると、wmiが利用可能になるため、再起動によって何らかの影響を受けます

プロセスエクスプローラーで環境変数を確認しましたが、両方のコマンドで同じです

それは何でしょうか?助けてください。

更新:どうやら問題は wbem サービスへの接続にあります:

>>> import win32com.client
>>> win32com.client.Dispatch('WbemScripting.SWbemLocator')
<COMObject WbemScripting.SWbemLocator>
>>> wmi_service= win32com.client.Dispatch('WbemScripting.SWbemLocator')
>>> wbem_service =  wmi_service.ConnectServer('.','root/cimv2')
>>> wbem_service
<COMObject <unknown>>
>>> items = wbem_service.ExecQuery('Select * from Win32_OperatingSystem')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<COMObject <unknown>>", line 3, in ExecQuery
  File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 282, in
_ApplyTypes_
    result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes
) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'SWbemServicesEx
', u'Generic failure ', None, 0, -2147217407), None)
>>>

注3:wmic os常に機能しました。

注 4: pywin32 パッケージを再インストールしても解決しませんでした。WMI コンポーネントの再登録/再コンパイル、および WMI データベースのリセットも行われませんでした (ここで推奨されているように) 。

注 5: 私の 4 他のラップトップにはこの問題はありません。

また、wmiprov.logには次の情報があります。

(Mon Oct 29 11:40:07 2012.248587) : ***************************************
(Mon Oct 29 11:40:07 2012.248587) : Could not get pointer to binary resource for file:
(Mon Oct 29 11:40:07 2012.248587) : C:\Windows\system32\drivers\ndis.sys[MofResourceName](Mon Oct 29 11:40:07 2012.248587) : 
(Mon Oct 29 11:40:07 2012.248587) : ***************************************
(Mon Oct 29 11:40:07 2012.248587) : ***************************************
(Mon Oct 29 11:40:07 2012.248587) : Could not get pointer to binary resource for file:
(Mon Oct 29 11:40:07 2012.248587) : C:\Windows\system32\drivers\en-US\ndis.sys.mui[MofResourceName](Mon Oct 29 11:40:07 2012.248587) : 
(Mon Oct 29 11:40:07 2012.248587) : ***************************************
(Mon Oct 29 11:40:07 2012.248603) : ***************************************
(Mon Oct 29 11:40:07 2012.248603) : Could not get pointer to binary resource for file:
(Mon Oct 29 11:40:07 2012.248603) : C:\Windows\system32\DRIVERS\wmiacpi.sys[MofResource](Mon Oct 29 11:40:07 2012.248603) : 
(Mon Oct 29 11:40:07 2012.248603) : ***************************************
(Mon Oct 29 11:40:07 2012.248603) : ***************************************
(Mon Oct 29 11:40:07 2012.248603) : Could not get pointer to binary resource for file:
(Mon Oct 29 11:40:07 2012.248603) : C:\Windows\system32\DRIVERS\monitor.sys[MonitorWMI](Mon Oct 29 11:40:07 2012.248603) : 
(Mon Oct 29 11:40:07 2012.248603) : ***************************************

注 6: WMIDiag ツールのレポートはドロップボックスにあります

4

0 に答える 0