Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


output as hta help

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,47372
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> output as hta help
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 output as hta help - 5/22/2007 2:00:28 AM   
  faulkkev

 

Posts: 151
Score: 0
Joined: 11/1/2005
Status: offline
How would I go about making the output for this code use hta html type format.  the script just pulls local group memberships and local account info.  Watered down from bigger script might be some unused code but it works fine minus I would like to improve the output to html.


strFilePath = "c:\test.txt"
output = "c:\output.txt"
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objfile = objfso.CreateTextFile(output, True)
Set objtextFile = objFSO.OpenTextFile (strFilePath)

wscript.echo " To run this script you must have a file on your C: drive named c:\test with a list of computer names. " & "" & " All ouput will be written to c:\output.txt. " & _
            " The proper format of the server list is one computer name on top of another " & " Ex. computer 1 " & vbCrLf & _                                                                         
            "                                                                                                                computer 2      "
Do Until objtextFile.AtEndOfStream
strComputer = Trim(objtextFile.ReadLine)
       if len(strComputer) <> 0 then
objfile.writeline "****************************************************************"
objfile.writeline " Summary for computer " & strcomputer & " Starts here"
objfile.writeline " "
objfile.writeline "****************************************************************"
on error resume next
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
if err.number = 0 then
count = count + 1
       
                    get_localaccountinfo(strcomputer)
                     get_localgroupmembers(strcomputer)
  else
noconnect = noconnect  + 1
objfile.writeline " "
objfile.writeline "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ "
objfile.writeline " error connecting to " & strcomputer
objfile.writeline "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ "
objfile.writeline " "
  end if


end if
err.clear
loop
objfile.writeline " "
objfile.writeline " "
if count = 0 then
  objfile.writeline 0 & " Comuters were Successfully Connected to "
else
  objfile.writeline count & " Comuters were Successfully Connected to "
end if
objfile.writeline " "
if noconnect = 0 then
   objfile.writeline 0 & " Computers were not Successfully Connected to "
    else
     objfile.writeline noconnect & " Computers were not Successfully Connected to "
  end if
objfile.close
objTextFile.close
Wscript.CreateObject("WScript.Shell").Run Output
'result = objfso.OpenTextFile(output, 1).ReadAll
'wscript.echo result
'******************************SUB ROUTINES******************************************




'**************SUB GET LOCAL ACCOUNT INFO****************************
sub get_localaccountinfo(strcomputer)
on error resume next
objfile.writeline " "
objfile.writeline "    *Local Account Info*      "
objfile.writeline " "
set objArgs=wscript.Arguments
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set UsrObj = GetObject("WinNT://" & strcomputer)
if err.Number<>0 then
objfile.writeline CHR(13)
objfile.writeline "ERROR CONNECTING TO . !"
err.clear
objfile.writeline CHR(13)
wscript.quit
end if
objfile.writeline    "Name: " & vbtab & _
      "Full Name: " & vbtab & _
      "Description: " & vbtab & _
      "Last Login:  " & vbtab & _
      "Password Expires:  " & vbtab & _
      "Password Age day(s):  "   & vbtab & _
      "Account Expires:  "   & vbtab & _  
      "Password Expired:  "   & vbtab & _  
      "Account Disabled: "
objfile.writeline " "
 
UsrObj.Filter = Array("user")
for each item in UsrObj


if item.UserFlags >=65536 then
 sPasswordExpires = "Never"
else
 sPasswordExpires = item.PasswordExpirationDate
end if

if item.AccountExpirationDate="" then
 sAccountExpires = "Never"
else
 sAccountExpires = item.AccountExpirationDate
end if
If item.AccountDisabled = True Then
 sAccountDisabled = "Yes"
 Else sAccountDisabled = "No"
End If

sfullname = item.fullname
sDescription = item.Description
sLastLogin = item.LastLogin
sPasswordExpired = item.PasswordExpired
sPasswordAge = FormatNumber(item.PasswordAge/86400)
objfile.writeline item.Name & vbtab & _
                         sfullname & vbtab & _
           sDescription & vbtab & _
           sLastLogin & vbtab & _
           sPasswordExpires & vbtab & _
           sPasswordAge & vbtab & _
           sAccountExpires & vbtab & _
           sPasswordExpired  & vbtab & _
           sAccountDisabled


