質問

I want to make a batch script that changes the IP of an interface on Windows XP. It is possible through the netsh utility:

netsh interface ip set address name="Local Area Connection 2" static 10.0.2.2 255.255.255.0 none

However, the netsh utility requires the dhcp service to be enabled, even though we are setting a static address.

The script itself is not run by the user, but automatically when the system starts up, and it's not guaranteed that the dhcp service will be ready yet.

When I try to call sc start dhcp, the system returns the output immediately, even though the service is NOT ready yet (calling the netsh command afterwards will result in a Failed to configure the DHCP service. The interfrace may be disconnected).

When I wait 30 seconds between starting the service and running the netsh command, everything works fine. However just waiting is not the right way to handle this situation.

Any ideas?

役に立ちましたか?

解決

wmic and sc can show you the running state of a service. See this answer.

Something else of note:

While testing, it occurs to me that net start will block until complete, whereas sc start is non-blocking. Is it possible for you to use net instead of sc?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top