Help - Search - Members - Calendar
Full Version: VBscript help
MSFN Forums > Coding, Scripting and Servers > Programming (C++, Delphi, VB, etc.)

   
Google Internet Forums Unattended CD/DVD Guide
`Felix`
Hi all,

Have been looking around the net but haven't been able to find anothing suitable... sad.gif

Ok i am looking for some help/advise on a script that will allow me to extract the value of multiple radio button fields and take all those values and output them to a text file. to provide a better understanding here is the form layout below.

CODE
<form value="form1">
<table border="1" width="300">
<tr>
  <td>object 1</td>
</tr>
<tr>
  <td>
    <input type="radio" value="object1" name="Disable">Disable
    <input type="radio" value="object1" name="Automatic">Automatic
    <input type="radio" value="object1" name="Manual">Manual
  </td>
</tr>
<tr>
  <td>object 2</td>
</tr>
<tr>
  <td>
    <input type="radio" value="object2" name="Disable">Disable
    <input type="radio" value="object2" name="Automatic">Automatic
    <input type="radio" value="object2" name="Manual">Manual
  </td>
</tr>
<tr>
</table>


Now the [object+number] are only there to show that layout - the objects will dynamically populated fields from WMI so every block (disable, automatic, manual) will be different. Now once we have captured the values - all the selected disabled values need to be output to a txt file called disabled, all the automatic values to txt called automatic and so on....

I hope i have explained my requirements suitably, however if you need more information, please let me know.

I would appreciate any help/advise you can offer as i am slowly teaching myself VBS and am still very, very new to this.
gunsmokingman
I Change the form tag to a body tag, I added 2 function for each radio group
hope this is what you wanted.

QUOTE
CODE
<body>
<table border="1" width="300">
<tr>
  <td>object 1</td>
</tr>
<tr>
  <td>
    <input type="radio" value="Disable" name="Rad1" OnClick='UserChoice1()'>
    Disable
    <input type="radio" value="Automatic" name="Rad1" OnClick='UserChoice1()'>
    Automatic
    <input type="radio" value="Manual" name="Rad1" OnClick='UserChoice1()'>
    Manual
  <script LANGUAGE="VBScript">
    Function UserChoice1()
    If Rad1(0).Checked Then
    alert(Rad1(0).value)
    ElseIf Rad1(1).Checked Then
    alert(Rad1(1).value)
    ElseIf Rad1(2).Checked Then
    alert(Rad1(2).value)
    End If
    End Function
   </SCRIPT>
  </td>
</tr>
<tr>
  <td>object 2</td>
</tr>
<tr>
  <td>
    <input type="radio" value="Disable" name="Rad2" OnClick='UserChoice2()'>
    Disable
    <input type="radio" value="Automatic" name="Rad2" OnClick='UserChoice2()'>
    Automatic
    <input type="radio" value="Manual" name="Rad2" OnClick='UserChoice2()'>
    Manual
  <script LANGUAGE="VBScript">
    Function UserChoice2()
    If Rad2(0).Checked Then
    alert(Rad2(0).value)
    ElseIf Rad2(1).Checked Then
    alert(Rad2(1).value)
    ElseIf Rad2(2).Checked Then
    alert(Rad2(2).value)
    End If
    End Function
   </SCRIPT>
  </td>
</tr>
<tr>
</table>
`Felix`
QUOTE (gunsmokingman @ May 27 2008, 11:30 PM) *
I Change the form tag to a body tag, I added 2 function for each radio group
hope this is what you wanted.

QUOTE
CODE
<body>
<table border="1" width="300">
<tr>
   <td>object 1</td>
</tr>
<tr>
   <td>
     <input type="radio" value="Disable" name="Rad1" OnClick='UserChoice1()'>
     Disable
     <input type="radio" value="Automatic" name="Rad1" OnClick='UserChoice1()'>
     Automatic
     <input type="radio" value="Manual" name="Rad1" OnClick='UserChoice1()'>
     Manual
   <script LANGUAGE="VBScript">
     Function UserChoice1()
     If Rad1(0).Checked Then
     alert(Rad1(0).value)
     ElseIf Rad1(1).Checked Then
     alert(Rad1(1).value)
     ElseIf Rad1(2).Checked Then
     alert(Rad1(2).value)
     End If
     End Function
    </SCRIPT>
   </td>
</tr>
<tr>
   <td>object 2</td>