Next
set usrobj=Nothing
objfile.writeline " "
objfile.writeline " "

end sub


'**************SUB GET LOCAL Group MEMBERS****************************
sub get_localgroupmembers(strcomputer)
on error resume next
objfile.writeline " "
objfile.writeline "    *Local GROUP MEMBERS*      "
objfile.writeline " "


err.clear

Set colgroups = GetObject("WinNT://" & strComputer & ",computer")
colGroups.GetInfo

colGroups.Filter = Array("Group")

For Each objgroup In colGroups
      objfile.writeline " " & strcomputer & " LOCAL GROUP " & objgroup.name

          
For Each objuser in objgroup.members
intcount = intcount + 1

  
if objuser.name <> "" then
                     user=objuser.name
    found = true
   
  end if


        if found = true then
          objfile.writeline "      " & user & ", " & objuser.fullname
         
        end if
                if err.number <> 0 then
                   objfile.writeline "      " & user
 
                end if
   err.clear   
next  

       
if intcount = 0 then
   objfile.writeline "      Group Is Empty "
end if
   objfile.writeline  ""



found = false
intcount = 0
next
objfile.writeline "  "

err.clear
 
set objuser=Nothing
objfile.writeline " "
objfile.writeline " "

end sub
Function WMIDateStringToDate(utcDate)
  WMIDateStringToDate = CDate(Mid(utcDate, 5, 2)  & "/" & _
      Mid(utcDate, 7, 2)  & "/" & _
          Left(utcDate, 4)    & " " & _
              Mid (utcDate, 9, 2) & ":" & _
                  Mid(utcDate, 11, 2) & ":" & _
                     Mid(utcDate, 13, 2))

End Function











 
 
Post #: 1
 
 RE: output as hta help - 5/22/2007 11:27:11 AM   
  BBistheKing

 

Posts: 107
Score: 0
Joined: 6/21/2005
Status: offline
Hi

You first change your output file to an extension of .hta or .htm. Secondly, in the .writeline codes you add your html tags.

eg. objfile.writeline "<html><body><font ...formatting goes here> Summary for computer " & strcomputer & " Starts here.. then the rest of your .writeline stuff...</font></body></html>"

Is that what you were after?

_____________________________

"Live simply, that others may simply live." - Mahatma Gandhi

(in reply to faulkkev)
 
 
Post #: 2
 
 RE: output as hta help - 5/23/2007 1:50:19 AM   
  faulkkev

 

Posts: 151
Score: 0
Joined: 11/1/2005
Status: offline
Yes this is kind of what I was looking for.  My issues is how to put the code in and use tables etc to make it look nice.  I'm having issues knowing where to  define the html body etc to allow the code to run and the output to be correct.

(in reply to faulkkev)
 
 
Post #: 3
 
 RE: output as hta help - 5/23/2007 5:48:27 AM   
  ehvbs

 

Posts: 2223
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi faulkkev,

while it's not impossible to retrofit a script that puts out text lines
with html formatting, it's surely a pain. I'd use a html editor to design
a page looking like the desired result and replace the informational
content with placeholders

  <html>
    <head>
       ..... lots of html that never changes ...
   </head>
   <body ..... >
       ..... lots of html that never changes ...
      <div ....>     
         ..... lots of html that never changes ...
         <table .... >
           ..... lots of html that never changes ...
            <tr ... ><td ...>§UserShortName§</td></tr>
            <tr ... ><td ...>§UserFullName§</td></tr>
              ..... lots of html that never changes ...
</html>

In the original script, I'd replace line like

objfile.writeline "      " & user & ", " & objuser.fullname

with

  dicRpl( "§UserShortName§" ) = user
  dicRpl( "§UserFullName§" ) = objuser.fullname

Then I'd load this html template  file into a string sTxt and do a

  For Each sKey In dicRpl.Keys
       sTxt = Replace( sTxt, sKey, dicRpl( sKey ) )
  Next

and write sTxt to a .hta/html file. To deal with blocks of variable length
I'd concatenate strings generated by replacing placeholders in shorter
template blocks (let's say one table row) and replace a 'second level'
placeholder (e.g. §UserList§) in the full html template with this concatened
string.

Good luck!

ehvbs

(in reply to faulkkev)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> output as hta help Page: [1]
Jump to:





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
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts