0

I am writing some script that automatically executes during startup of computer (XP), the script is actually mapping a network drive to windows. The problem I have is that the DHCP in the network is not responding fast enough and that the script executes before the system got IP. So an error would occur.

Before putting the system under AD, my solution is to make the script "Sleep" for about 30 seconds and of course this is just an ad-hoc solution. Any related script that can do such job?

xandy
  • 105
  • 1
  • 1
  • 4

2 Answers2

1

A common (and somewhat kludgy) way to solve this problem is to write a function that "waits for the network" by essentially trying to ping a host until it succeeds. You can optionally include a timeout value where the script will eventually give up. I have a JScript based version of this function if you'd like me to post it.

I would think a more elegant way to do this would be to use WMI to query the status of the network adapter in a loop until you've got a valid IP address. I don't have an example of doing this though.

Here are some other things to think about when choosing a solution. It will be up to you to determine how robust you care to make it.

  • Just because DHCP has returned a valid IP doesn't mean you can connect to your fileserver
  • Just because you can ping your fileserver doesn't mean mapping a drive will always work
Ryan Bolger
  • 16,755
  • 4
  • 42
  • 64
0

I can't tell for sure from the question, but if the PC is joined to a domain, you can apply the policy:

Computer Configuration\Administrative Templates\System\Logon\

Always wait for the network at computer startup and logon

via GPO to force the PC to wait for the network before giving a logon prompt. If the PC isn't a domain member, you could set the same policy using GPEdit or maybe via a reghack.

sahmeepee
  • 146
  • 3