<% @Language=VbScript%> <% Option Explicit%> <% '--------------------------------------------------------------------- ' nicdns_prop.asp: display and update the DNS properties of NIC. ' ' Copyright (c) Microsoft Corporation. All rights reserved. ' ' Date Description ' 15-Jan-01 Creation Date. ' 06-Mar-01 Modified Date '--------------------------------------------------------------------- %> <% '--------------------------------------------------------------------- 'Global Variables '--------------------------------------------------------------------- Dim G_objService 'Instance of the WMI Connection Dim page 'Variable that receives the output page object when 'creating a page Dim rc 'Return value for CreatePage Dim SOURCE_FILE 'To get file name SOURCE_FILE = SA_GetScriptFileName() '--------------------------------------------------------------------- 'Form Variables '--------------------------------------------------------------------- Dim F_ID 'ID of the Network Adapter Dim F_radSelected 'Which option is selected ' "1" means DHCP enabled ' "2" means Manual Settings Dim F_DNSserverList '"," seperated DNS Server list Dim F_strFlag 'To hold the Flag Value 'to hold the registry path Const G_CONST_REGISTRY_PATH ="SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces" 'Create property page rc=SA_CreatePage(L_DNSTASKTITLE_TEXT,"",PT_PROPERTY,page) 'Serve the page If(rc=0) then SA_ShowPage(Page) End if '------------------------------------------------------------------------- 'Function: OnInitPage() 'Description: Called to signal first time processing for this page. ' Use this method to do first time initialization tasks 'Input Variables: PageIn,EventArg 'Output Variables: PageIn,EventArg 'Returns: True/False 'Global Variables: None '------------------------------------------------------------------------- Public Function OnInitPage(ByRef PageIn,ByRef EventArg) Call SA_TraceOut( SOURCE_FILE, "OnInitPage") 'getting default values of dns server settings OnInitPage = SetDnsDefaultValues() End Function '------------------------------------------------------------------------- 'Function: OnServePropertyPage() 'Description: Called when the page needs to be served.Use this ' method to serve content 'Input Variables: PageIn,EventArg 'Output Variables: PageIn,EventArg 'Returns: True/False 'Global Variables: In:G_objService-Getting WMI connection Object ' In:F_iD-Getting NIC adapter Index ' In:F_radSelected-Getting radio button selection ' In:F_DNSserverList-Getting new list dns servers ' In:L_(*)-Localization content '------------------------------------------------------------------------- Public Function OnServePropertyPage(ByRef PageIn,Byref EventArg) Dim objNetAdapter Dim strDHCPEnabled Call SA_TraceOut( SOURCE_FILE, "OnServerPropertyPage") ' To get the Network Adapter object set objNetAdapter = getNetworkAdapterObject(G_objService,F_iD) 'Get Whether the DHCP is enabled on the NIC. strDHCPEnabled = isDHCPenabled(objNetAdapter) Call ServeCommonJavaScript() %>
<%=GetNicName(F_ID)%>
 
<%=L_CONFIGURATION_TEXT%> onClick="EnableOK();disableDNSControls(true);" > <%= L_OBTAINIPFROMDHCP_TEXT%>
  onClick="EnableOK(); enableDNSControls();" > <%=L_DNSCONFIGUREMANUALLY_TEXT%>
<%=L_DNS_SERVER_ADDRESSES_TEXT%>
<%=L_LIST_DNSSERVERS_TEXT%> <% Call SA_ServeOnClickButtonEx(L_BUTTON_ADD_TEXT, "", "addDNSServerToListBox()", 60, 0, "DISABLED", "btnAddDNS") %>




