Enabling DHCP via VBscript or WMIC

R

Ryan

Has any one know how I can use a VB script or run a WMIC
command to configure one or multiple clients to use DHCP
instead of a static IP address?

WMIC allows me to query a group of machines and to find
which NIC has IP enabled, I'd like to run a simmilar
command or group of commands to enableDHCP for all those
interfaces.

.... Or I'd like to know how to accomplish the same task
using a VB script. Either option works for me, I just
can't seem to get figure the VB script out, and as far as
WMIC, I can't "set" DHCPEnabled = TRUE.

Surely one of you have crossed this path before, could
you please share your experiences with me.
TIA,
-Ryan
 
P

Pegasus \(MVP\)

Here is how you do it in a batch file:

netsh interface ip set dns name="Local Area Connection" source=dhcp
 
R

Ryan

I may have to resort to using that as part of our current
login script with some extra logic. I was under the
impression that I'd have to run that locally on each
machine I want to make the change to DHCP. Do you know
any method to push that or run it remotely via script
from a single console, against a list of machines?
 
P

Pegasus \(MVP\)

Since the script affects the local TCP/IP settings, you
must run it locally. You can push it out from your own
PC by running this script:

@echo off
for /F %%a in (c:\PCs.lst) do call :Action %%a
goto :eof

:Action
if exist \\SomeServer\SomeShare\%1 goto :eof
ping %1 -n 1 | find /i "bytes=" > nul || goto :eof
psexec.exe \\%1 \\SomeServer\Netlogon\DCHP.bat

And here is DHCP.bat:

@echo off
echo %date% %time% %ComputerName% >
\\SomeServer\SomeShare\%ComputerName%
netsh interface ip set dns name="Local Area Connection" source=dhcp

Prerequisites:
- The share \\SomeServer\Netlogon must exist.
- The share \\SomeServer\SomeShare must exist. You must
have write-access to it.
- psexec (www.sysinternals.com) must be in your path
 
R

Ryan

Thanks, I'll tweak the psexec -u and -p options as the
script works locally, but fails remotely due to "access
is denied" I will have to verify requirements for those
switches. I should be able to specify my ID as a (Domain
Admin) and my password to have it operate properly, but
something is missing. I'm a bit tired of testing
tonight, so I'll resume in the morning. Thanks again for
your quick assistance.
 
P

Pegasus \(MVP\)

Every machine I'm responsible for has the same two
local admin accounts, enabling me to access them
remotely at leasure.

You may have to try something like

psexec \\SomePC -u DomainName\JSmith -p SomePassword . . .
or
psexec \\SomePC -u \\ServerName\JSmith -p SomePassword . . .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top