;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       SetDnsSRV() 
;; 
;;ACTION         Creates a DNS SRV record (with defaults for SWDIST) 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.0  - 2009/10/19 
;; 
;;HISTORY        1.0  - 2009/10/19 - Initial Release 
;; 
;;SYNTAX         SetDnsSRV(Priority, Weight, DnsIp [, DnsDomain] [, RecordType] [, Port] [, Hostname]) 
;; 
;;PARAMETERS     Priority - REQUIRED - String 
;;               - The desired SRV record priority (SWDIST server class) 
;; 
;;               Weight - REQUIRED - String 
;;               - The desired SRV record weight (SWDIST netmask) 
;; 
;;               DnsIP - REQUIRED - String 
;;               - IP string of the DNS server where the update should be made 
;; 
;;               DnsDomain - OPTIONAL - String 
;;               - The DNS domain to be updated, defaults to %USERDNSDOMAIN% 
;; 
;;               RecordType - OPTIONAL - String 
;;               - specifies the type of SRV record to return. The default  
;;		 type is the custom record "_swdist._tcp" (easily changed) 
;; 
;;               Port - Optional - String 
;;               - The desired SRV record service port (SWDIST Default is 1758) 
;; 
;;               Hostname - Optional - String 
;;               - The hostname that this record will represent. Default is  
;;		 the local host's name. 
;; 
;;RETURNS        1 if successful, 0 otherwise 
;; 
;;REMARKS        Used to create a SRV recod in DNS. SRV records are usd to identify 
;;		 the name & address of hosts that provide specific services.  
;;		  
;;		 When used in the SWDIST environment, SetDnsSRV is used to define a 
;;		 new SWDIST server, including the type (PRIORITY: 0=primary, 1=secondary, 
;;		 2=Slave) and subnet size served. 
;;               (WEIGHT: 0-31 indicating the number of subnet bits) 
;; 
;;DEPENDENCIES   WScript 
;; 
;;TESTED WITH    W2K, WXP, W2K3, W2K8, Vista 
;; 
;;EXAMPLES       ; Define a SRV record if it doesn't exist 
;;		 $MyRecord = 0 ; clear flag 
;;		 ; get my IP address 
;;		 $IpAdd = Join(Split(@IPADDRESS0, ' '), '') 
;;		 ; get list of SRV data 
;;		 $aRecords = GetResourceBySrv($IpAdd, 1) 
;;		 ; enumerate the records 
;;		 For Each $Rec in $aRecords 
;;		   If InStr($Rec[0], @WKSTA) = 1 $MyRecord = 1 EndIf 
;;		 Next 
;;		 If Not $MyRecord 
;;		   SetDnsSRV(2, 24, '10.32.70.52')	; add my SRV data to DNS 
;;		 EndIf 
;;		  
;;		  
; 
Function SetDnsSRV($_Priority, $_Weight, $_DnsIp, OPTIONAL $_DnsDomain, OPTIONAL $_RecordType, OPTIONAL $_Port, OPTIONAL $_Hostname)
 
  Dim $_oExec			; WScript object 
  Dim $_Cmd			; command to execute 
 
  $SetDnsSRV = 0
 
  ; Set default values for optional parameters 
  $_DnsDomain  = IIf($_DnsDomain, $_DnsDomain, '%USERDNSDOMAIN%')
  $_RecordType = IIf($_RecordType, $_RecordType, '_swdist._tcp')
  $_Port       = IIf($_Port, $_Port, '1758')
  $_Hostname   = IIf($_Hostname, $_Hostname, @WKSTA + '.' + '%USERDNSDOMAIN%')
 
 
  ; format of command to execute: 
  ; dnscmd.exe <DNS_IP> /RecordAdd <DNS_DOMAIN> <RECORD_TYPE> SRV <PRI> <WEIGHT> <PORT> <HOSTNAME.FQDN> 
 
  $_Cmd = '%COMSPEC% /c dnscmd.exe ' + $_DnsIp + ' /RecordAdd '
  $_Cmd = $_Cmd + $_DnsDomain + ' '
  $_Cmd = $_Cmd + $_RecordType + ' SRV '
  $_Cmd = $_Cmd + $_Priority + ' '
  $_Cmd = $_Cmd + $_Weight + ' '
  $_Cmd = $_Cmd + $_Port + ' '
  $_Cmd = $_Cmd + $_Hostname
 
  ; Use WScript to execute the command and check the result 
  $_oExec = CreateObject("WScript.Shell").Exec($_Cmd)
  If Not VarType($_oExec) = 9
    Exit 10
  EndIf
 
  $SetDnsSRV = Not @ERROR
  Exit @ERROR
 
EndFunction