HTA help

Author Message
EQNish

  • Total Posts : 5
  • Scores: 0
  • Reward points : 0
  • Joined: 8/8/2011
  • Status: offline
HTA help Wednesday, November 16, 2011 4:19 AM (permalink)
0
I'm rewriting an my older script to dynamically list printers off our print server, and, the below code does not seem to build the HTML as I had intended.  I start the building at line 45 putting together strings, I'm not sure my loop is working either.  any help or direct is appreciated
 <head>
<title>HTA Test</title>
<HTA:APPLICATION
    ID               = "objHTA"
    APPLICATIONNAME  = "DMA Printer Utility"
    SCROLL           = "no"
    border           = "thick"
    borderStyle      = "normal"
    caption          = "yes"
    contextMenu      = "no"
    maximizeButton   = "no"
    minimizeButton   = "no"
    navigable        = "yes"
    showInTaskbar    = "yes"
    singleInstance   = "yes"
    sysmenu          = "yes"
    version          = "0.1"
/>
<script language="VBScript">
   Sub Window_Onload
 Dim objWMIService, objItem, colItems, strComputer, intPrinters, intMatch1, intMatch2
 strComputer ="."
 strServer ="hawkins"
 intPrinters = 1        Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
       Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor where DeviceID = 'DesktopMonitor1'")
       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
       
  Set objWMIService = GetObject ("winmgmts:\\" & strServer & "\root\CIMV2")
  Set colItems = objWMIService.ExecQuery ("SELECT * FROM Win32_Printer")
  Wscript.sleep 2000
  For Each objItem In colItems
   intMatch1 =instr (1,ObjItem.Location,"Private",1)
   intMatch2 =instr (1,ObjItem.Location,"Private",1)
   if intMatch1 = 0 OR intMatch2 = 0 Then
  
   StrHtml1="<td bgcolor="& chr(34) & "white"& chr(34)&  "style="& chr(34) & "text-align: center"& chr(34) & "><input name="& chr(34) & "Select_Printer"& chr(34) & " type="& chr(34) & "checkbox"& chr(34) & " /></td>"
   STrHTml2="<td bgcolor="& chr(34) & "white"& chr(34)&  "style="& chr(34) & "text-align: center"& chr(34) & "><input name="& chr(34) & "group1"& chr(34) & " type="& chr(34) & "radio"& chr(34) & " value="& chr(34) & "1"& chr(34) & " /></td>"
   STrHTml3="<td bgcolor="& chr(34) & "white"& chr(34) & ">" objItem.ShareName "& chr(34) & "</td>"
   STrHTml4="<td bgcolor="& chr(34) & "white"& chr(34) & ">" objItem.Location "& chr(34) & "</td>"
   DataArea1.InnerHTML = STrHTml1 & STrHTml2 & STrHTml3 & STrHTml4
   DataArea2.InnerHTML= DataArea2 & DataArea1
 
  End if
  intPrinters = intPrinters + 1
 Next
End Sub
Sub RunScript
   Dim objNetwork
End Sub sub Wait()
 If strComputer = "." then
  strComputer = "Local Host"
  Else strComputer = strComputer
 end if
'WScript.Echo "Wait 2 mins for " & strComputer & " to enumerate printers"
End Sub          
</script> <body>
Please Check which Printer in install, and if it is to be the default or not<br>
<table cellpadding="0" cellspacing="0">
<tbody>
        <tr>
           <td style="text-align: center; background-color: white; width: 50px">Install</td>
           <td style="text-align: center; background-color: white; width: 100px">Make Default</td>
           <td style="text-align: center; background-color: white; width: 300px">&nbsp;</td>
           <td style="text-align: center; background-color: white;">&nbsp;</td>
        </tr>
   <tr>
   <span id="DataArea2"></span>        
  </tr>
        
</tbody>
</table>
<br>
<hr>
<body>
   <table border="0" cellpadding="0" cellspacing="1">
 <tbody>
            <tr>
        <td colspan="1" rowspan="1" nowrap="nowrap" width="500px">
   <input type="button" value="Install Printers" name="run_button" onClick="RunScript">
   <span id="DataArea"><br>Click to Install selected Printers<br></span>
   <span id="DataArea2"><br></pre></span>
   <input align="center" name="Exit" onclick="CloseWindow" type="button" value="Exit" /></td>
        <td align="middle" nowrap="nowrap" valign="center">
   <img alt="DMA The Greatest place on earth" height="200" src="\\bob\public\dma_logo.jpg" width="200" />
        </td>
      </tr>
        </tbody>
    </table>