</tr>
<tr>
   <td>
     <input type="radio" value="Disable" name="Rad2" OnClick='UserChoice2()'>
     Disable
     <input type="radio" value="Automatic" name="Rad2" OnClick='UserChoice2()'>
     Automatic
     <input type="radio" value="Manual" name="Rad2" OnClick='UserChoice2()'>
     Manual
   <script LANGUAGE="VBScript">
     Function UserChoice2()
     If Rad2(0).Checked Then
     alert(Rad2(0).value)
     ElseIf Rad2(1).Checked Then
     alert(Rad2(1).value)
     ElseIf Rad2(2).Checked Then
     alert(Rad2(2).value)
     End If
     End Function
    </SCRIPT>
   </td>
</tr>
<tr>
</table>



Works fine in html, but not working in HTA sad.gif
gunsmokingman
It ran find on my computer, I am on Vista Sp1
This is what it should look like.

Scr1ptW1zard
Give this a try:

CODE
<html>
<head>
<title>Test</title>
   <HTA:APPLICATION
   ID = "objApp"
   APPLICATIONNAME = "Test"
   /HTA:APPLICATION>
</head>

<script language=javascript>
</script>
<script language=vbscript>
sub getOption(optobj)
  msgbox optobj.name + ": " + optobj.value
end sub
</script>

<body>
<table border="1" width="300">
<tr>
   <td>object 1</td>
</tr>
<tr>
   <td>
     <input type="radio" value="Disable" name="Rad1" OnClick='getOption(this);'>
     Disable
     <input type="radio" value="Automatic" name="Rad1" OnClick='getOption(this);'>
     Automatic
     <input type="radio" value="Manual" name="Rad1" OnClick='getOption(this);'>
     Manual
   </td>
</tr>
<tr>
   <td>object 2</td>
</tr>
<tr>
   <td>
     <input type="radio" value="Disable" name="Rad2" OnClick='getOption(this);'>
     Disable
     <input type="radio" value="Automatic" name="Rad2" OnClick='getOption(this);'>
     Automatic
     <input type="radio" value="Manual" name="Rad2" OnClick='getOption(this);'>
     Manual
   </td>
</tr>
<tr>
</table>
</body>
</html>

`Felix`
Hi People,

Have tried a number of variations with no success... i think i am missing something here... and i am pulling my hair out! realmad.gif

Here is the code i am currently working with...

CODE
<head>
  <title>test</title>
  <hta:application
    ID="objHTA"
    VERSION="1.0"
    applicationName="test"
/>
<style>
html, form, body, span {
    margin:0;
    font-family:Arial, Helvetica, sans-serif;
    border:0px;
    background-color: ghostwhite;
}

#content, #DiscriptionArea, #dName, #Options, td {
font-size:12px;
padding:5px;
}

#title {
    text-align:center;
    color: #FFFFFF;
    background-color: #3366FF;
    font-size:18px;
    font-weight: bold;
    border:0px;
}

#content{
    position:absolute;
    left:0px;
    width:100%;
    height:100%;
    /*overflow:auto;*/
}

#dName, #dDisc {
    background-color: #EAEAFF;
    font-weight: bold;
    border-top:solid 1px black;
}

#dDisc {
    border-top:solid 1px black;
    font-weight: normal;
    font-style: italic;
}

#options {
    background-color: #FFFFCC;
}

</style>
<script language="vbscript">
    Const wbemFlagReturnImmediately = &h10
    Const wbemFlagForwardOnly = &h20
    Dim Act         : Set Act = CreateObject("Wscript.Shell")
    Dim Fso         : Set Fso = CreateObject("Scripting.FileSystemObject")
    Dim strComputer : strComputer = "."
    Dim ObjWMI, Ts, objItem, colItems, SysName, Lst
    
        Set ObjWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'/----------------------------------------------------------------------->
   Set colItems = ObjWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", WmiVar)
