[UDF] Configuration réseau


SUBMITTED BY: Guest

DATE: May 28, 2013, 6:29 a.m.

FORMAT: Text only

SIZE: 53.7 kB

HITS: 2898

  1. #CS
  2. #INDEX ========================================================================================================================
  3. Title................: Network informations and configuration for AutoIt
  4. Filename.............: network.au3
  5. Author...............: J1GUINCHARD
  6. Version..............: 3.3.8.1
  7. Date.................: 2013-24-29
  8. ! #RequireAdmin is needed to use some functions !
  9. Available functions :
  10. _DisableNetAdapter
  11. _EnableDHCP
  12. _EnableDHCP_DNS
  13. _EnableNetAdapter
  14. _EnableStatic
  15. _ErrFunc
  16. _FlushDNS
  17. _GetNetworkAdapterFromID
  18. _GetNetworkAdapterInfos
  19. _GetNetworkAdapterList
  20. _GetNetworkGUI
  21. _GetNetworkIDFromAdapter
  22. _InitWmi
  23. _ReleaseDHCPLease
  24. _RenewDHCPLease
  25. _SetDNSDomain
  26. _SetDNSServerSearchOrder
  27. _SetDNSSuffixSearchOrder
  28. _SetDynamicDNSRegistration
  29. _SetGateways
  30. _SetWINSServer
  31. Internal functions :
  32. _WMIDate
  33. _Array2String (from array.au3)
  34. Remarks.......:
  35. Some functions may fail (returns 0). @error is set to these values :
  36. 64 = Method not supported on this platform.
  37. 65 = Unknown failure.
  38. 66 = Invalid subnet mask.
  39. 67 = An error occurred while processing an instance that was returned.
  40. 68 = Invalid input parameter.
  41. 69 = More than five gateways specified.
  42. 70 = Invalid IP address.
  43. 71 = Invalid gateway IP address.
  44. 72 = An error occurred while accessing the registry for the requested information.
  45. 73 = Invalid domain name.
  46. 74 = Invalid host name.
  47. 75 = No primary or secondary WINS server defined.
  48. 76 = Invalid file.
  49. 77 = Invalid system path.
  50. 78 = File copy failed.
  51. 79 = Invalid security parameter.
  52. 80 = Unable to configure TCP/IP service.
  53. 81 = Unable to configure DHCP service.
  54. 82 = Unable to renew DHCP lease.
  55. 83 = Unable to release DHCP lease.
  56. 84 = IP not enabled on adapter.
  57. 85 = IPX not enabled on adapter.
  58. 86 = Frame or network number bounds error.
  59. 87 = Invalid frame type.
  60. 88 = Invalid network number.
  61. 89 = Duplicate network number.
  62. 90 = Parameter out of bounds.
  63. 91 = Access denied.
  64. 92 = Out of memory.
  65. 93 = Already exists.
  66. 94 = Path, file, or object not found.
  67. 95 = Unable to notify service.
  68. 96 = Unable to notify DNS service.
  69. 97 = Interface not configurable.
  70. 98 = Not all DHCP leases could be released or renewed.
  71. 100 = DHCP not enabled on the adapter.
  72. #==============================================================================================================================
  73. #CE
  74. Global Const $wbemFlagReturnImmediately = 0x10
  75. Global Const $wbemFlagForwardOnly = 0x20
  76. Global $objWMIService
  77. Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
  78. Global $errFunc = 0
  79. ; #FUNCTION# ====================================================================================================================
  80. ; Name...........: _InitWmi
  81. ; Description....: Connects to the local WMI provider.
  82. ; Syntax.........: _InitWmi()
  83. ; Return values..: Success - 1
  84. ; Failure - 0
  85. ; ===============================================================================================================================
  86. Func _InitWmi()
  87. $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
  88. If $objWMIService = 0 Then Return 0
  89. Return 1
  90. EndFunc ; ===> _initWmi
  91. ; #FUNCTION# ====================================================================================================================
  92. ; Name...........: _DisableNetAdapter
  93. ; Description....: Disables the specified network adapter.
  94. ; Syntax.........: _DisableNetAdapter($sNetAdapter)
  95. ; Parameters.....: $sNetAdapter - Name of the network adapter.
  96. ; The Windows network connection name can be used instead of network adapter.
  97. ; Return values..: Success - 1
  98. ; Failure - 0
  99. ; ===============================================================================================================================
  100. Func _DisableNetAdapter($sNetAdapter)
  101. Local $sQueryNetAdapterConfig, $colNetAdapterConfig, $objNetAdapter , $iReturn = 0
  102. Local $adapterName
  103. $adapterName = _GetNetworkAdapterFromID($sNetAdapter)
  104. If $adapterName Then $sNetAdapter = $adapterName
  105. $sQueryNetAdapterConfig = "select * from Win32_NetworkAdapter Where Name = '" & $sNetAdapter & "'"
  106. $colNetAdapterConfig = $objWMIService.ExecQuery($sQueryNetAdapterConfig, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  107. If NOT IsObj($colNetAdapterConfig) Then Return 0
  108. For $objNetAdapter In $colNetAdapterConfig
  109. $iReturn = $objNetAdapter.Disable()
  110. If $iReturn == 0 Then Return 1
  111. Next
  112. Return 0
  113. EndFunc ; ===> _DisableNetAdapter
  114. ; #FUNCTION# ====================================================================================================================
  115. ; Name...........: _EnableDHCP
  116. ; Description....: Enables the Dynamic Host Configuration Protocol (DHCP) for IP configuration.
  117. ; Syntax.........: _EnableDHCP($sNetAdapter)
  118. ; Parameters.....: $sNetAdapter - Name of the network adapter.
  119. ; The Windows network connection name can be used instead of network adapter.
  120. ; Return values..: Success - 1 or 2 (reboot required)
  121. ; Failure - 0 and sets @error (see remarks)
  122. ;
  123. ; Remarks........: When the function fails (returns 0) @error contains extended information (see global remarks).
  124. ; ===============================================================================================================================
  125. Func _EnableDHCP($sNetAdapter)
  126. Local $sQueryNetAdapterConfig, $colNetAdapterConfig, $objNetAdapter, $iReturn = 0
  127. Local $adapterName
  128. $adapterName = _GetNetworkAdapterFromID($sNetAdapter)
  129. If $adapterName Then $sNetAdapter = $adapterName
  130. $sQueryNetAdapterConfig = "select * from Win32_NetworkAdapterConfiguration Where Description = '" & $sNetAdapter & "'"
  131. $colNetAdapterConfig = $objWMIService.ExecQuery($sQueryNetAdapterConfig, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  132. If NOT IsObj($colNetAdapterConfig) Then Return 0
  133. For $objNetAdapter In $colNetAdapterConfig
  134. $iReturn = $objNetAdapter.EnableDHCP()
  135. If _EnableDHCP_DNS($sNetAdapter) Then
  136. If $iReturn == 0 Then return 1
  137. If $iReturn == 1 Then return 2
  138. EndIf
  139. Next
  140. If $iReturn == "" Then $iReturn = 65
  141. Return SetError($iReturn, "", 0)
  142. EndFunc ; ===> _EnableDHCP
  143. ; #FUNCTION# ====================================================================================================================
  144. ; Name...........: _EnableDHCP_DNS
  145. ; Description....: Enables the Dynamic Host Configuration Protocol (DHCP) for DNS configuration.
  146. ; Syntax.........: _EnableDHCP_DNS($sNetAdapter)
  147. ; Parameters.....: $sNetAdapter - Name of the network adapter.
  148. ; The Windows network connection name can be used instead of network adapter.
  149. ; Return values..: Success - 1
  150. ; Failure - 0
  151. ; ===============================================================================================================================
  152. Func _EnableDHCP_DNS($sNetAdapter)
  153. Local $sQueryNetAdapterConfig, $colNetAdapterConfig, $objNetAdapter
  154. Local $guid
  155. Local $adapterName
  156. $adapterName = _GetNetworkAdapterFromID($sNetAdapter)
  157. If $adapterName Then $sNetAdapter = $adapterName
  158. $guid = _GetNetworkGUI($sNetAdapter)
  159. If $guid == 0 Then Return 0
  160. $sQueryNetAdapterConfig = "select * from Win32_NetworkAdapterConfiguration Where Description = '" & $sNetAdapter & "'"
  161. $colNetAdapterConfig = $objWMIService.ExecQuery($sQueryNetAdapterConfig, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  162. If NOT IsObj($colNetAdapterConfig) Then Return 0
  163. For $objNetAdapter In $colNetAdapterConfig
  164. If $objNetAdapter.DHCPEnabled == False Then Return 0
  165. Next
  166. Return RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & $guid , "NameServer", "REG_SZ", "")
  167. EndFunc ; ===> _EnableDHCP_DNS
  168. ; #FUNCTION# ====================================================================================================================
  169. ; Name...........: _EnableNetAdapter
  170. ; Description....: Enables the specified network adapter.
  171. ; Syntax.........: _EnableNetAdapter($sNetAdapter)
  172. ; Parameters.....: $sNetAdapter - Name of the network adapter.
  173. ; The Windows network connection name can be used instead of network adapter.
  174. ; Return values..: Success - 1
  175. ; Failure - 0
  176. ; ===============================================================================================================================
  177. Func _EnableNetAdapter($sNetAdapter)
  178. Local $sQueryNetAdapterConfig, $colNetAdapterConfig, $objNetAdapter, $iReturn = 0
  179. Local $adapterName
  180. $adapterName = _GetNetworkAdapterFromID($sNetAdapter)
  181. If $adapterName Then $sNetAdapter = $adapterName
  182. $sQueryNetAdapterConfig = "select * from Win32_NetworkAdapter Where Name = '" & $sNetAdapter & "'"
  183. $colNetAdapterConfig = $objWMIService.ExecQuery($sQueryNetAdapterConfig, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  184. If NOT IsObj($colNetAdapterConfig) Then Return 0
  185. For $objNetAdapter In $colNetAdapterConfig
  186. $iReturn = $objNetAdapter.Enable()
  187. If $iReturn == 0 Then Return 1
  188. Next
  189. Return 0
  190. EndFunc ; ===> _EnableNetAdapter
  191. ; #FUNCTION# ====================================================================================================================
  192. ; Name...........: _EnableStatic
  193. ; Description....: Enables static TCP/IP addressing for the specified network adapter.
  194. ; As a result, DHCP for this network adapter is disabled.
  195. ; Syntax.........: _EnableStatic($sNetAdapter, $sIPAddress, $sSubnetMask)
  196. ; Parameters.....: $sNetAdapter - Name of the network adapter.
  197. ; The Windows network connection name can be used instead of network adapter.
  198. ; $IPAddress - IP addresse(s) the set to the specified network adapter. Example: 155.34.22.0.
  199. ; To specify only one IP address, $IPAddress can be a string
  200. ; To specify more than one IP address, $sIPAddress must be an array
  201. ; $sSubnetMask - Subnet masks that complement the values in the $IPAddress parameter. Example: 255.255.0.0.
  202. ; To specify more than one subnet mask, $sSubnetMask must be an array
  203. ; Return values..: Success - 1 or 2 (reboot required)
  204. ; Failure - 0 and sets @error (see remarks)
  205. ;
  206. ; Remarks........: When the function fails (returns 0) @error contains extended information (see global remarks).
  207. ; ===============================================================================================================================
  208. Func _EnableStatic($sNetAdapter, $sIPAddress, $sSubnetMask)
  209. Local $sQueryNetAdapterConfig, $colNetAdapterConfig, $objNetAdapterConfig, $iReturn = 0
  210. Local $aIPAddress[1] = [ $sIPAddress ]
  211. Local $aSubnetMask[1] = [ $sSubnetMask ]
  212. Local $adapterName
  213. $adapterName = _GetNetworkAdapterFromID($sNetAdapter)
  214. If $adapterName Then $sNetAdapter = $adapterName
  215. $sQueryNetAdapterConfig = "select * from Win32_NetworkAdapterConfiguration Where Description = '" & $sNetAdapter & "'"
  216. $colNetAdapterConfig = $objWMIService.ExecQuery($sQueryNetAdapterConfig, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  217. If NOT IsObj($colNetAdapterConfig) Then Return 0
  218. For $objNetAdapterConfig In $colNetAdapterConfig
  219. $iReturn = $objNetAdapterConfig.EnableStatic($aIPAddress, $aSubnetMask)
  220. If $iReturn == 0 Then Return 1
  221. If $iReturn == 1 Then return 2
  222. Next
  223. If $iReturn == "" Then $iReturn = 65
  224. Return SetError($iReturn, "", 0)
  225. EndFunc ; ===> _EnableStatic
  226. ; #FUNCTION# ====================================================================================================================
  227. ; Name...........: _FlushDNS
  228. ; Description....: Reset the client resolver cache.
  229. ; Syntax.........: _FlushDNS
  230. ; Return values..: Success - 1
  231. ; Failure - 0
  232. ; ===============================================================================================================================
  233. Func _FlushDNS()
  234. Local $aReturn
  235. $aReturn = DllCall("dnsapi.dll", "BOOL", "DnsFlushResolverCache")
  236. Return $aReturn[0]
  237. EndFunc
  238. ; #FUNCTION# ====================================================================================================================
  239. ; Name...........: _GetNetAdapterFromID
  240. ; Description....: Get the network card name from its Windows network connection name
  241. ; Syntax.........: _GetNetAdapterFromID($sNetworkID)
  242. ; Parameters.....: $sNetworkID - Name of the network connection (ex: Local Area Network).
  243. ; Return values..: Success - Returns the network adapter name
  244. ; Failure - 0
  245. ; ===============================================================================================================================
  246. Func _GetNetworkAdapterFromID($sNetworkID)
  247. Local $sQueryNetAdapter, $objNetAdapter, $colNetAdapter
  248. If $sNetworkID = "" Then Return 0
  249. $sQueryNetAdapter = "select * from Win32_NetworkAdapter Where NetConnectionID = '" & $sNetworkID & "'"
  250. $colNetAdapter = $objWMIService.ExecQuery($sQueryNetAdapter, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  251. If NOT IsObj($colNetAdapter) Then return 0
  252. For $objNetAdapter In $colNetAdapter
  253. Return $objNetAdapter.Name
  254. Next
  255. Return 0
  256. EndFunc ; ===> _GetNetConnectionID
  257. ; #FUNCTION# ====================================================================================================================
  258. ; Name...........: _GetNetworkAdapterInfos
  259. ; Description....: Retrieve informations for the specified network card.
  260. ; If no network adapter is specified (default), the function returns informations for all network adapters.
  261. ; Syntax.........: _GetNetworkAdapterInfos([$sNetAdapter])
  262. ; Parameters.....: $sNetAdapter - Name of the network adapter or network ID
  263. ; The Windows network connection name can be used instead of network adapter.
  264. ; Return values..: Success - Returns a 2 dimensional array containing informations about the adapter configuration :
  265. ; - element[n][0] = AdapterType - Network adapter type.
  266. ; "Ethernet 802.3"
  267. ; "Token Ring 802.5"
  268. ; "Fiber Distributed Data Interface (FDDI)"
  269. ; "Wide Area Network (WAN)"
  270. ; "LocalTalk"
  271. ; "Ethernet using DIX header format"
  272. ; "ARCNET"
  273. ; "ARCNET (878.2)"
  274. ; "ATM"
  275. ; "Wireless"
  276. ; "Infrared Wireless"
  277. ; "Bpc"
  278. ; "CoWan"
  279. ; "1394"
  280. ; - element[n][1] = DeviceID - Unique identifier of the network adapter.
  281. ; - element[n][2] = GUID - Globally unique identifier for the connection.
  282. ; - element[n][3] = Index - Index number of the network adapter, stored in the system registry.
  283. ; - element[n][4] = InterfaceIndex - Index value that uniquely identifies the local network interface.
  284. ; - element[n][5] = MACAddress - MAC address for this network adapter.
  285. ; - element[n][6] = Manufacturer - Name of the network adapter's manufacturer.
  286. ; - element[n][7] = Name - Label by which the object is known.
  287. ; - element[n][8] = NetConnectionID - Name of the network connection as it appears in the Network Connections Control Panel program.
  288. ; - element[n][9] = NetConnectionStatus - State of the network adapter connection to the network.
  289. ; 0 (0x0) Disconnected
  290. ; 1 (0x1) Connecting
  291. ; 2 (0x2) Connected
  292. ; 3 (0x3) Disconnecting
  293. ; 4 (0x4) Hardware not present
  294. ; 5 (0x5) Hardware disabled
  295. ; 6 (0x6) Hardware malfunction
  296. ; 7 (0x7) Media disconnected
  297. ; 8 (0x8) Authenticating
  298. ; 9 (0x9) Authentication succeeded
  299. ; 10 (0xA) Authentication failed
  300. ; 11 (0xB) Invalid address
  301. ; 12 (0xC) Credentials required
  302. ; - element[n][10] = NetEnabled - Indicates whether the adapter is enabled or not.
  303. ; - element[n][11] = PNPDeviceID - Windows Plug and Play device identifier of the logical device.
  304. ; - element[n][12] = ProductName - Product name of the network adapter.
  305. ; - element[n][13] = ServiceName - Service name of the network adapter.
  306. ; - element[n][14] = Speed - Estimate of the current bandwidth in bits per second.
  307. ; - element[n][15] = DatabasePath - Valid Windows file path to standard Internet database files
  308. ; - element[n][16] = DefaultIPGateway - List of IP addresses of default gateways that the computer system uses (comma-separated values).
  309. ; - element[n][17] = DHCPEnabled - If TRUE, the DHCP server automatically assigns an IP address to the computer system when establishing a network connection.
  310. ; - element[n][18] = DHCPLeaseExpires - Expiration date and time for a leased IP address that was assigned to the computer by the DHCP server (YYYY-MM-DD HH:MM:SS format).
  311. ; - element[n][19] = DHCPLeaseObtained - Date and time the lease was obtained for the IP address assigned to the computer by the DHCP server (YYYY-MM-DD HH:MM:SS format).
  312. ; - element[n][20] = DHCPServer - IP address of the DHCP server.
  313. ; - element[n][21] = DNSDomain - Organization name followed by a period and an extension that indicates the type of organization.
  314. ; - element[n][22] = DNSDomainSuffixSearch - Lt of DNS domain suffixes to be appended to the end of host names during name resolution (comma-separated values).
  315. ; - element[n][23] = DNSEnabledForWINSResolution - If TRUE, the DNS is enabled for name resolution over WINS resolution.
  316. ; - element[n][24] = DNSHostName - Host name used to identify the local computer for authentication by some utilities.
  317. ; - element[n][25] = DNSServerSearchOrder - List of server IP addresses to be used in querying for DNS servers (comma-separated values).
  318. ; - element[n][26] = DomainDNSRegistrationEnabled - If TRUE, the IP addresses for this connection are registered in DNS under the domain name of this connection in addition to being registered under the computer's full DNS name.
  319. ; - element[n][27] = FullDNSRegistrationEnabled - If TRUE, the IP addresses for this connection are registered in DNS under the computer's full DNS name.
  320. ; - element[n][28] = GatewayCostMetric - List of integer cost metric values (ranging from 1 to 9999) to be used in calculating the fastest, most reliable, or least resource-intensive routes (comma-separated values).
  321. ; - element[n][29] = IPAddress - List of all of the IP addresses associated with the specified network adapter (comma-separated values).
  322. ; - element[n][30] = IPSubnet - List of all of the subnet masks associated with the current network adapter.
  323. ; - element[n][31] = WINSEnableLMHostsLookup - If TRUE, local lookup files are used. Lookup files will contain a map of IP addresses to host names.
  324. ; - element[n][32] = WINSPrimaryServer - IP address for the primary WINS server.
  325. ; - element[n][33] = WINSSecondaryServer - IP address for the secondary WINS server.
  326. ; Failure - 0
  327. ; ===============================================================================================================================
  328. Func _GetNetworkAdapterInfos($sNetAdapter = "")
  329. Local $aInfos[1][1], $sQueryNetAdapter, $sQueryNetAdapterConfig, $colNetAdapter, $colNetAdapterConfig, $objNetAdapter, $objNetAdapterConfig
  330. Local $filter = "", $n = 0, $adapterIndex
  331. If $sNetAdapter <> "" Then $filter = " WHERE Name = '" & $sNetAdapter & "' OR NetConnectionID = '" & $sNetAdapter & "'"
  332. $sQueryNetAdapter = 'select * from Win32_NetworkAdapter' & $filter
  333. $colNetAdapter = $objWMIService.ExecQuery($sQueryNetAdapter, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  334. If NOT IsObj($colNetAdapter) Then Return 0
  335. For $objNetAdapter In $colNetAdapter
  336. $adapterIndex = $objNetAdapter.Index
  337. $sQueryNetAdapterConfig = 'select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True AND Index = ' & $adapterIndex
  338. $colNetAdapterConfig = $objWMIService.ExecQuery($sQueryNetAdapterConfig, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  339. If IsObj($colNetAdapterConfig) Then
  340. For $objNetAdapterConfig In $colNetAdapterConfig
  341. $n += 1
  342. Redim $aInfos[$n][34]
  343. $aInfos[$n - 1][0] = $objNetAdapter.AdapterType
  344. $aInfos[$n - 1][1] = $objNetAdapter.DeviceID
  345. $aInfos[$n - 1][2] = $objNetAdapter.GUID
  346. $aInfos[$n - 1][3] = $objNetAdapter.Index
  347. $aInfos[$n - 1][4] = $objNetAdapter.InterfaceIndex
  348. $aInfos[$n - 1][5] = $objNetAdapter.MACAddress
  349. $aInfos[$n - 1][6] = $objNetAdapter.Manufacturer
  350. $aInfos[$n - 1][7] = $objNetAdapter.Name
  351. $aInfos[$n - 1][8] = $objNetAdapter.NetConnectionID
  352. $aInfos[$n - 1][9] = $objNetAdapter.NetConnectionStatus
  353. $aInfos[$n - 1][10] = $objNetAdapter.NetEnabled
  354. $aInfos[$n - 1][11] = $objNetAdapter.PNPDeviceID
  355. $aInfos[$n - 1][12] = $objNetAdapter.ProductName
  356. $aInfos[$n - 1][13] = $objNetAdapter.ServiceName
  357. $aInfos[$n - 1][14] = $objNetAdapter.Speed
  358. $aInfos[$n - 1][15] = $objNetAdapterConfig.DatabasePath
  359. $aInfos[$n - 1][16] = _Array2String( ($objNetAdapterConfig.DefaultIPGateway) , ",")
  360. $aInfos[$n - 1][17] = $objNetAdapterConfig.DHCPEnabled
  361. $aInfos[$n - 1][18] = _WMIDate($objNetAdapterConfig.DHCPLeaseExpires)
  362. $aInfos[$n - 1][19] = _WMIDate($objNetAdapterConfig.DHCPLeaseObtained)
  363. $aInfos[$n - 1][20] = $objNetAdapterConfig.DHCPServer
  364. $aInfos[$n - 1][21] = $objNetAdapterConfig.DNSDomain
  365. $aInfos[$n - 1][22] = _Array2String( ($objNetAdapterConfig.DNSDomainSuffixSearch) , ",")
  366. $aInfos[$n - 1][23] = $objNetAdapterConfig.DNSEnabledForWINSResolution
  367. $aInfos[$n - 1][24] = $objNetAdapterConfig.DNSHostName
  368. $aInfos[$n - 1][25] = _Array2String( ($objNetAdapterConfig.DNSServerSearchOrder) , ",")
  369. $aInfos[$n - 1][26] = $objNetAdapterConfig.DomainDNSRegistrationEnabled
  370. $aInfos[$n - 1][27] = $objNetAdapterConfig.FullDNSRegistrationEnabled
  371. $aInfos[$n - 1][28] = _Array2String( ( $objNetAdapterConfig.GatewayCostMetric) , ",")
  372. $aInfos[$n - 1][29] = _Array2String( ( $objNetAdapterConfig.IPAddress) , ",")
  373. $aInfos[$n - 1][30] = _Array2String( ( $objNetAdapterConfig.IPSubnet) , ",")
  374. $aInfos[$n - 1][31] = $objNetAdapterConfig.WINSEnableLMHostsLookup
  375. $aInfos[$n - 1][32] = $objNetAdapterConfig.WINSPrimaryServer
  376. $aInfos[$n - 1][33] = $objNetAdapterConfig.WINSSecondaryServer
  377. Next
  378. EndIf
  379. Next
  380. If $n = 0 Then Return 0
  381. Return $aInfos
  382. EndFunc ; ===> _GetNetworkAdapterInfos
  383. ; #FUNCTION# ====================================================================================================================
  384. ; Name...........: _GetNetworkAdapterList
  385. ; Description....: Get a list of Ethernet network adapter installed on the system
  386. ; Syntax.........: _GetNetworkAdapterList()
  387. ; Return values..: Success - Returns a 2 dimensional array.
  388. ; element[n][0] - Name of the network adapter
  389. ; element[n][1] - Name of the network ID
  390. ; Failure - 0
  391. ; ===============================================================================================================================
  392. Func _GetNetworkAdapterList()
  393. Local $aInfos[1][1], $sQueryNetAdapter, $colNetAdapter, $objNetAdapter
  394. Local $n = 0
  395. $sQueryNetAdapter = "select * from Win32_NetworkAdapter Where AdapterType like 'Ethernet%'"
  396. $colNetAdapter = $objWMIService.ExecQuery($sQueryNetAdapter, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  397. If IsObj($colNetAdapter) Then
  398. For $objNetAdapter In $colNetAdapter
  399. $n += 1
  400. Redim $aInfos[$n][2]
  401. $aInfos[$n - 1][0] = $objNetAdapter.Name
  402. $aInfos[$n - 1][1] = $objNetAdapter.NetConnectionID
  403. Next
  404. EndIf
  405. If $n = 0 Then Return 0
  406. Return $aInfos
  407. EndFunc
  408. ; #FUNCTION# ====================================================================================================================
  409. ; Name...........: _GetNetworkGUI
  410. ; Description....: Get the network ID stored in the system registry for the specified network adapter (GUID)
  411. ; Syntax.........: _GetNetworkGUI($sNetAdapter)
  412. ; Parameters.....: $sNetAdapter - Name of the network adapter
  413. ; Return values..: Success - Returns the network GUID
  414. ; Failure - 0
  415. ; ===============================================================================================================================
  416. Func _GetNetworkGUI($sNetAdapter)
  417. Local $sQueryNetAdapterConfig, $colNetAdapterConfig, $objNetAdapter
  418. Local $adapterName
  419. $adapterName = _GetNetworkAdapterFromID($sNetAdapter)
  420. If $adapterName Then $sNetAdapter = $adapterName
  421. $sQueryNetAdapterConfig = "select * from Win32_NetworkAdapter Where Name = '" & $sNetAdapter & "'"
  422. $colNetAdapterConfig = $objWMIService.ExecQuery($sQueryNetAdapterConfig, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  423. If NOT IsObj($colNetAdapterConfig) Then Return 0
  424. For $objNetAdapter In $colNetAdapterConfig
  425. Return $objNetAdapter.GUID
  426. Next
  427. Return 0
  428. EndFunc ; ===> _GetNetworkGUI
  429. ; #FUNCTION# ====================================================================================================================
  430. ; Name...........: _GetNetworkIDFromAdapter
  431. ; Description....: Get the Windows network connection name ID from the network adapter
  432. ; Syntax.........: _GetNetAdapterFromID($sNetAdapter)
  433. ; Parameters.....: $sNetAdapter - Name of the network adapter
  434. ; Return values..: Success - Returns the network adapter name
  435. ; Failure - 0
  436. ; ===============================================================================================================================
  437. Func _GetNetworkIDFromAdapter($sNetAdapter)
  438. Local $sQueryNetAdapter, $objNetAdapter, $colNetAdapter
  439. If $sNetAdapter = "" Then Return 0
  440. $sQueryNetAdapter = "select * from Win32_NetworkAdapter Where Name = '" & $sNetAdapter & "'"
  441. $colNetAdapter = $objWMIService.ExecQuery($sQueryNetAdapter, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  442. If NOT IsObj($colNetAdapter) Then return 0
  443. For $objNetAdapter In $colNetAdapter
  444. Return $objNetAdapter.NetConnectionID
  445. Next
  446. Return 0
  447. EndFunc ; ===> _GetNetConnectionID
  448. ; #FUNCTION# ====================================================================================================================
  449. ; Name...........: _IsWirelessAdapter
  450. ; Description....: Checks if a network adapter is a wireless type
  451. ; Syntax.........: _IsWirelessAdapter($sAdapter)
  452. ; Parameters.....: $sNetAdapter - Name of the network adapter
  453. ; Return values..: Success - Returns 1
  454. ; Failure - 0
  455. ; ===============================================================================================================================
  456. Func _IsWirelessAdapter($sAdapter)
  457. Local $hDLL = DllOpen("wlanapi.dll"), $aResult, $hClientHandle, $pInterfaceList, _
  458. $tInterfaceList, $iInterfaceCount, $tInterface, $pInterface, $tGUID, $pGUID
  459. $aResult = DllCall($hDLL, "dword", "WlanOpenHandle", "dword", 2, "ptr", 0, "dword*", 0, "hwnd*", 0)
  460. If @error Or $aResult[0] Then Return 0
  461. $hClientHandle = $aResult[4]
  462. $aResult = DllCall($hDLL, "dword", "WlanEnumInterfaces", "hwnd", $hClientHandle, "ptr", 0, "ptr*", 0)
  463. If @error Or $aResult[0] Then Return 0
  464. $pInterfaceList = $aResult[3]
  465. $tInterfaceList = DllStructCreate("dword", $pInterfaceList)
  466. $iInterfaceCount = DllStructGetData($tInterfaceList, 1)
  467. If Not $iInterfaceCount Then Return 0
  468. Local $abGUIDs[$iInterfaceCount]
  469. For $i = 0 To $iInterfaceCount - 1
  470. $pInterface = Ptr(Number($pInterfaceList) + ($i * 532 + 8))
  471. $tInterface = DllStructCreate("byte GUID[16]; wchar descr[256]; int State", $pInterface)
  472. $abGUIDs[$i] = DllStructGetData($tInterface, "GUID")
  473. If DllStructGetData($tInterface, "descr") == $sAdapter Then Return 1
  474. Next
  475. DllCall($hDLL, "dword", "WlanFreeMemory", "ptr", $pInterfaceList)
  476. $tGUID = DllStructCreate("byte[16]")
  477. DllStructSetData($tGUID, 1, $abGUIDs[0])
  478. $pGUID = DllStructGetPtr($tGUID)
  479. DllCall($hDLL, "dword", "WlanCloseHandle", "ptr", $hClientHandle, "ptr", 0)
  480. DllClose($hDLL)
  481. Return 0
  482. EndFunc ; ===> _IsWirelessAdapter
  483. ; #FUNCTION# ====================================================================================================================
  484. ; Name...........: _ReleaseDHCPLease
  485. ; Description....: Releases the IP address bound to the specified (or all) DHCP-enabled network adapter.
  486. ; As a result, DHCP for this network adapter is disabled.
  487. ; Syntax.........: _ReleaseDHCPLease([$sNetAdapter])
  488. ; Parameters.....: $sNetAdapter - Name of the network adapter.
  489. ; If no network adapter is specified (default), the function applies to all network adapters.
  490. ; The Windows network connection name can be used instead of network adapter.
  491. ; Return values..: Success - 1 or 2 (reboot required)
  492. ; Failure - 0 and sets @error (see remarks)
  493. ;
  494. ; Remarks........: When the function fails (returns 0) @error contains extended information (see global remarks).
  495. ; ===============================================================================================================================
  496. Func _ReleaseDHCPLease($sNetAdapter = "")
  497. Local $sQueryNetAdapterConfig, $colNetAdapterConfig, $objInstance, $objNetAdapter, $iReturn = 0
  498. Local $adapterName
  499. $adapterName = _GetNetworkAdapterFromID($sNetAdapter)
  500. If $adapterName Then $sNetAdapter = $adapterName
  501. If $sNetAdapter = "" Then
  502. $objInstance = $objWMIService.Get("Win32_NetworkAdapterConfiguration")
  503. If NOT IsObj($objInstance) Then Return 0
  504. $iReturn = $objInstance.ReleaseDHCPLeaseAll()
  505. Else
  506. $sQueryNetAdapterConfig = "select * from Win32_NetworkAdapterConfiguration Where Description = '" & $sNetAdapter & "'"
  507. $colNetAdapterConfig = $objWMIService.ExecQuery($sQueryNetAdapterConfig, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  508. If NOT IsObj($colNetAdapterConfig) Then Return 0
  509. For $objNetAdapter In $colNetAdapterConfig
  510. $iReturn = $objNetAdapter.ReleaseDHCPLease()
  511. If $iReturn == 0 Then Return 1
  512. If $iReturn == 1 Then return 2
  513. Next
  514. EndIf
  515. If $iReturn == "" Then $iReturn = 65
  516. Return SetError($iReturn, "", 0)
  517. EndFunc ; ===> _ReleaseDHCPLease
  518. ; #FUNCTION# ====================================================================================================================
  519. ; Name...........: _RenewDHCPLease
  520. ; Description....: Renews the IP address on the specified DHCP-enabled network adapters
  521. ; Syntax.........: _RenewDHCPLease([$sNetAdapter])
  522. ; Parameters.....: $sNetAdapter - Name of the network adapter.
  523. ; If no network adapter is specified (default), the function applies to all network adapters.
  524. ; The Windows network connection name can be used instead of network adapter.
  525. ; Return values..: Success - 1 or 2 (reboot required)
  526. ; Failure - 0 and sets @error (see remarks)
  527. ;
  528. ; Remarks........: When the function fails (returns 0) @error contains extended information (see global remarks).
  529. ; ===============================================================================================================================
  530. Func _RenewDHCPLease($sNetAdapter = "")
  531. Local $sQueryNetAdapterConfig, $colNetAdapterConfig, $objInstance, $objNetAdapter, $iReturn = 0
  532. Local $adapterName
  533. $adapterName = _GetNetworkAdapterFromID($sNetAdapter)
  534. If $adapterName Then $sNetAdapter = $adapterName
  535. If $sNetAdapter = "" Then
  536. $objInstance = $objWMIService.Get("Win32_NetworkAdapterConfiguration")
  537. If NOT IsObj($objInstance) Then Return 0
  538. $iReturn = $objInstance.RenewDHCPLeaseAll()
  539. Else
  540. $sQueryNetAdapterConfig = "select * from Win32_NetworkAdapterConfiguration Where Description = '" & $sNetAdapter & "'"
  541. $colNetAdapterConfig = $objWMIService.ExecQuery($sQueryNetAdapterConfig, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  542. If NOT IsObj($colNetAdapterConfig) Then Return 0
  543. For $objNetAdapter In $colNetAdapterConfig
  544. $iReturn = $objNetAdapter.RenewDHCPLease()
  545. If $iReturn == 0 Then Return 1
  546. If $iReturn == 1 Then return 2
  547. Next
  548. EndIf
  549. If $iReturn == "" Then $iReturn = 65
  550. Return SetError($iReturn, "", 0)
  551. EndFunc ; ===> _RenewDHCPLease
  552. ; #FUNCTION# ====================================================================================================================
  553. ; Name...........: _SetDNSDomain
  554. ; Description....: Sets the DNS domain to the specified network connection/adapter
  555. ; Syntax.........: _SetDNSDomain($sNetAdapter, $sDNSDomain)
  556. ; Parameters.....: $sNetAdapter - Name of the network adapter.
  557. ; The Windows network connection name can be used instead of network adapter.
  558. ; $sDNSDomain - Domain name
  559. ; Return values..: Success - 1 or 2 (reboot required)
  560. ; Failure - 0 and sets @error (see remarks)
  561. ;
  562. ; Remarks........: When the function fails (returns 0) @error contains extended information (see global remarks).
  563. ; ===============================================================================================================================
  564. Func _SetDNSDomain($sNetAdapter, $sDNSDomain)
  565. Local $sQueryNetAdapterConfig, $colNetAdapterConfig, $objNetAdapter, $iReturn = 0
  566. Local $adapterName
  567. $adapterName = _GetNetworkAdapterFromID($sNetAdapter)
  568. If $adapterName Then $sNetAdapter = $adapterName
  569. $sQueryNetAdapterConfig = "select * from Win32_NetworkAdapterConfiguration Where Description = '" & $sNetAdapter & "'"
  570. $colNetAdapterConfig = $objWMIService.ExecQuery($sQueryNetAdapterConfig, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  571. If NOT IsObj($colNetAdapterConfig) Then Return 0
  572. For $objNetAdapter In $colNetAdapterConfig
  573. $iReturn = $objNetAdapter.SetDNSDomain($sDNSDomain)
  574. If $iReturn == 0 Then Return 1
  575. If $iReturn == 1 Then return 2
  576. Next
  577. If $iReturn == "" Then $iReturn = 65
  578. Return SetError($iReturn, "", 0)
  579. EndFunc ; ===> _SetDNSDomain
  580. ; #FUNCTION# ====================================================================================================================
  581. ; Name...........: _SetDNSServerSearchOrder
  582. ; Description....: Sets the DNS IP addresses search order.
  583. ; Syntax.........: _SetDNSServerSearchOrder ($sNetAdapter, $aDNSServerSearchOrder)
  584. ; Parameters.....: $sNetAdapter - Name of the network adapter.
  585. ; The Windows network connection name can be used instead of network adapter.
  586. ; $aDNSServerSearchOrder - (ARRAY) List of IP addresses to query for DNS servers.
  587. ; Return values..: Success - 1 or 2 (reboot required)
  588. ; Failure - 0 and sets @error (see remarks)
  589. ;
  590. ; Remarks........: When the function fails (returns 0) @error contains extended information (see global remarks).
  591. ; ===============================================================================================================================
  592. Func _SetDNSServerSearchOrder($sNetAdapter, $aDNSServerSearchOrder)
  593. Local $sQueryNetAdapterConfig, $colNetAdapterConfig, $objNetAdapter, $iReturn = 0
  594. Local $adapterName
  595. If NOT IsArray($aDNSServerSearchOrder) Then return 0
  596. $adapterName = _GetNetworkAdapterFromID($sNetAdapter)
  597. If $adapterName Then $sNetAdapter = $adapterName
  598. $sQueryNetAdapterConfig = "select * from Win32_NetworkAdapterConfiguration Where Description = '" & $sNetAdapter & "'"
  599. $colNetAdapterConfig = $objWMIService.ExecQuery($sQueryNetAdapterConfig, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  600. If NOT IsObj($colNetAdapterConfig) Then Return 0
  601. For $objNetAdapter In $colNetAdapterConfig
  602. $iReturn = $objNetAdapter.SetDNSServerSearchOrder($aDNSServerSearchOrder)
  603. If $iReturn == 0 Then Return 1
  604. If $iReturn == 1 Then return 2
  605. Next
  606. If $iReturn == "" Then $iReturn = 65
  607. Return SetError($iReturn, "", 0)
  608. EndFunc ; ===> _SetDNSSuffixSearchOrder
  609. ; #FUNCTION# ====================================================================================================================
  610. ; Name...........: _SetDNSSuffixSearchOrder
  611. ; Description....: Sets the suffix search order.
  612. ; Syntax.........: _SetDNSSuffixSearchOrder($sNetAdapter, $aDNSDomainSuffixSearchOrder)
  613. ; Parameters.....: $sNetAdapter - Name of the network adapter.
  614. ; The Windows network connection name can be used instead of network adapter.
  615. ; $aDNSDomainSuffixSearchOrder - (ARRAY) List of server suffixes to query for DNS servers.
  616. ; Return values..: Success - 1 or 2 (reboot required)
  617. ; Failure - 0 and sets @error (see remarks)
  618. ;
  619. ; Remarks........: When the function fails (returns 0) @error contains extended information (see global remarks).
  620. ; ===============================================================================================================================
  621. Func _SetDNSSuffixSearchOrder($sNetAdapter, $aDNSDomainSuffixSearchOrder)
  622. Local $sQueryNetAdapterConfig, $colNetAdapterConfig, $objNetAdapter, $iReturn = 0
  623. Local $adapterName
  624. If NOT IsArray($aDNSDomainSuffixSearchOrder) Then return 0
  625. $adapterName = _GetNetworkAdapterFromID($sNetAdapter)
  626. If $adapterName Then $sNetAdapter = $adapterName
  627. $sQueryNetAdapterConfig = "select * from Win32_NetworkAdapterConfiguration Where Description = '" & $sNetAdapter & "'"
  628. $colNetAdapterConfig = $objWMIService.ExecQuery($sQueryNetAdapterConfig, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  629. If NOT IsObj($colNetAdapterConfig) Then Return 0
  630. For $objNetAdapter In $colNetAdapterConfig
  631. $iReturn = $objNetAdapter.SetDNSSuffixSearchOrder($aDNSDomainSuffixSearchOrder)
  632. If $iReturn == 0 Then Return 1
  633. If $iReturn == 1 Then return 2
  634. Next
  635. If $iReturn == "" Then $iReturn = 65
  636. Return SetError($iReturn, "", 0)
  637. EndFunc ; ===> _SetDNSSuffixSearchOrder
  638. ; #FUNCTION# ====================================================================================================================
  639. ; Name...........: _SetDynamicDNSRegistration
  640. ; Description....: Indicates the dynamic DNS registration of IP addresses for the specified IP-bound adapter..
  641. ; Syntax.........: _SetDynamicDNSRegistration($sNetAdapter, $FullDNSRegistrationEnabled, $DomainDNSRegistrationEnabled)
  642. ; Parameters.....: $sNetAdapter - Name of the network adapter.
  643. ; The Windows network connection name can be used instead of network adapter.
  644. ; $FullDNSRegistrationEnabled - If true, the IP addresses for this connection is registered in DNS
  645. ; under the computer's full DNS name.
  646. ; $DomainDNSRegistrationEnabled - If true, the IP addresses for this connection are registered under the
  647. ; domain name of this connection, in addition to being registered under
  648. ; the computer's full DNS name.
  649. ; Return values..: Success - 1 or 2 (reboot required)
  650. ;
  651. ; Failure - 0 and sets @error (see remarks)
  652. ;
  653. ; Remarks........: When the function fails (returns 0) @error contains extended information (see global remarks).
  654. ; ===============================================================================================================================
  655. Func _SetDynamicDNSRegistration($sNetAdapter, $FullDNSRegistrationEnabled, $DomainDNSRegistrationEnabled)
  656. Local $sQueryNetAdapterConfig, $colNetAdapterConfig, $objNetAdapter, $iReturn = 0
  657. Local $adapterName
  658. $adapterName = _GetNetworkAdapterFromID($sNetAdapter)
  659. If $adapterName Then $sNetAdapter = $adapterName
  660. $sQueryNetAdapterConfig = "select * from Win32_NetworkAdapterConfiguration Where Description = '" & $sNetAdapter & "'"
  661. $colNetAdapterConfig = $objWMIService.ExecQuery($sQueryNetAdapterConfig, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  662. If NOT IsObj($colNetAdapterConfig) Then Return 0
  663. For $objNetAdapter In $colNetAdapterConfig
  664. $iReturn = $objNetAdapter.SetDynamicDNSRegistration($FullDNSRegistrationEnabled, $DomainDNSRegistrationEnabled)
  665. If $iReturn == 0 Then Return 1
  666. If $iReturn == 1 Then return 2
  667. Next
  668. If $iReturn == "" Then $iReturn = 65
  669. Return SetError($iReturn, "", 0)
  670. EndFunc ; ===> _SetDynamicDNSRegistration
  671. ; #FUNCTION# ====================================================================================================================
  672. ; Name...........: _SetGateways
  673. ; Description....: Set one or more IP gateway adresses to use for the specified network adapter
  674. ; Syntax.........: _SetGateways($sNetAdapter, $DefaultIPGateway [, $GatewayCostMetric])
  675. ; Parameters.....: $sNetAdapter - Name of the network adapter.
  676. ; The Windows network connection name can be used instead of network adapter.
  677. ; $DefaultIPGateway - IP address of one or more gateways.
  678. ; To specify only one gateway, $DefaultIPGateway can be a string.
  679. ; To specify more than one gateway, $DefaultIPGateway must be an array.
  680. ; $GatewayCostMetric - Assigns a value that ranges from 1 to 9999, which is used to calculate the fastest and
  681. ; most reliable routes. Default is 1.
  682. ; If multiple gateways are defined, metrics must be defined for each one in an array.
  683. ; Return values..: Success - 1 or 2 (reboot required)
  684. ; Failure - 0 and sets @error (see remarks)
  685. ;
  686. ; Remarks........: When the function fails (returns 0) @error contains extended information (see global remarks).
  687. ; ===============================================================================================================================
  688. Func _SetGateways($sNetAdapter, $DefaultIPGateway, $GatewayCostMetric = 1)
  689. Local $sQueryNetAdapterConfig, $colNetAdapterConfig, $objNetAdapterConfig, $iReturn = 0
  690. Local $aGWAddress[1]
  691. Local $aGWMetric[1]
  692. Local $adapterName
  693. $adapterName = _GetNetworkAdapterFromID($sNetAdapter)
  694. If $adapterName Then $sNetAdapter = $adapterName
  695. If IsArray($DefaultIPGateway) AND IsArray($GatewayCostMetric) Then
  696. $aGWAddress = $DefaultIPGateway
  697. $aGWMetric = $GatewayCostMetric
  698. Else
  699. If NOT IsArray($DefaultIPGateway) Then $aGWAddress[0] = $DefaultIPGateway
  700. If NOT IsArray($GatewayCostMetric) Then $aGWMetric[0] = $GatewayCostMetric
  701. EndIf
  702. $sQueryNetAdapterConfig = "select * from Win32_NetworkAdapterConfiguration Where Description = '" & $sNetAdapter & "'"
  703. $colNetAdapterConfig = $objWMIService.ExecQuery($sQueryNetAdapterConfig, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  704. If NOT IsObj($colNetAdapterConfig) Then return 0
  705. For $objNetAdapterConfig In $colNetAdapterConfig
  706. $iReturn = $objNetAdapterConfig.SetGateways($aGWAddress, $aGWMetric)
  707. If $iReturn == 0 Then Return 1
  708. If $iReturn == 1 Then return 2
  709. Next
  710. If $iReturn == "" Then $iReturn = 65
  711. Return SetError($iReturn, "", 0)
  712. EndFunc ; ===> _SetIPAddress
  713. ; #FUNCTION# ====================================================================================================================
  714. ; Name...........: _SetWINSServer
  715. ; Description....: Sets the primary and secondary WINS servers on the specified TCP/IP-bound network adapter
  716. ; Syntax.........: _SetWINSServer($sNetAdapter, $sWinsAddr1, $sWinsAddr2 = "")
  717. ; Parameters.....: $sNetAdapter - Name of the network adapter.
  718. ; The Windows network connection name can be used instead of network adapter.
  719. ; $sWinsAddr1 - IP address of the primary WINS server..
  720. ; $sWinsAddr2 - IP address of the secondary WINS server.
  721. ; Return values..: Success - 1 or 2 (reboot required)
  722. ; Failure - 0 and sets @error (see remarks)
  723. ;
  724. ; Remarks........: When the function fails (returns 0) @error contains extended information (see global remarks).
  725. ; ===============================================================================================================================
  726. Func _SetWINSServer($sNetAdapter, $sWinsAddr1, $sWinsAddr2 = "")
  727. Local $sQueryNetAdapterConfig, $colNetAdapterConfig, $objNetAdapter, $iReturn = 0
  728. Local $adapterName
  729. $adapterName = _GetNetworkAdapterFromID($sNetAdapter)
  730. If $adapterName Then $sNetAdapter = $adapterName
  731. $sQueryNetAdapterConfig = "select * from Win32_NetworkAdapterConfiguration Where Description = '" & $sNetAdapter & "'"
  732. $colNetAdapterConfig = $objWMIService.ExecQuery($sQueryNetAdapterConfig, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  733. If NOT IsObj($colNetAdapterConfig) Then return 0
  734. For $objNetAdapter In $colNetAdapterConfig
  735. $iReturn = $objNetAdapter.SetWINSServer($sWinsAddr1, $sWinsAddr2)
  736. If $iReturn == 0 Then Return 1
  737. If $iReturn == 1 Then return 2
  738. Next
  739. If $iReturn == "" Then $iReturn = 65
  740. Return SetError($iReturn, "", 0)
  741. EndFunc ; ===> _SetWINSServer
  742. ; #FUNCTION# ====================================================================================================================
  743. ; Name...........: _ErrFunc
  744. ; Description....: Empty function witch intercepts AutoIt errors
  745. ; ===============================================================================================================================
  746. Func _ErrFunc($oError)
  747. EndFunc ;==>_ErrFunc
  748. ; #FUNCTION# ====================================================================================================================
  749. ; Name...........: _WMIDate
  750. ; Description....: Converts a WMI date to a standard date-time format.
  751. ; Syntax.........: _WMIDate($sDate, [$iFormat])
  752. ; Parameters.....: $sDate - WMI date (obtnained from a WMI object)
  753. ; $iFormat - Format of date that the user want to get.
  754. ; 0 = YYYY-MM-DD HH:MM:SS ( default)
  755. ; 1 = DD/MM/YYYY HH:MM:SS
  756. ; 2 = YYYYMMDDHHMMSS
  757. ; Return values..: Success - Converted date
  758. ; Failure - ""
  759. ; ===============================================================================================================================
  760. Func _WMIDate($sDate, $iFormat = 0)
  761. Local $dateFormat, $newdate = ""
  762. If $iFormat = 0 Then $dateFormat = "$1-$2-$3 $4:$5:$6"
  763. If $iFormat = 1 Then $dateFormat = "$3/$2/$1 $4:$5:$6"
  764. If $iFormat = 2 Then $dateFormat = "$1$2$3$4$5$6"
  765. If NOT IsString($sDate) Then Return ""
  766. $newDate = StringRegExpReplace($sDate, "\A(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2}).*", $dateFormat)
  767. Return $newDate
  768. EndFunc ; ===> _WMIDate
  769. ; #FUNCTION# ====================================================================================================================
  770. ; Name...........: _Array2String
  771. ; Description ...: Places the elements of an array into a single string, separated by the specified delimiter.
  772. ; Syntax.........: _Array2String(Const ByRef $avArray[, $sDelim = "|"[, $iStart = 0[, $iEnd = 0]]])
  773. ; Parameters ....: $avArray - Array to combine
  774. ; $sDelim - [optional] Delimiter for combined string
  775. ; $iStart - [optional] Index of array to start combining at
  776. ; $iEnd - [optional] Index of array to stop combining at
  777. ; Return values .: Success - string which combined selected elements separated by the delimiter string.
  778. ; Failure - "", sets @error:
  779. ; |1 - $avArray is not an array
  780. ; |2 - $iStart is greater than $iEnd
  781. ; |3 - $avArray is not an 1 dimensional array
  782. ; Author ........: Brian Keene <brian_keene at yahoo dot com>, Valik - rewritten
  783. ; Modified.......: Ultima - code cleanup
  784. ; ===============================================================================================================================
  785. Func _Array2String(Const ByRef $avArray, $sDelim = "|", $iStart = 0, $iEnd = 0)
  786. If Not IsArray($avArray) Then Return SetError(1, 0, "")
  787. If UBound($avArray, 0) <> 1 Then Return SetError(3, 0, "")
  788. Local $sResult, $iUBound = UBound($avArray) - 1
  789. ; Bounds checking
  790. If $iEnd < 1 Or $iEnd > $iUBound Then $iEnd = $iUBound
  791. If $iStart < 0 Then $iStart = 0
  792. If $iStart > $iEnd Then Return SetError(2, 0, "")
  793. ; Combine
  794. For $i = $iStart To $iEnd
  795. $sResult &= $avArray[$i] & $sDelim
  796. Next
  797. Return StringTrimRight($sResult, StringLen($sDelim))
  798. EndFunc ;==>_Array2String

comments powered by Disqus