`
ihuashao
  • 浏览: 4745007 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

Dealing with WMI Timeouts (c#)

阅读更多

There was a question in the PowerShellCommunity.Org forums about WMI timeouts.

I did some digging and found there are several different types of timeouts that can affect your WMI queries. I’m still working through different scenarios and I’d appreciate any feedback.

The first type of timeout can occur if the machine that you are targeting does not respond to network traffic (it’s down, you have the wrong IP address, firewalled, etc..). Your WMI call will usually time out after around 20 seconds.

A partial solution to that type of timeout is to ping the machine first. If you can ping that machine, you’ve eliminated a number of potential problems. You still might have permission issues or firewall issues, but you are able to reach the machine.

The second time of timeout I’ve seen is when the connection is made, but the WMI call hangs and does not return.

A potential fix for this issue is to use the [WMISearcher] accelerator. In the options property of the resulting object, there is a ReturnImmediately property, which should be set by default to true.

$searcher = [WMISearcher]”

$searcher.Options.ReturnImmediately

The ReturnImmediately property being set to true requires that the invoked operation (the search) be done synchronously and return immediately. The enumeration of the results of the WMI call are handled after the return of this operation.

An alternative solution for this issue would be to check the Transaction timeout setting on the target machine. Run DCOMCnfg.exe and navigate to the Component Services->My Computer. Right click and choose properties. On the options tab, there is a timeout (in seconds) for DCOM transactions. The default value for this setting is 60 seconds. Fiddle with that at your own risk. Also, I haven’t had a chance to check for where that value is in the registry or see if there is a Group Policy setting for it. Setting this value should allow a failed WMI connection to timeout more quickly.

The third area in which I’ve found timeouts/hangs in WMI queries is during the enumeration of the query results.

There is a property in options for the WMI class accelerator called Timeout, which sets the length of time between enumerations before timing out. The options property is hidden in the default view of PowerShell, so you will need to access it via the psbase property.

The timeout value is a System.TimeSpan object. You can specify the value with a TimeSpan object, a number of ticks, or a string that can be cast to a TimeSpan.

It can be set like this:

$wmi = [wmi]”

$wmi.psbase.options.timeout =’0:0:2′ #String that will be cast to a two second TimeSpan

You can also set a timeout value for the [WMISearcher] accelerator.

$searcher = [WMISearcher]”

$searcher.Options.timeout = ‘0:0:2′

WMI timeouts can be aggravating, hopefully one of these solutions will help mitigate your WMI woes.

http://blog.usepowershell.com/2009/01/dealing-with-wmi-timeouts/

[C#]
ManagementObjectSearcher s = new ManagementObjectSearcher(
"root\\MyApp",
"SELECT * FROM MyClass",
new EnumerationOptions(null, InfiniteTimeout, 1, true, false, true);

http://msdn.microsoft.com/en-us/library/aa329203(VS.71).aspx

EnumerationOptions Members

Timeout

Gets or sets the time-out to apply to the operation. Note that for operations that return collections, this time-out applies to the enumeration through the resulting collection, not the operation itself (the ReturnImmediately property is used for the latter). This property is used to indicate that the operation should be performed semi-synchronously. (Inherited from ManagementOptions.)

http://msdn.microsoft.com/en-us/library/aa329203(VS.71).aspx

分享到:
评论

相关推荐

    八年级英语Dealing with troublePPT课件.pptx

    这篇PPT课件是针对八年级英语教学的内容,主题为“应对困难”(Dealing with trouble)。通过一系列的填空练习和情景模拟,旨在帮助学生掌握如何在不同情况下正确处理问题,尤其是面对紧急情况时的应对策略。以下是...

    Dealing with Undesirable Outputs in DEA: A Slacks-based Measure(SBM) Approach

    在进行数据包络分析(Data Envelopment Analysis, DEA)研究时,经常需要面对的问题之一是如何处理非期望产出(undesirable outputs)。传统DEA模型在处理生产效率分析时通常假设决策单元(Decision Making Units, ...

    Image Processing:Dealing With Texture

    《图像处理:处理纹理》是图像处理领域内一部权威性的著作,由Maria Petrou和Pedro Garcia Sevilla两位学者共同编写,他们分别来自英国伦敦帝国理工学院和西班牙卡斯特利翁的Jaume I大学。该书由全球知名的学术出版...

    C# and XML Primer

    This guide helps you avoid the pitfalls of dealing with XML and C# since handling XML with C# and the .NET Platform can present its own set of challenges. XML is far from a dead technology, so it is ...

    r scripts for dealing with mturk survey

    R scripts for dealing with mturk

    Dealing with stress.doc

    "Dealing With Stress" 这个主题的工作坊就是为此而设,旨在帮助参与者理解和管理他们面临的压力。 首先,我们要理解压力的来源。在大学生活中,学生面临的主要压力源包括: 1. **学术压力**:大学课程繁重,报告...

    Chapter 3 Dealing with trouble测试题2.doc

    Chapter 3 Dealing with trouble测试题2.doc

    dealing with hard people

    "Dealing with Hard People"这一主题,虽然看似不直接涉及技术,但它实际上对提升工作效率和团队协作至关重要。在这个知识领域,我们将深入探讨如何在复杂的职场环境中处理人际关系,特别是那些难缠的人物。 首先,...

    Dealing_With_Difficult_People (en)

    - - 与人交往中注意的一些容易被跳过的细节.以及基础理论分析与人交往出现的情况.

    一个进行 Unicode 相关字符串转换的易语言库 An Eyuyan library dealing with Unicode string conversion.zip

    An Eyuyan library dealing with Unicode string conversion.Unicode-Eyuyan一个进行 Unicode 相关字符串转换的易语言库。一个处理 Unicode 字符串转换的 Eyuyan 库。背景 Background易语言是一个面向初学者的编程...

    八年级英语Dealing with troublePPT学习教案.pptx

    这篇PPT学习教案是针对八年级英语的一课,主题为"Dealing with trouble",旨在帮助学生学习如何处理各种突发状况。以下是对其中涉及的知识点的详细解释: 1. **词汇与短语**: - **hurry**:匆忙,表示动作迅速。 ...

    Dealing with Audio Ground Loops

    音频地环回问题详解 音频地环回是音频系统中常见的问题,主要由于不同设备通过不同的路径连接到共同的地线而产生。这种多路径接地方式实际上就像一个天线,会拾取并引入干扰。当地环回发生时,地线(通常是屏蔽层)...

    处理不均衡数据 (深度学习)! Dealing with imbalanced data (deep learning)

    处理不均衡数据_(深度学习)!_Dealing_with_imbalanced_data_(deep_learning)

    ASTM E178 - 21 Standard Practice for Dealing With Outlying Obser

    标题中的"ASTM E178 - 21"指的是美国材料与...通过阅读提供的"ASTM E178 - 21 Standard Practice for Dealing With Outlying Observations - 完整英文版(11页).pdf"文件,可以深入学习这一标准的细节和具体实施步骤。

    MFC dealing with window size_IntheFrame_MFC实例_

    在Microsoft Foundation Class (MFC)库中,"MFC dealing with window size_IntheFrame_MFC实例_" 主题涉及如何在框架窗口(Frame Window)中管理子窗口(Subwindow)的大小。MFC是C++的一个类库,它为Windows应用...

    The C# Player’s Guide, 3rd Edition

    Learn to control the tools and tricks of programming in C#, including the .NET framework, dealing with compiler errors, and hunting down bugs in your program. Master the needed skills by taking on a ...

    Functional C#[January 2017].pdf

    Chapter 11, Coding Best Practice and Testing the Functional Code, explains the best practice in the functional approach, including the creation of an honest signature and dealing with the side-effects...

    Multi-Label classification: Dealing with Imbalance by Combining Labels

    ### 多标签分类:通过合并标签处理不平衡问题 #### 摘要与介绍 本文讨论了一个在多标签分类(Multi-Label Classification, MLC)领域中的常见问题——数据不平衡,并提出了一种新颖的方法来解决这一难题。...

Global site tag (gtag.js) - Google Analytics