'/----------------------------------------------------------------------->
    Sub GetServices
     strTITLE = "<table width='100%' height='40px'><tr><td align='center' valign='middle' id='title'>" & _
     objHTA.applicationName & " "& objHTA.Version & "</td></tr></table>"
     strNAME = "<table border='0' style='border-collapse: collapse' "  & _
        "bordercolor='#111111' width='100%'>"
   Set colItems = ObjWMI.ExecQuery("SELECT * FROM Win32_Service")
        For Each objItem In colItems
            intNumber = intNumber +1
          strNAME = strNAME & "<tr>"
      strNAME = strNAME & "<td id='dName' nowrap>" & objItem.DisplayName & _
      "</td><td rowspan='2' id='dDisc'>" & objItem.Description & _
      "</td></tr><tr><td id='options'>" &_
      "<input type='radio' name='object1' value='Disable' OnClick='getOption(this)'>Disable" &_
      "<input type='radio' name='object1' value='Automatic' OnClick='getOption(this)'>Automatic" & _
      "<input type='radio' name='object1' value='Manual' OnClick='getOption(this)'>Manual</td></tr>" & _
      "<tr><td>&nbsp;</td></tr>"
      NumTotalServices = intNumber
        Next
            Title.InnerHTML = strTitle
            strName = strName & "</table>"
            content.InnerHTML = strNAME
            'MsgBox NumTotalServices
    End Sub

sub getOption(optobj)
  msgbox optobj.name + ": " + optobj.value
end sub
    
  Sub GetDisc
     Set colItems = ObjWMI.ExecQuery("SELECT * FROM Win32_Service")
        For Each objItem In colItems
            strDISC = strDISC & objItem.Description & "<br><br>"
        Next
        DiscriptionArea.InnerHTML = strDISC            
    End Sub
    
      Sub ClearDisc
     Set colItems = ObjWMI.ExecQuery("SELECT * FROM Win32_Service")
        For Each objItem In colItems
            strDISC = strDISC
        Next
        DiscriptionArea.InnerHTML = strDISC            
    End Sub

Sub Radios()
    Const cMAX = 1
    Dim arrCTF(3)
    Dim intCTF
    Dim strCTF
    Dim arrDIC(3)
        arrDIC(1) = "Automatic"
        arrDIC(2) = "Disable"
        arrDIC(3) = "Manual"
    Dim intDIC
    Set objDIC = CreateObject("Scripting.Dictionary")
    For intDIC = 1 To UBound(arrDIC)
     objDIC.Add arrDIC(intDIC), intDIC
    Next
    Dim iMAX : iMAX = 0
    Dim i, o, s
    For i = 1 To cMAX
        For Each o In Eval("document.form1.object" & i)
            If o.Checked = True Then
                iMAX = iMAX + 1
                intCTF = objDIC.Item(o.Value)
                arrCTF(intCTF) = arrCTF(intCTF) & "object" & i & vbCrLf
            End If
        Next
    Next
   '*
    If iMAX = cMAX Then
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        For intDIC = 1 To UBound(arrDIC)
            strCTF = arrDIC(intDIC) & ".txt"
            Set objCTF = objFSO.CreateTextFile(strCTF,True)
                objCTF.Write arrCTF(intDIC)
            Set objCTF = Nothing
            s = s & "<li>" & strCTF & " : " & Replace(arrCTF(intDIC),vbCrLf," ") & vbCrLf
        Next
    Else
        Alert("Only " & iMAx & " of " & cMAX & " radio buttons checked!")
        Exit Sub
    End If
   '*
    document.write s
End Sub

'/----------------------------------------------------------------------->

    Sub Window_Onload
        Set colItems = objWMI.ExecQuery("Select * From Win32_DesktopMonitor")
        For Each objItem In colItems
            intHorizontal = objItem.ScreenWidth
            intVertical = objItem.ScreenHeight
        Next
        intLeft = (intHorizontal - 800) / 2
        intTop = (intVertical - 600) / 2
        window.resizeTo 800,600
        window.moveTo intLeft, intTop
        GetServices
        window.focus()        
        'playSound
    End Sub

Sub playSound
strSoundFile = ".\whats_going_on.wav"
Set objShell = CreateObject("Wscript.Shell")
strCommand = "sndrec32 /play /close " & chr(34) & strSoundFile & chr(34)
objShell.Run strCommand, 0, True
End Sub

</script>
</head>

<body>
<form name="form1">
<div id="title"></div>
<span id="text"><p>Selection what option you would like for each service.</p>
<table width="50%" border="0" align="center" cellpadding="5">
  <tr>
    <th width="50%" align="right"><input type="button" value="Create Configuration Files" onclick="Radios()"></th>
    <th width="50%" align="left"><input type="reset" value="Reset/Clear All Values" ></th>
  </tr>
</table>
</span>
<span id="content"></span>
</form>
</body>
gunsmokingman
I copy and pasted your code and it seemed to run fine on Vista Sp1.



