soha_1
09-02-2013, 11:56
اخوتي لدي شبكه تحتوي على ويندوز سيرفر 2008 و مربوط بها 64 جهاز يحملون ويندوز اكس بي و الجميع متصلين با السيرفر , كل المستخدمين الان يملكون اي بي معرف يدويا , وقد قمت بتشغيل ال DHCP و اردت تحويل الاي بي مره واحده عن طريق group policy وو جدت انه يجب استخدام سكريب لعمل ذلك , احضرت سكربتان (سوف اضعهم في الاسفل ) واضفت السكريب في جروب و ووضتعها تحت قسم الكمبيوتر والمستخدم و وضعتها تحت التشغيل و رفعت زمن التشغيل الى 30 ثانيه وربطت الجروب با الدومين و لكن شيئا لم يحدث !!! هل من الممكن ان يساعديني احدكم ؟؟؟
اختكم في الله سها ...
السكربت الاول اسميته DHCP.vbs
'----------------------------------------------------------------------------------------------------------------------------
'Script Name : EnableDHCP.vbs
'Author : Matthew Beattie
'Created : 29/12/10
'Description : This script enables DHCP for systems on specified subnets.
'----------------------------------------------------------------------------------------------------------------------------
'Initialization Section
'----------------------------------------------------------------------------------------------------------------------------
Option Explicit
Dim objFSO, wshShell, wshNetwork, hostName
On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshNetwork = Wscript.CreateObject("Wscript.Network")
Set wshShell = CreateObject("Wscript.Shell")
hostName = wshNetwork.ComputerName
ProcessScript
If Err.Number <> 0 Then
Wscript.Quit
End If
On Error Goto 0
'----------------------------------------------------------------------------------------------------------------------------
'Name : ProcessScript -> Primary Function that controls all other script processing.
'Parameters : None ->
'Return : None ->
'----------------------------------------------------------------------------------------------------------------------------
Function ProcessScript
Dim ipAddress, macAddress, product, systems, system
Dim subnets, subnet, network, continue
product = ReadRegistry("HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProductName")
systems = Array("Windows XP","Windows 7")
subnets = Array("192.168.1.0")
'-------------------------------------------------------------------------------------------------------------------------
'Ensure this script only applies to client operating systems. (Don't configure servers with DHCP!)
'-------------------------------------------------------------------------------------------------------------------------
Continue = False
For Each system In systems
If InStr(1, product, system, vbTextCompare) <> 0 Then
continue = True
Exit For
End If
Next
If Not continue Then
Exit Function
End If
'-------------------------------------------------------------------------------------------------------------------------
'Enumerate the IP and MAC Addresses from the local system.
'-------------------------------------------------------------------------------------------------------------------------
If Not GetIPConfig(hostName, ipAddress, macAddress) Then
Exit Function
End If
'-------------------------------------------------------------------------------------------------------------------------
'Ensure the script continues processing only if the systems IP address is within the specified subnets.
'-------------------------------------------------------------------------------------------------------------------------
network = Left(ipAddress, InStrRev(ipAddress, ".")) & "0"
continue = False
For Each subnet In subnets
If StrComp(subnet, network, vbTextCompare) = 0 Then
continue = True
Exit For
End If
Next
'-------------------------------------------------------------------------------------------------------------------------
'Ensure the script only continues processing if the systems IP address is within the specified subnets.
'-------------------------------------------------------------------------------------------------------------------------
If Not continue Then
Exit Function
End If
'-------------------------------------------------------------------------------------------------------------------------
'The system is within one of the specified subnets. Enable DHCP on all enabled interfaces that have static IP Addresses.
'-------------------------------------------------------------------------------------------------------------------------
If Not EnableDHCP Then
Exit Function
End If
End Function
'----------------------------------------------------------------------------------------------------------------------------
'Name : ReadRegistry -> Read the value of a registry key or value.
'Parameters : key -> Name of the key (ending in "\") or value to read.
'Return : ReadRegistry -> Value of key or value read from the local registry (blank is not found).
'----------------------------------------------------------------------------------------------------------------------------
Function ReadRegistry(ByVal key)
Dim result
If StrComp (Left (key, 4), "HKU\", vbTextCompare) = 0 Then
Key = "HKEY_USERS" & Mid (key, 4)
End If
On Error Resume Next
ReadRegistry = WshShell.RegRead (key)
If Err.Number <> 0 Then
ReadRegistry = ""
End If
On Error Goto 0
End Function
'----------------------------------------------------------------------------------------------------------------------------
'Name : GetIPConfig -> Enumerates the IP & MAC Address of the system via WMI
'Parameters : hostName -> String containing the hostname of the computer to enumerate the IP configuration for.
' : ipAddress -> Input/Output : Variable assigned to the IP Address of the system.
'Parameters : macAddress -> Input/Output : Variable assigned to the MAC Address of the system.
'Return : GetIPConfig -> Returns True and the systems IP & MAC Address if successful otherwise returns False.
'----------------------------------------------------------------------------------------------------------------------------
Function GetIPConfig(hostName, ipAddress, macAddress)
Dim wmi, ipConfig, query
GetIPConfig = False
ipAddress = ""
macAddress = ""
query = "select * from Win32_NetworkAdapterConfiguration where IPEnabled = True"
On Error Resume Next
Set wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & hostName & "\root\cimv2")
If Err.Number <> 0 Then
Exit Function
End If
For Each ipConfig in wmi.ExecQuery(query)
If Err.Number <> 0 Then
Exit Function
End If
ipAddress = ipConfig.IPAddress(0)
macAddress = ipConfig.MACAddress(0)
If ipAddress <> "" And ipAddress <> "0.0.0.0" And MACAddress <> "" Then
Exit For
End If
Next
On Error Goto 0
GetIPConfig = True
End Function
'----------------------------------------------------------------------------------------------------------------------------
'Name : EnableDHCP -> enables DHCP on all interfaces that have static IP Addresses.
'Parameters : hostName -> String containing the hostname of the system to enable DHCP on.
'Return : EnableDHCP -> Returns True if DHCP was enabled otherwise False.
'----------------------------------------------------------------------------------------------------------------------------
Function EnableDHCP
Dim query, wmi, adapter, adapters, result
EnableDHCP = False
query = "Select * From Win32_NetworkAdapterConfiguration Where DHCPEnabled = False And IPEnabled = True"
On Error Resume Next
Set wmi = GetObject("winmgmts:\\" & hostName & "\root\cimv2")
Set adapters = wmi.ExecQuery(query)
For Each adapter In adapters
result = adapter.EnableDHCP()
Next
If Err.Number <> 0 Then
Exit Function
End If
On Error Goto 0
EnableDHCP = True
End Function
'----------------------------------------------------------------------------------------------------------------------------
السكربت الثاني اسميته DHCP.bat
REM Start Script
netsh interface ip set address "Local Area Connection" dhcp
netsh interface ip set DNS "Local Area Connection" dhcp
:end
REM End script
اختكم في الله سها ...
السكربت الاول اسميته DHCP.vbs
'----------------------------------------------------------------------------------------------------------------------------
'Script Name : EnableDHCP.vbs
'Author : Matthew Beattie
'Created : 29/12/10
'Description : This script enables DHCP for systems on specified subnets.
'----------------------------------------------------------------------------------------------------------------------------
'Initialization Section
'----------------------------------------------------------------------------------------------------------------------------
Option Explicit
Dim objFSO, wshShell, wshNetwork, hostName
On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshNetwork = Wscript.CreateObject("Wscript.Network")
Set wshShell = CreateObject("Wscript.Shell")
hostName = wshNetwork.ComputerName
ProcessScript
If Err.Number <> 0 Then
Wscript.Quit
End If
On Error Goto 0
'----------------------------------------------------------------------------------------------------------------------------
'Name : ProcessScript -> Primary Function that controls all other script processing.
'Parameters : None ->
'Return : None ->
'----------------------------------------------------------------------------------------------------------------------------
Function ProcessScript
Dim ipAddress, macAddress, product, systems, system
Dim subnets, subnet, network, continue
product = ReadRegistry("HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProductName")
systems = Array("Windows XP","Windows 7")
subnets = Array("192.168.1.0")
'-------------------------------------------------------------------------------------------------------------------------
'Ensure this script only applies to client operating systems. (Don't configure servers with DHCP!)
'-------------------------------------------------------------------------------------------------------------------------
Continue = False
For Each system In systems
If InStr(1, product, system, vbTextCompare) <> 0 Then
continue = True
Exit For
End If
Next
If Not continue Then
Exit Function
End If
'-------------------------------------------------------------------------------------------------------------------------
'Enumerate the IP and MAC Addresses from the local system.
'-------------------------------------------------------------------------------------------------------------------------
If Not GetIPConfig(hostName, ipAddress, macAddress) Then
Exit Function
End If
'-------------------------------------------------------------------------------------------------------------------------
'Ensure the script continues processing only if the systems IP address is within the specified subnets.
'-------------------------------------------------------------------------------------------------------------------------
network = Left(ipAddress, InStrRev(ipAddress, ".")) & "0"
continue = False
For Each subnet In subnets
If StrComp(subnet, network, vbTextCompare) = 0 Then
continue = True
Exit For
End If
Next
'-------------------------------------------------------------------------------------------------------------------------
'Ensure the script only continues processing if the systems IP address is within the specified subnets.
'-------------------------------------------------------------------------------------------------------------------------
If Not continue Then
Exit Function
End If
'-------------------------------------------------------------------------------------------------------------------------
'The system is within one of the specified subnets. Enable DHCP on all enabled interfaces that have static IP Addresses.
'-------------------------------------------------------------------------------------------------------------------------
If Not EnableDHCP Then
Exit Function
End If
End Function
'----------------------------------------------------------------------------------------------------------------------------
'Name : ReadRegistry -> Read the value of a registry key or value.
'Parameters : key -> Name of the key (ending in "\") or value to read.
'Return : ReadRegistry -> Value of key or value read from the local registry (blank is not found).
'----------------------------------------------------------------------------------------------------------------------------
Function ReadRegistry(ByVal key)
Dim result
If StrComp (Left (key, 4), "HKU\", vbTextCompare) = 0 Then
Key = "HKEY_USERS" & Mid (key, 4)
End If
On Error Resume Next
ReadRegistry = WshShell.RegRead (key)
If Err.Number <> 0 Then
ReadRegistry = ""
End If
On Error Goto 0
End Function
'----------------------------------------------------------------------------------------------------------------------------
'Name : GetIPConfig -> Enumerates the IP & MAC Address of the system via WMI
'Parameters : hostName -> String containing the hostname of the computer to enumerate the IP configuration for.
' : ipAddress -> Input/Output : Variable assigned to the IP Address of the system.
'Parameters : macAddress -> Input/Output : Variable assigned to the MAC Address of the system.
'Return : GetIPConfig -> Returns True and the systems IP & MAC Address if successful otherwise returns False.
'----------------------------------------------------------------------------------------------------------------------------
Function GetIPConfig(hostName, ipAddress, macAddress)
Dim wmi, ipConfig, query
GetIPConfig = False
ipAddress = ""
macAddress = ""
query = "select * from Win32_NetworkAdapterConfiguration where IPEnabled = True"
On Error Resume Next
Set wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & hostName & "\root\cimv2")
If Err.Number <> 0 Then
Exit Function
End If
For Each ipConfig in wmi.ExecQuery(query)
If Err.Number <> 0 Then
Exit Function
End If
ipAddress = ipConfig.IPAddress(0)
macAddress = ipConfig.MACAddress(0)
If ipAddress <> "" And ipAddress <> "0.0.0.0" And MACAddress <> "" Then
Exit For
End If
Next
On Error Goto 0
GetIPConfig = True
End Function
'----------------------------------------------------------------------------------------------------------------------------
'Name : EnableDHCP -> enables DHCP on all interfaces that have static IP Addresses.
'Parameters : hostName -> String containing the hostname of the system to enable DHCP on.
'Return : EnableDHCP -> Returns True if DHCP was enabled otherwise False.
'----------------------------------------------------------------------------------------------------------------------------
Function EnableDHCP
Dim query, wmi, adapter, adapters, result
EnableDHCP = False
query = "Select * From Win32_NetworkAdapterConfiguration Where DHCPEnabled = False And IPEnabled = True"
On Error Resume Next
Set wmi = GetObject("winmgmts:\\" & hostName & "\root\cimv2")
Set adapters = wmi.ExecQuery(query)
For Each adapter In adapters
result = adapter.EnableDHCP()
Next
If Err.Number <> 0 Then
Exit Function
End If
On Error Goto 0
EnableDHCP = True
End Function
'----------------------------------------------------------------------------------------------------------------------------
السكربت الثاني اسميته DHCP.bat
REM Start Script
netsh interface ip set address "Local Area Connection" dhcp
netsh interface ip set DNS "Local Area Connection" dhcp
:end
REM End script