<% Call SA_ServeOnClickButtonEx(L_BUTTON_REMOVE_TEXT, "", "EnableOK();removeListBoxItems(document.frmTask.cboDNSServers,document.frmTask.btnRemoveDNS);EnableAddText()", 60, 0, "DISABLED", "btnRemoveDNS") %>
<% 'destroying dynamically created objects Set objNetAdapter=Nothing OnServePropertyPage = True End Function '------------------------------------------------------------------------- 'Function: OnPostBackPage() 'Description: Called to signal that the page has been posted-back. 'Input Variables: PageIn,EventArg 'Output Variables: PageIn,EventArg 'Returns: True/False 'Global Variables: None '------------------------------------------------------------------------- Public Function OnPostBackPage(ByRef PageIn ,ByRef EventArg) Call SA_TraceOut( SOURCE_FILE, "OnPostBackPage") OnPostBackPage = True End Function '------------------------------------------------------------------------- 'Function: OnSubmitPage() 'Description: Called when the page has been submitted for processing. ' Use this method to process the submit request. 'Input Variables: PageIn,EventArg 'Output Variables: PageIn,EventArg 'Returns: True/False 'Global Variables: In: G_objService-Getting WMI connection Object ' Out:F_iD-Getting NIC adapter Index ' Out:F_radSelected-Getting radio button selection ' Out:F_DNSserverList-Getting new list dns servers ' In: L_(*)-Localization content '------------------------------------------------------------------------- Public Function OnSubmitPage(ByRef PageIn ,ByRef EventArg) Call SA_TraceOut( SOURCE_FILE, "OnSubmitPage") 'Nic adapter index no F_ID = Request.Form("hdnNicID") 'Dns servers list after form has been submiited F_DNSserverList = Request.Form("hdnDNSserverList") ' The radio button to be selected - contains 1 or 2 only F_radSelected = Request.Form("hdnRadioSelected") 'Getting WMI connection Object on error displays failure page Set G_objService=GetWMIConnection(CONST_WMI_WIN32_NAMESPACE) 'Updating the dsn server settings If UpdateDNSSettingsForNIC() Then OnSubmitPage = true Else OnSubmitPage = false End If End Function '------------------------------------------------------------------------- 'Function: OnClosePage() 'Description: Called when the page is about closed.Use this method ' to perform clean-up processing 'Input Variables: PageIn,EventArg 'Output Variables: PageIn,EventArg 'Returns: True/False 'Global Variables: None '------------------------------------------------------------------------- Public Function OnClosePage(ByRef PageIn ,ByRef EventArg) Call SA_TraceOut( SOURCE_FILE, "OnClosePage") Set G_objService = nothing OnClosePage = TRUE End Function '------------------------------------------------------------------------- 'Function: ServeCommonJavaScript 'Description: Serves in initializing the values,setting the form ' data and validating the form values 'Input Variables: None 'Output Variables: None 'Returns: True/False 'Global Variables: None '------------------------------------------------------------------------- Function ServeCommonJavaScript() Err.Clear On Error Resume Next Call SA_TraceOut( SOURCE_FILE, "ServeCommonJavaScript") %> <% End Function '--------------------------------------------------------------------- ' Function name: UpdateDNSSettingsForNIC ' Description: To update the DNS Settings for the Network Card. ' Input Variables: None ' Output Variables: None ' Returns: true on success; otherwise false 'Global Variables: In:G_objService-Getting WMI connection Object ' In:F_ID-Getting NIC adapter Index ' In:F_radSelected-Getting radio button selection ' In:L_(*)-Localization content '--------------------------------------------------------------------- Function UpdateDNSSettingsForNIC() Err.Clear On Error Resume Next Dim objNetAdapter 'To hold Network adapter object Dim intReturnValue 'To hold the return value Dim strSettingId 'To hold the registry setting value Dim objRegistry 'To hold the registry object Call SA_TraceOut( SOURCE_FILE, "UpdateDNSSettingsForNIC") UpdateDNSSettingsForNIC = false ' Getting the Network adapter objects & DNS servers list set objNetAdapter = getNetworkAdapterObject(G_objService,F_ID) strSettingId=objNetAdapter.SettingID 'Connecting to default namespace to carry registry operations Set objRegistry=regConnection() If (objRegistry is Nothing) Then Call SA_TraceOut( SOURCE_FILE, "Error in getting registry object-UpdateDNSSettingsForNIC()") SA_ServeFailurePage(L_SERVERCONNECTIONFAIL_ERRORMESSAGE) UpdateDNSSettingsForNIC = False Exit Function End If 'If the DNS server is to be obtained dynamically If F_radSelected = "1" Then 'Check whether DHCP is enabled If isDHCPEnabled(objNetAdapter) Then intReturnValue=updateRegkeyvalue(objRegistry,G_CONST_REGISTRY_PATH & "\" & strSettingID,"NameServer","",CONST_STRING) Else SA_SetErrMsg L_DHCPDISABLED_ERRORMESSAGE & "(" & Hex(Err.number) & ")" Exit Function End If Else 'removing the last comma from dns server list F_DNSserverList=Mid(F_DNSserverList,1, len(F_DNSserverList)-1) 'Set the DNS server list in the WMI intReturnValue=updateRegkeyvalue(objRegistry,G_CONST_REGISTRY_PATH & "\" & strSettingID,"NameServer",F_DNSserverList,CONST_STRING) End If If Err.number <> 0 Then Call SA_TraceOut( SOURCE_FILE, "DNS settings Not set-UpdateDNSSettingsForNIC()") Call SA_ServeFailurePage( L_DNSSETTINGSNOTSET_ERRORMESSAGE) UpdateDNSSettingsForNIC=False Exit Function End If set objNetAdapter = Nothing UpdateDNSSettingsForNIC = intReturnValue End Function '--------------------------------------------------------------------- ' Function name: SetDnsDefaultValues() ' Description: Setting the dns server default values ' Input Variables: None ' Output Variables: None ' Returns: True if its a success; False otherwise 'Global Variables: In:G_objService-Getting WMI connection Object ' Out:F_ID-Getting NIC adapter Index ' Out:F_radSelected-Getting radio button selection ' In:L_(*)-Localization content '--------------------------------------------------------------------- Function SetDnsDefaultValues() Err.Clear On Error Resume Next Dim objNetAdapter 'To hold nic adapter object Dim objRegistry 'To hold registry object Dim strNameServer 'To hold the dns servers list Dim strSettingId 'To hold registry setting id Const DHCPON="ON" 'Constant for DHCP On COnst DHCPOFF="OFF" 'Constant for DHCP Off Const CONSTFLAGNO="No" 'Constant for for flag value Call SA_TraceOut( SOURCE_FILE, "SetDnsDefaultValues()") 'Connecting to default namespace to carry registry operations Set objRegistry=regConnection() If (objRegistry is Nothing) Then Call SA_TraceOut( SOURCE_FILE, "Error in getting registry object-SetDnsDefaultValues()") SA_ServeFailurePage(L_SERVERCONNECTIONFAIL_ERRORMESSAGE) UpdateDNSSettingsForNIC = False Exit Function End If 'getting dns setting from area page F_ID = Request.QueryString("PKey") If F_ID = "" Then Call SA_TraceOut( SOURCE_FILE, "Dns settings not retrieved-SetDnsDefaultValues()") Call SA_ServeFailurePage(L_DNSSETTINGSNOTRETRIEVED_ERRORMESSAGE) SetDnsDefaultValues=False Exit Function End If 'Getting WMI connection Object on error displays failure page Set G_objService=GetWMIConnection(CONST_WMI_WIN32_NAMESPACE) 'To get the Network Adapter object set objNetAdapter = getNetworkAdapterObject(G_objService,F_ID) strSettingId=objNetAdapter.SettingID strNameServer=getRegkeyvalue(objRegistry,G_CONST_REGISTRY_PATH & "\" _ & strSettingId,"NameServer",CONST_STRING) If strNameServer="" and isDHCPenabled(objNetAdapter) then F_strFlag=CONSTFLAGNO Else ''getting the dns server list F_DNSserverList=strNameServer End If 'checking for the DHCP is enabled or not If isDHCPenabled(objNetAdapter) Then F_radSelected = DHCPON Else F_radSelected = DHCPOFF End If SetDnsDefaultValues=True End Function '------------------------------------------------------------------------- ' Function Name: OutputDNSServersToListbox ' Description: To display the DNS Servers in the LISTBOX. ' Input Variables: None. ' Output Variables: None. ' Returns: None. ' Global Variables: In: F_DNSserverList - *-separated list of DNS servers IPs ' This function Outputs DNS servers to the listbox control in the Form. '------------------------------------------------------------------------- Function OutputDNServersToListbox() Err.Clear On Error Resume Next Dim arrDnsSrv 'To hold the dns servers list Dim nIndex 'To hold the array index arrDnsSrv = split(F_DNSserverList,",") nIndex = 0 If (NOT IsNull(arrDnsSrv)) Then If IsArray(arrDnsSrv) Then For nIndex = LBound(arrDnsSrv) to UBound(arrDnsSrv) If arrDnsSrv(nIndex) <> "" Then Response.Write "" End If Next End If End If End Function %>