Could you provide more details as to what the problem you are having.
Scr1ptW1zard
A couple of things that I see would be the following:

Make sure that the following is inserted before the script tag for "vbscript".
CODE
<script language="javascript">
</script>


All your option buttons are being given the same name. Change the following:
CODE
      "<input type='radio' name='object1' value='Disable' OnClick='getOption(this)'>Disable" &_
      "<input type='radio' name='object1' value='Automatic' OnClick='getOption(this)'>Automatic" & _
      "<input type='radio' name='object1' value='Manual' OnClick='getOption(this)'>Manual</td></tr>" & _


to

CODE
      "<input type='radio' name='object" + cstr(intNumber) + "' value='Disable' OnClick='getOption(this)'>Disable" &_
      "<input type='radio' name='object" + cstr(intNumber) + "' value='Automatic' OnClick='getOption(this)'>Automatic" & _
      "<input type='radio' name='object" + cstr(intNumber) + "' value='Manual' OnClick='getOption(this)'>Manual</td></tr>" & _


That seems to work for me under XP SP3.
`Felix`
Thanks Scr1ptW1zard/GSM - both your comments helped to me sorted... now below is the code i am currently using and it is working as i want, however i believe there is more than likely a cleaner way of producing the file with a single click after making whatever selections i want for each item.

I would appreciate and suggestions to clean up the processing....