</body> 

 
#1
    rasimmer

    • Total Posts : 2363
    • Scores: 163
    • Reward points : 0
    • Joined: 3/19/2009
    • Location: Cedar Rapids, IA
    • Status: offline
    Re:HTA help Thursday, November 17, 2011 5:41 AM (permalink)
    0
    You should really use HTML DOM (Document Object Model) to dynamically create tables.  There are alot of ways to do things in scripting, but this is how typically dynamically generate a table.  If you search the forum for keywords like .InsertCell(), I've posted alot of different examples.  Here is something to get you start though:
     
    <!DOCTYPE HTML PUBLIC "-//W3C//Dth HTML 4.0 Transitional//EN">
    <html>
    <head>
        <META http-equiv=Content-Type content="text/html; CHARSET=iso-8859-1">
        <title>Dynamic Table</title>
    <style type="text/css">
        body {
            font-family:Verdana;
            font-size: 8px;
            color: #49403B;
            background: #FFFFFF;
            text-align: center;
            }
       
        table.Results, th.Results, td.Results {
            border-width: thin;
            border-color: black;
            border-style: groove;
            border-collapse: collapse;
            font-size: 9px;
        }   
       
        th.Results {
            font-size:10px;
         font-weight:bold;
         background-color:goldenrod;
         color:#FFFFFF;
         text-align:center;
         padding: 5px;
         margin-top:0px;
        }
    </style>
    <script language="vbscript" type="text/vbscript">
    Call Center_HTA(600, 600)
    Sub Window_Onload()
        Generate_Table()
    End Sub
    Sub Center_HTA( widthX, heightY )
        self.ResizeTo widthX, heightY
        self.MoveTo (screen.Width - widthX)/2, (screen.Height - heightY)/2
    End Sub
    Sub Generate_Table
        Set objWMI = GetObject("WinMGMTS://./Root/CIMv2")
        arrAttributes = Array("Name", "DisplayName", "ProcessID", "Status")
        Set colItems = objWMI.ExecQuery("Select " & Join(arrAttributes, ",") & " From Win32_Service")
        'Create a table in the document
        Set objTable = document.createElement("TABLE")
        'Create a table header
        Set objTHead = objTable.createTHead()
        'Insert a row into the table header
        Set objRow = objTHead.InsertRow()
        'Loop through the attributes in the array
        For Each strAttrib In arrAttributes
            'Add a TH cell
            Set objTH = document.createElement("TH")      
            'Add text to the cell
            objTH.InnerText = strAttrib
            'Apply the .Results style class to the cell
            objTH.className = "Results"
            'Append the new TH to the TR
            objRow.appendChild(objTH)
        Next
        'Create a table body
        Set objTBody = document.createElement("TBODY")   
        'Apply the .Results style class to the cell
        objTable.className = "Results"
        'Append the body to the table created
        objTable.appendChild(objTBody)
        'Append the shell table into the DIV
        div_Main.appendChild(objTable)
        'Loop through WMI and set each cell with the appropriate property
        For Each objItem In colItems
            'Insert a row into the table body
            Set objRow = objTBody.InsertRow(-1)
            'Add a cell for Name
            Set objCell = objRow.InsertCell(-1)
            'Add text to the cell with the WMI Property
            objCell.InnerText = objItem.Name
            'Apply the .Results style class to the cell
            objCell.className = "Results"
            'Add a cell for DisplayName
            Set objCell = objRow.InsertCell(-1)
            'Add text to the cell with the WMI Property
            objCell.InnerText = objItem.DisplayName
            'Apply the .Results style class to the cell
            objCell.className = "Results"
           
            'Add a cell for ProcessID
            Set objCell = objRow.InsertCell(-1)
            'Add text to the cell with the WMI Property
            objCell.InnerText = objItem.ProcessId
            'Apply the .Results style class to the cell
            objCell.className = "Results"
                   
            'Add a cell for Status
            Set objCell = objRow.InsertCell()
            'Add text to the cell with the WMI Property
            objCell.InnerText = objItem.Status
            'Apply the .Results style class to the cell
            objCell.className = "Results"
        Next
    End Sub
    </script>
    <hta:application
     applicationname="Dynamic Table"
     border="dialog"
     borderstyle="normal"
     caption="yes"
     contextmenu="no"
     icon="no.ico"
     maximizebutton="yes"
     minimizebutton="yes"
     navigable="no"
     scroll="yes"
     selection="no"
     showintaskbar="yes"
     singleinstance="yes"
     sysmenu="no"
     version="1.0"
     windowstate="normal"
    >
    </head>
        <body>
            <div id="div_Main"></div>
        </body>
    </html>
     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9