<% @Language=VbScript%> <% Option Explicit %> <% '---------------------------------------------------------------------------- ' nicwins_prop.asp: display and update the WINS properties of NIC. ' Description: this page displays the wins server properties of NIC and ' allows to change the properties ' Copyright (c) Microsoft Corporation. All rights reserved. ' ' Date Description ' 16-Jan-01 Creation date ' 09-Mar-01 Modified date '----------------------------------------------------------------------------- %> <% '------------------------------------------------------------------------- ' Global Variables '------------------------------------------------------------------------- Dim G_objService 'Object to SWBEM service Dim page 'Variable that receives the output page object when 'creating a page Dim rc 'Return value for CreatePage Dim SOURCE_FILE 'To hold source file name SOURCE_FILE = SA_GetScriptFileName() '------------------------------------------------------------------------- ' Global Form Variables '------------------------------------------------------------------------- Dim F_strNWadapter 'NIC adapter description Dim F_nNWadapterindex 'NIC adapter index Dim F_strWinservers 'Contains #-seperated list of WINS servers Dim F_radSelected 'Which option is selected ' "1" means DHCP enabled ' "2" means Manual Settings 'Create property page rc=SA_CreatePage(L_WINSTASKTITLE_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") 'gets the default values of the wins server OnInitPage = GetDefaultValues() 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: None '------------------------------------------------------------------------- Public Function OnServePropertyPage(ByRef PageIn,Byref EventArg) Call SA_TraceOut( SOURCE_FILE, "OnServePropertyPage") Call ServeCommonJavaScript() 'serves the html content Call ServePage() 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") 'To get the value of NIC adapter index value after form is submitted F_nNWadapterindex = Request.Form("hdnNWAdapterID") 'List of winsservers after form has been submitted F_strWinservers =Request.Form("hdnServerslist") ' The radio button to be selected - contains 1 or 2 only F_radSelected = Request.Form("hdnRadioSelected") 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_nNWadapterindex-Getting NIC adapter Index ' Out:F_radSelected-Getting radio button selection ' Out:F_strWinservers-Getting new list wins servers ' L_(*)-Localization content '------------------------------------------------------------------------- Public Function OnSubmitPage(ByRef PageIn ,ByRef EventArg) Call SA_TraceOut( SOURCE_FILE, "OnSubmitPage") 'Getting WMI connection Object on error displays failure page Set G_objService=GetWMIConnection(CONST_WMI_WIN32_NAMESPACE) call GetWINSConfiguration(1) 'Updating the wins server settings If SetWINSserverConfiguration() Then OnSubmitPage = True Else OnSubmitPage = False End if 'Release the object set G_objService = nothing 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") 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: None 'Global Variables: None '------------------------------------------------------------------------- Function ServeCommonJavaScript() %> <% End Function '------------------------------------------------------------------------- ' Subroutine name: ServePage ' Description: Serves few Javascript functions and helps in ' displaying HTML of the page ' Input Variables: None. ' Output Variables: None ' Return Values: None. ' Global Variables: In:G_objService-Getting WMI connection Object ' Out:F_nNWadapterindex-Getting NIC adapter Index ' Out:F_radSelected-Getting radio button selection ' Out:F_strWinservers-Getting new list wins servers ' L_(*)-Localization content '------------------------------------------------------------------------- Sub ServePage() Err.CLear On Error Resume Next Dim objNetAdapter 'To hold network adapter object instance Dim strDHCPEnabled 'to hold the value Dhcp enabled or not Call SA_TraceOut( SOURCE_FILE, "ServePage()") ' Getting the Network adapter objects set objNetAdapter = getNetworkAdapterObject(G_objService,F_nNWadapterindex) If Err.number <>0 then Call SA_TraceOut( SOURCE_FILE, "Error in getting Network adapter Object-ServePage()") Call SA_ServeFailurePage(L_NIC_ADAPTERINSTANCEFAILED_ERRORMESSAGE) Exit Sub End If 'Get Whether the DHCP is enabled on the NIC. strDHCPEnabled = isDHCPenabled(objNetAdapter) %>
<%=GetNicName(F_nNWadapterindex)%>
 