CODE
<head>
    <title>ModifyServices Configurator</title>
    <hta:application
      ID="objHTA"
      VERSION="1.0"
      icon="simple.ico"
      applicationName="ModifyServices Configurator"
      border=dialog
      borderStyle=normal
      caption=yes
      contextMenu=yes
      innerBorder=yes
      maximizeButton=yes
      minimizeButton=yes
      navigable=yes
      scroll=yes
      selection=yes
      showInTaskBar=yes
      sysMenu=yes
      singleInstance=yes
      windowState=normal
  />
  
  <style>
  html, form, body, span {
      margin:0;
      font-family:Arial, Helvetica, sans-serif;
      border:0px;
      background-color: ghostwhite;
  }
  
  #content, #DiscriptionArea, #dName, #Options, td {
  font-size:12px;
  padding:5px;
  }
  
  #header {
      text-align:center;
      color: #FFFFFF;
      background-color: #3366FF;
      font-size:18px;
      font-weight: bold;
      border:0px;    
  }
  
  #content{
      position:absolute;
      left:0px;
      width:100%;
      height:440px;
      /*overflow:auto;*/
  }
  
  #dName, #dDisc {
      background-color: #EAEAFF;
      font-weight: bold;
      border-top:solid 1px black;
  }
  
  #dDisc {
      border-top:solid 1px black;
      font-weight: normal;
      font-style: italic;
  }
  
  #options {
      background-color: #FFFFCC;
  }
  
  
  * html,
  * html body {
  overflow-y: hidden!important;
  height: 100%;
  margin: 0;
  padding: 0;
  }
  
  * html #content {
  height: 440px;
  overflow-y: scroll;
  position: relative;
  }
  
  * html #header,
  * html #header-bottom,
  * html #header-middle  
  position: absolute;
  
  * html #footer,
  * html #footer-bottom,
  * html #footer-middle {
  position: absolute;
  bottom:0px;
  }
  </style>
  
  <script language="javascript">
  </script>
  <script language="vbscript">
      Const wbemFlagReturnImmediately = &h10
      Const wbemFlagForwardOnly = &h20
      Dim Act         : Set Act = CreateObject("Wscript.Shell")
      Dim Fso         : Set Fso = CreateObject("Scripting.FileSystemObject")
      Dim strComputer : strComputer = "."
      Dim ObjWMI, oList, objItem, colItems, SysName, Lst
      
          Set ObjWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  '/----------------------------------------------------------------------->
     Set colItems = ObjWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", WmiVar)
  '/----------------------------------------------------------------------->
      For Each objItem In colItems        
              SysName = objItem.CSName
          Next
          Lst = ".\List of Current Services on " & SysName & ".lst"
          Set oList = Fso.OpenTextFile(Lst, 2, True)
  
      Sub GetServices
       strheader = "<table width='100%' height='40px'><tr><td align='center' valign='middle' id='header'>" & _
       objHTA.applicationName & " "& objHTA.Version & "</td></tr></table>"
       strNAME = "<table border='0' style='border-collapse: collapse' "  & _
          "bordercolor='#111111' width='100%'>"
     Set colItems = ObjWMI.ExecQuery("SELECT * FROM Win32_Service")
          For Each objItem In colItems
              intNumber = intNumber +1
            strNAME = strNAME & "<tr>"
        strNAME = strNAME & "<td id='dName' nowrap>" & objItem.DisplayName & _
        "</td><td rowspan='2' id='dDisc'>" & objItem.Description & _
        "</td></tr><tr><td id='options'>" &_
        "<input type='radio' name='" + objItem.Name + "' value='Disable' OnClick='getOption(this)'>Disable" &_
        "<input type='radio' name='" + objItem.Name + "' value='Automatic' OnClick='getOption(this)'>Automatic" & _
        "<input type='radio' name='" + objItem.Name + "' value='Manual' OnClick='getOption(this)'>Manual</td></tr>" & _
        "<tr><td>&nbsp;</td></tr>"
        NumTotalServices = intNumber
          Next
              header.InnerHTML = strheader
              strName = strName & "</table>"
              content.InnerHTML = strNAME
              'MsgBox NumTotalServices
      End Sub
  
  Sub getOption(optobj)
  oList.WriteLine optobj.name + ": " + optobj.value
  End Sub
      
    Sub GetDisc
       Set colItems = ObjWMI.ExecQuery("SELECT * FROM Win32_Service")
          For Each objItem In colItems
              strDISC = strDISC & objItem.Description & "<br><br>"
          Next
          DiscriptionArea.InnerHTML = strDISC            
      End Sub
      
        Sub ClearDisc
       Set colItems = ObjWMI.ExecQuery("SELECT * FROM Win32_Service")
          For Each objItem In colItems
              strDISC = strDISC
          Next
          DiscriptionArea.InnerHTML = strDISC            
      End Sub
  '/----------------------------------------------------------------------->
  
      Sub Window_Onload
          Set colItems = objWMI.ExecQuery("Select * From Win32_DesktopMonitor")
          For Each objItem In colItems
              intHorizontal = objItem.ScreenWidth
              intVertical = objItem.ScreenHeight
          Next
          intLeft = (intHorizontal - 800) / 2
          intTop = (intVertical - 600) / 2
          window.resizeTo 800,600
          window.moveTo intLeft, intTop
          GetServices
          window.focus()        
          'playSound
      End Sub
  
  Sub playSound
  strSoundFile = ".\whats_going_on.wav"
  Set objShell = CreateObject("Wscript.Shell")
  strCommand = "sndrec32 /play /close " & Chr(34) & strSoundFile & Chr(34)
  objShell.Run strCommand, 0, True
  End Sub
  
  </script>
  </head>
  
  <body>
  <form name="form1">
  <span id="header"></span>
  <span id="text"><p>Selection what option you would like for each service.</p>
  <table width="50%" border="0" align="center" cellpadding="5">
    <tr>
      <th width="50%" align="right"><input type="button" value="Create Configuration Files" onclick="Radios()"></th>
      <th width="50%" align="left"><input type="reset" value="Reset/Clear All Values" ></th>
    </tr>
  </table>
  </span>
  <span id="content"></span>
  <span id"footer"></span>
  </form>
  </body>
Scr1ptW1zard
You could change a couple of things...

Remove the onclick routine from each radio button.
Add another button to perform the change.

Here is your code with the changes. I only commented out the getOption line that was writing the file, you can remove this subroutine and the associated calls to it if you like.


