Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DHCP Scopes

Status
Not open for further replies.
Jul 25, 2003
25
US
I am having problems trying to create DHCP Scopes. Though Netsh will perform the task, it has timing flaws and does not work all of the time. The following script uses dhcpobjs.dll but when used gives me a "Activex unable to create object DhcpObjects.Manager" error. Dhcpobjs.dll was registered successfully so it says but the error persists. Can anyone help with this or provide another way to script the creation of dhcp scopes without using objShell.Run (netsh)?

set dhcpmanager=CreateObject("DhcpObjects.Manager") 'Create objects for use
set dhcpserver=CreateObject("DhcpObjects.Server")
set dhcpserver = dhcpmanager.servers.Connect(strServer1)
Set dhcpscopeNew = dhcpserver.Scopes.CreateNew()

dhcpscopeNew.StartAddress=strIpRangeBegin 'Create new scope
dhcpscopeNew.EndAddress = strIpRangeEnd
dhcpscopeNew.Mask = strdhcpSubNet
dhcpscopeNew.Name = strdhcpname
dhcpscopeNew.Active = True
dhcpscopeNew.Update

dhcpserver.Scopes(strdhcpIP).Exclusions.CreateNew() 'Create 1st exclusion
dhcpserver.StartAddress = strIpRangeBegin
dhcpserver.EndAddress = strExRangeEnd31
dhcpserver.Update

dhcpserver.Scopes(strdhcpIP).Exclusions.CreateNew() 'Create 2nd exclusion
dhcpserver.StartAddress = strExRangeBegin144
dhcpserver.EndAddress = strIpRangeEnd
dhcpserver.Update

dhcpserver.Scopes(strdhcpIP).Options.Add 3, strIPRouter 'Configure scope
dhcpserver.Scopes(strdhcpIP).Options.Add 6, Array(strdhcpDNS1, strdhcpDNS1)
dhcpserver.Scopes(strdhcpIP).Options.Add 15, strDnsPath
dhcpserver.Scopes(strdhcpIP).Options.Add 51, 259200
dhcpserver.Update

dhcpserver.Disconnect
 
Seems I have stumbled onto the answer by accident. The following script:

set dhcpmanager=CreateObject("DhcpObjects.Manager") 'Create objects for use
set dhcpserver=CreateObject("DhcpObjects.Server")
set dhcpserver = dhcpmanager.servers.Connect(strServer1)
Set dhcpscopeNew = dhcpserver.Scopes.CreateNew()

should have been written this way:

set dhcpmanager=CreateObject("Dhcp.Manager") 'Create objects for use
set dhcpserver = dhcpmanager.servers.Connect(strServer1)
Set dhcpscopeNew = dhcpserver.Scopes.CreateNew

This part now works fine but I am missing the reference list for the possible properties and methods available for Dhcpobjs.dll. I now have a problem with the DHCP Scope Options. The following portion of the script still returns an error.

dhcpserver.Scopes(strdhcpIP).Options.Add 3, strIPRouter 'Configure scope
dhcpserver.Scopes(strdhcpIP).Options.Add 6, Array(strdhcpDNS1, strdhcpDNS1)
dhcpserver.Scopes(strdhcpIP).Options.Add 15, strDnsPath
dhcpserver.Scopes(strdhcpIP).Options.Add 51, 259200
dhcpserver.Update

Option 3, 6, 15 and 51 are appearently not written in vbscript this way. Anyone have any help on what Dhcpobjs.dll requires for syntax on scope options?
 
Again it seems I have found the solution with the help of a neat object viewer called OLEView.exe. The proper full script should be:

set dhcpmanager = CreateObject("Dhcp.Manager")
set dhcpserver = dhcpmanager.servers.Connect(strdhcpserver1)

Set dhcpscopeNew = dhcpserver.Scopes.CreateNew 'Creates scope
dhcpscopeNew.StartAddress = strIpRangeBegin
dhcpscopeNew.EndAddress = strIpRangeEnd
dhcpscopeNew.Mask = strdhcpSubNet
dhcpscopeNew.Name = strdhcpname
dhcpscopeNew.Active = True
dhcpscopeNew.Update

set dhcpExclusionNew = dhcpserver.Scopes(strdhcpIP).Exclusions.CreateNew 'Sets exclusion range
dhcpExclusionNew.StartAddress = strIpRangeBegin
dhcpExclusionNew.EndAddress = strExRangeEnd31
dhcpExclusionNew.Update

set dhcpOptionValues = dhcpserver.Scopes(strScopeIP).Options.CreateNew 'Sets Router IP Address
dhcpOptionValues.ID = 3
dhcpOptionValues.Value = Array(strIPRouter)
dhcpOptionValues.Update

set dhcpOptionValues1 = dhcpserver.Scopes(strScopeIP).Options.CreateNew 'Sets DNS IP Addresses
dhcpOptionValues1.ID = 6
dhcpOptionValues1.Value = Array(strdhcpDNS1, strdhcpDNS2)
dhcpOptionValues1.Update

set dhcpOptionValues2 = dhcpserver.Scopes(strdhcpIP).Options.CreateNew 'Sets DNS path
dhcpOptionValues2.ID = 15
dhcpOptionValues2.Value = strDnsPath
dhcpOptionValues2.Update

set dhcpOptionValues3 = dhcpserver.Scopes(strdhcpIP).Options.CreateNew 'Sets lease time (259200 = 3 Days)
dhcpOptionValues3.ID = 51
dhcpOptionValues3.Value = 259200
dhcpOptionValues3.Update

dhcpserver.Disconnect

For anyone who wants to create scopes via vbscript, here you go.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top