<%=L_CONFIGURATION_TEXT%> onClick="EnableOK();HandleControls(true)"> <%=L_OBTAINIPFROMDHCP_TEXT%>
  onClick="EnableOK(); enableWINSControls();" > <%=L_NIC_IP_CONFIGUREMANUALLY%>
<%=L_WINS_SERVER_ADDRESS_TEXT%>
<%=L_WINSADDRESSES_TEXT%> <% Call SA_ServeOnClickButtonEx(L_BUTTON_ADD_TEXT, "", "JavaScript:verifyIPaddress()", 60, 0, "DISABLED", "btnAddwinsserver") %>




<% Call SA_ServeOnClickButtonEx(L_BUTTON_REMOVE_TEXT, "", "javaScript:removeIPFromWINSserverListbox()", 60, 0, "DISABLED", "btnRemovewinsserver") %>
<% 'destroying dynamically created objects Set objNetAdapter=Nothing End Sub '------------------------------------------------------------------------- ' Function Name: GetWINSConfiguration ' Description: To retrieve the WINS configuration settings ' for the network adapter from system. ' Input Variables: nFormReload - a flag value to differentiate ' intial loading and form submition. ' Output Variables: None ' Returns: True/False ' Global Variables: In : F_nNWadapterindex - Index of adapter(WMI index number) ' In : L_INVALIDOBJECT_ERRORMESSAGE ' In : G_objService - WMI Connection Object ' Out: F_WINSERVER - #-separated list of WINS servers ' 'On Form intial loading gets the NIC adapter descrition and WINS servers 'from WMI .Displays the error message on failure of getting object from WMI. 'On form Reloading/submitting gets only description of NIC adapter. '------------------------------------------------------------------------- Function GetWINSConfiguration(nFormReload) Err.Clear On Error Resume Next Const IPCONST="127.0.0.0" Dim objWinsCfg 'To hold Network adapter object instance Call SA_TraceOut( SOURCE_FILE, "GetWINSConfiguration()") Set objWinsCfg = G_objService.Get("Win32_NetworkAdapterConfiguration.Index=" _ & chr(34) & F_nNWadapterindex & chr(34)) 'if initial load failure then ServeFailurePage called else SetErrMsg If Err.Number <> 0 Then Call SA_TraceOut( SOURCE_FILE, "Error in getting Network adapter object-GetWINSConfiguration()") If nFormReload Then SA_SetErrMsg L_INVALIDOBJECT_ERRORMESSAGE & " (" & HEX(Err.Number) & ")" Else Call SA_ServeFailurePage( L_INVALIDOBJECT_ERRORMESSAGE) End If GetWINSConfiguration = FALSE Exit Function End If If (nFormReload) Then ' Form being reloaded, keep the other values since they ' are passed through the form. Exit Function End If F_strWinservers = "" 'WMI returns '127.0.0.0' for server addresses that are not set 'so we must treat this value same as an unset address If Len(Trim(objWinsCfg.WINSPrimaryServer)) > 0 Then If objWinsCfg.WINSPrimaryServer <> IPCONST Then F_strWinservers = F_strWinservers & objWinsCfg.WINSPrimaryServer & "#" End If End If If Len(Trim(objWinsCfg.WINSSecondaryServer)) > 0 Then If objWinsCfg.WINSSecondaryServer <> IPCONST Then F_strWinservers = F_strWinservers & objWinsCfg.WINSSecondaryServer & "#" End If End If GetWINSConfiguration = True 'Destroying dynamically created objects Set objWinsCfg=Nothing End Function '------------------------------------------------------------------------- ' Function name: SetWINSserverConfiguration ' Description: Sets the WINS Configuration for the N/W Adapter. ' Input Variables: None ' Output Variables: None ' Return Values: True on sucess, False on error (and error msg ' will be set by SetErrMsg) ' Global Variables: In: F_nNWadapterindex -Index of adapter (WMI index number) ' In: F_strWinservers - #-separated list of WINS server IPs ' In: G_objService - WMI Connection Object ' In: L_SETWINSFAILED_ERRORMESSAGE ' In: L_INVALIDOBJECT_ERRORMESSAGE ' ' Updates system with WINS servers as given by F_strWinservers. If an error ' occurs, sets error message with SetErrMsg and exits with False. '------------------------------------------------------------------------- Function SetWINSserverConfiguration() Err.Clear On Error Resume Next Dim objWinsCfg 'To hold Network adapter object instance Dim strPrimAdd 'To hold Primary Wins server Dim strSecAdd 'To hold Secondary Wins server Dim arrWinsSrv 'TO hold the array list of wins servers Dim nValue 'To hold return value of the Wmi method Call SA_TraceOut( SOURCE_FILE, "SetWINSserverConfiguration()") Set objWinsCfg = G_objService.Get("Win32_NetworkAdapterConfiguration.Index=" & _ chr(34) & F_nNWadapterindex & chr(34)) If Err.Number <> 0 Then Call SA_TraceOut( SOURCE_FILE, "Error in getting Network adapter object-SetWINSserverConfiguration()") SA_SetErrMsg L_INVALIDOBJECT_ERRORMESSAGE & " (" & HEX(Err.Number) & ")" SetWINSserverConfiguration = FALSE Exit Function End If arrWinsSrv = split(F_strWinservers, "#") 'Convert the array into a primary and secondary WINS server, ' as required by WMI. strPrimAdd = "" strSecAdd = "" If Ubound(arrWinsSrv) > 0 Then strPrimAdd = arrWinsSrv(0) If Ubound(arrWinsSrv) > 1 Then strSecAdd = arrWinsSrv(1) End If End If nValue = objWinsCfg.SetWINSServer(strPrimAdd, strSecAdd) If (Err.Number <> 0 or nValue <> 0 )Then Call SA_TraceOut( SOURCE_FILE, "Error in setting wins server settings-SetWINSserverConfiguration()") SA_SetErrMsg L_SETWINSFAILED_ERRORMESSAGE & " (" & HEX(Err.Number) & ")" SetWINSserverConfiguration = false Else SetWINSserverConfiguration = true End If 'Destroying dynamically created objects Set objWinsCfg=Nothing End Function '------------------------------------------------------------------------- ' Function Name: OutputWINSServersToListbox ' Description: To display the WINS Servers in the LISTBOX. ' Input Variables: None. ' Output Variables: None. ' Returns: None. ' Global Variables: In: F_WINSERVER - #-separated list of WINS server IPs ' This function Outputs WINS servers to the listbox control in the Form. '------------------------------------------------------------------------- Function OutputWINSServersToListbox() Err.Clear On Error Resume Next Call SA_TraceOut( SOURCE_FILE, "OutputWINSServersToListbox()") Dim arrWinsSrv 'To hold the Wins server list Dim nIndex 'To hold the Wins server list Index arrWinsSrv = split(F_strWinservers,"#") nIndex = 0 If (NOT IsNull(arrWinsSrv)) Then If IsArray(arrWinsSrv) Then For nIndex = LBound(arrWinsSrv) to UBound(arrWinsSrv) If arrWinsSrv(nIndex) <> "" Then Response.Write "" End If Next End If End If End Function '------------------------------------------------------------------------- 'Function: GetDefaultValues 'Description: gets default values of wins server setting 'Input Variables: None 'Output Variables: None 'Returns: True/False 'Global Variables: In:G_objService-Getting WMI connection Object ' Out:F_nNWadapterindex-Getting NIC adapter Index ' Out:F_radSelected-Getting radio button selection ' In:L_(*)-Localization content '------------------------------------------------------------------------- Function GetDefaultValues() Err.Clear On Error Resume Next Dim objNetAdapter 'holds network adapter object Const DHCPON="ON" 'Const for dhcp on Const DHCPOFF="OFF" 'Const for dhcp off Call SA_TraceOut( SOURCE_FILE, "GetDefaultValues()") 'getting NIC adapter Index from area page F_nNWadapterindex = Request.QueryString("PKey") 'Getting WMI connection Object on error displays failure page Set G_objService=GetWMIConnection(CONST_WMI_WIN32_NAMESPACE) set objNetAdapter = getNetworkAdapterObject(G_objService,F_nNWadapterindex) 'getting default wins server settings from system GetWINSConfiguration(0) 'checking for the DHCP is enabled or not If isDHCPenabled(objNetAdapter) Then F_radSelected = DHCPON Else F_radSelected = DHCPOFF End If GetDefaultValues=True 'destroying dynamically created objects Set objNetAdapter=Nothing End Function %>