CODE
<head>
    <title>ModifyServices Configurator</title>
    <hta:application
      ID="objHTA"
      VERSION="1.0"
      icon="simple.ico"
      applicationName="ModifyServices Configurator"
      border=dialog
      borderStyle=normal
      caption=yes
      contextMenu=yes
      innerBorder=yes
      maximizeButton=yes
      minimizeButton=yes
      navigable=yes
      scroll=yes
      selection=yes
      showInTaskBar=yes
      sysMenu=yes
      singleInstance=yes
      windowState=normal
  />
  
  <style>
  html, form, body, span {
      margin:0;
      font-family:Arial, Helvetica, sans-serif;
      border:0px;
      background-color: ghostwhite;
  }
  
  #content, #DiscriptionArea, #dName, #Options, td {
  font-size:12px;
  padding:5px;
  }
  
  #header {
      text-align:center;
      color: #FFFFFF;
      background-color: #3366FF;
      font-size:18px;
      font-weight: bold;
      border:0px;    
  }
  
  #content{
      position:absolute;
      left:0px;
      width:100%;
      height:440px;
      /*overflow:auto;*/
  }
  
  #dName, #dDisc {
      background-color: #EAEAFF;
      font-weight: bold;
      border-top:solid 1px black;
  }
  
  #dDisc {
      border-top:solid 1px black;
      font-weight: normal;
      font-style: italic;
  }
  
  #options {
      background-color: #FFFFCC;
  }
  
  
  * html,
  * html body {
  overflow-y: hidden!important;
  height: 100%;
  margin: 0;
  padding: 0;
  }
  
  * html #content {
  height: 440px;
  overflow-y: scroll;
  position: relative;
  }
  
  * html #header,
  * html #header-bottom,
  * html #header-middle  
  position: absolute;
  
  * html #footer,
  * html #footer-bottom,
  * html #footer-middle {
  position: absolute;
  bottom:0px;
  }
  </style>
  
  <script language="javascript">
  function Save()
  {
    var all=document.body.all.tags("INPUT");

    for(var i=0;i<all.length;i++)
    {
      if(all[i].type=="radio" && all[i].checked)
      {
        oList.writeline(all[i].name + ": " + all[i].value);
      }
    }
  }
  </script>
  <script language="vbscript">
      Const wbemFlagReturnImmediately = &h10
      Const wbemFlagForwardOnly = &h20
      Dim Act         : Set Act = CreateObject("Wscript.Shell")
      Dim Fso         : Set Fso = CreateObject("Scripting.FileSystemObject")
      Dim strComputer : strComputer = "."
      Dim ObjWMI, oList, objItem, colItems, SysName, Lst
      
          Set ObjWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  '/----------------------------------------------------------------------->
     Set colItems = ObjWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", WmiVar)
  '/----------------------------------------------------------------------->
      For Each objItem In colItems        
              SysName = objItem.CSName
          Next
          Lst = ".\List of Current Services on " & SysName & ".lst"
          Set oList = Fso.OpenTextFile(Lst, 2, True)
  
      Sub GetServices
       strheader = "<table width='100%' height='40px'><tr><td align='center' valign='middle' id='header'>" & _
       objHTA.applicationName & " "& objHTA.Version & "</td></tr></table>"
       strNAME = "<table border='0' style='border-collapse: collapse' "  & _
          "bordercolor='#111111' width='100%'>"
     Set colItems = ObjWMI.ExecQuery("SELECT * FROM Win32_Service")
          For Each objItem In colItems
              intNumber = intNumber +1
            strNAME = strNAME & "<tr>"
        strNAME = strNAME & "<td id='dName' nowrap>" & objItem.DisplayName & _
        "</td><td rowspan='2' id='dDisc'>" & objItem.Description & _
        "</td></tr><tr><td id='options'>" &_
        "<input type='radio' name='" + objItem.Name + "' value='Disable' OnClick='getOption(this)'>Disable" &_
        "<input type='radio' name='" + objItem.Name + "' value='Automatic' OnClick='getOption(this)'>Automatic" & _
        "<input type='radio' name='" + objItem.Name + "' value='Manual' OnClick='getOption(this)'>Manual</td></tr>" & _
        "<tr><td>&nbsp;</td></tr>"
        NumTotalServices = intNumber
          Next
              header.InnerHTML = strheader
              strName = strName & "</table>"
              content.InnerHTML = strNAME
              'MsgBox NumTotalServices
      End Sub
  
  Sub getOption(optobj)
