• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How to reduce WMI connection timeout?

D

D.P. Roberts

#1
I have a script that uses WMI to modify registry keys on hundreds of domain
machines (running XP pro). In a nutshell, here's what the script does:

1. Pings each machine, one at a time.
2. If a machine does not reply to the ping, the script skips to the next
machine.
2. If a machine does reply to the ping, the script uses WMI to connect to
the machine and modify a registry key.

In a perfect world, the script would complete in a matter of seconds.
However, sometimes the script cannot make a WMI connection to a machine even
though the machine replied to the ping request. The line of code where it
can hang is this:

Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& strComputer & "/root/default:StdRegProv")

When this happens, the script hangs for a minute or two before finally
timing out and proceeding to the next machine. The end result is that the
script can take 10-20 minutes to complete, depeding on how many machines
can't make the WMI connection at that time. Incidentally, I've noticed when
a machine fails to allow WMI connections, it also doesn't allow remote
connections using Services, Regedit, or Computer Management. A manual reboot
fixes the problem, but it happens sort of randomly across our domain in an
unpredictable way.

So my question is this: How can I force the WMI connection attempt to
timeout earlier - say after 5 seconds instead of 1-2 minutes? Or as an
alternative, is there a way to modify registry keys remotely without using
WMI?

Thanks for any help out there...
 
R

Richard Mueller [MVP]

#2
D.P. Roberts wrote:

>I have a script that uses WMI to modify registry keys on hundreds of domain
>machines (running XP pro). In a nutshell, here's what the script does:
>
> 1. Pings each machine, one at a time.
> 2. If a machine does not reply to the ping, the script skips to the next
> machine.
> 2. If a machine does reply to the ping, the script uses WMI to connect to
> the machine and modify a registry key.
>
> In a perfect world, the script would complete in a matter of seconds.
> However, sometimes the script cannot make a WMI connection to a machine
> even though the machine replied to the ping request. The line of code
> where it can hang is this:
>
> Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
> & strComputer & "/root/default:StdRegProv")
>
> When this happens, the script hangs for a minute or two before finally
> timing out and proceeding to the next machine. The end result is that the
> script can take 10-20 minutes to complete, depeding on how many machines
> can't make the WMI connection at that time. Incidentally, I've noticed
> when a machine fails to allow WMI connections, it also doesn't allow
> remote connections using Services, Regedit, or Computer Management. A
> manual reboot fixes the problem, but it happens sort of randomly across
> our domain in an unpredictable way.
>
> So my question is this: How can I force the WMI connection attempt to
> timeout earlier - say after 5 seconds instead of 1-2 minutes? Or as an
> alternative, is there a way to modify registry keys remotely without using
> WMI?
>
> Thanks for any help out there...
Similar questions have been asked several times, and I'm fairly sure there
is no way to reduce the WMI connection timeout. Many people use a ping
function and specify a short timeout. Al Dunbar has suggested using Net View
to get a list of available computers. However, it appears this won't help
you.

In my experience the WMI connection fails (even if the computer responds to
a ping) if the remote client does not have WMI installed (a Win9x client for
example), or the OS version does not support the WMI class. In rare
instances WMI is either not running or is corrupted. If nothing seems to
connect to the remote computer something else is wrong, especially if a
reboot of the remote computer fixes it. Can you verify that the WMI service
is running before the reboot?

I don't think it will help in your case (because a reboot fixes the
problem), but documentation suggests it can help (with newer OS's) to
specify authenticationLevel:

Set objReg = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _
& strComputer & "/root/default:StdRegProv")

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
 
K

Kellie Fitton

#3
On Aug 6, 4:43 pm, "D.P. Roberts" <dprobe...@xxxxxx> wrote:

>
> So my question is this: How can I force the WMI connection attempt to
> timeout earlier - say after 5 seconds instead of 1-2 minutes? Or as an
> alternative, is there a way to modify registry keys remotely without using
> WMI?
>
> Thanks for any help out there...


Hi,

You can use the following APIs to establish a connection to
a predefined registry handle on another computer and backup
the Windows registry:

GetCurrentProcess()

OpenProcessToken() TOKEN_ADJUST_PRIVILEGES

LookupPrivilegeValue() SE_BACKUP_NAME

AdjustTokenPrivileges() SE_PRIVILEGE_ENABLED

RegConnectRegistry()

RegEnumKeyEx()

RegCreateKeyEx()

RegSaveKeyEx()

RegCloseKey()

AdjustTokenPrivileges(hToken, TRUE, NULL, 0, NULL, NULL);

CloseHandle()

http://msdn2.microsoft.com/en-us/library/ms683179.aspx

http://msdn2.microsoft.com/en-us/library/aa379295.aspx

http://msdn2.microsoft.com/en-us/library/aa379180.aspx

http://msdn2.microsoft.com/en-us/library/aa375202.aspx

http://msdn2.microsoft.com/en-us/library/ms724840.aspx

http://msdn2.microsoft.com/en-us/library/ms724862.aspx

http://msdn2.microsoft.com/en-us/library/ms724844.aspx

http://msdn2.microsoft.com/en-us/library/ms724919.aspx

http://msdn2.microsoft.com/en-us/library/ms724837.aspx

http://msdn2.microsoft.com/en-us/library/ms724211.aspx

Kellie.