'  oList.WriteLine optobj.name + ": " + optobj.value
  End Sub
  
    Sub GetDisc
       Set colItems = ObjWMI.ExecQuery("SELECT * FROM Win32_Service")
          For Each objItem In colItems
              strDISC = strDISC & objItem.Description & "<br><br>"
          Next
          DiscriptionArea.InnerHTML = strDISC            
      End Sub
      
        Sub ClearDisc
       Set colItems = ObjWMI.ExecQuery("SELECT * FROM Win32_Service")
          For Each objItem In colItems
              strDISC = strDISC
          Next
          DiscriptionArea.InnerHTML = strDISC            
      End Sub
  '/----------------------------------------------------------------------->
  
      Sub Window_Onload
          Set colItems = objWMI.ExecQuery("Select * From Win32_DesktopMonitor")
          For Each objItem In colItems
              intHorizontal = objItem.ScreenWidth
              intVertical = objItem.ScreenHeight
          Next
          intLeft = (intHorizontal - 800) / 2
          intTop = (intVertical - 600) / 2
          window.resizeTo 800,600
          window.moveTo intLeft, intTop
          GetServices
          window.focus()        
          'playSound
      End Sub
  
  Sub playSound
  strSoundFile = ".\whats_going_on.wav"
  Set objShell = CreateObject("Wscript.Shell")
  strCommand = "sndrec32 /play /close " & Chr(34) & strSoundFile & Chr(34)
  objShell.Run strCommand, 0, True
  End Sub
  
  </script>
  </head>
  
  <body>
  <form name="form1">
  <span id="header"></span>
  <span id="text"><p>Selection what option you would like for each service.</p>
  <table width="50%" border="0" align="center" cellpadding="5">
    <tr>
      <th width="33%" align="right"><input type="button" value="Create Configuration Files" onclick="Radios()"></th>
      <th width="33%" align="middle"><input type="reset" value="Reset/Clear All Values" ></th>
      <th width="33%" align="left"><input type="button" value="Save All Values" onclick="Save()"></th>
    </tr>
  </table>
  </span>
  <span id="content"></span>
  <span id"footer"></span>
  </form>
  </body>

`Felix`
QUOTE (Scr1ptW1zard @ May 30 2008, 12:48 AM) *
You could change a couple of things...

Remove the onclick routine from each radio button.
Add another button to perform the change.

Here is your code with the changes. I only commented out the getOption line that was writing the file, you can remove this subroutine and the associated calls to it if you like.


EXCELLENT!

That has sorted out my issues - thank you very much!

Have one other question for you that is indirectly related - i would ideally like to populate the fields with the current settings for each service and then if there is a change from the current setting - output this value (selected by the radio button) to the text file... can this be done easily of is it a really pain in the rear end?

PS i certainly prefer coding in JS as i have some basic knowledge here - whereas i am learning the VBS as i go... I didn't know i could use both and share var's etc - this is really cool and i am learning allot from this development... thankyou again for your help and input it is greatly appreaciated!
Scr1ptW1zard
To have the service start mode pre-selected with the current setting, change your GetServices subroutine to retrieve the current mode and "check" the appropriate radio button like so:

CODE
    Sub GetServices
        strheader = "<table width='100%' height='40px'><tr><td align='center' valign='middle' id='header'>" & _
            objHTA.applicationName & " "& objHTA.Version & "</td></tr></table>"
        strNAME = "<table border='0' style='border-collapse: collapse' "  & _
            "bordercolor='#111111' width='100%'>"
        Set colItems = ObjWMI.ExecQuery("SELECT * FROM Win32_Service")
        For Each objItem In colItems
            intNumber = intNumber +1
            strNAME = strNAME & "<tr>"
            strNAME = strNAME & "<td id='dName' nowrap>" & objItem.DisplayName & _
                "</td><td rowspan='2' id='dDisc'>" & objItem.Description & _
                "</td></tr><tr><td id='options'>" &_
                "<input type='radio' name='" + objItem.Name + "' value='Disable' OnClick='getOption(this)'"
            if lcase(objItem.StartMode)="disabled" then strName=strName + " checked"
            strName=strName & ">Disable" &_
                "<input type='radio' name='" + objItem.Name + "' value='Automatic' OnClick='getOption(this)'"
            if lcase(objItem.StartMode)="auto" then strName=strName + " checked"
            strName=strName & ">Automatic" & _
                "<input type='radio' name='" + objItem.Name + "' value='Manual' OnClick='getOption(this)'"
            if lcase(objItem.StartMode)="manual" then strName=strName + "checked"
            strName=strName & ">Manual</td></tr>" & _
                "<tr><td>&nbsp;</td></tr>"
            NumTotalServices = intNumber
        Next
        header.InnerHTML = strheader
        strName = strName & "</table>"
        content.InnerHTML = strNAME
        'MsgBox NumTotalServices
    End Sub


As for recording any changes, you actually already have this functionality. Simply write your changes from the GetOption subroutine:

CODE
    Sub getOption(optobj)
        oList.WriteLine "Change made: " + optobj.name + ": " + optobj.value
    End Sub


That should do it.
`Felix`
Scr1ptW1zard,

Thank you very much for your patience and help - it is greatly appreciated!


Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.