Solved

Need editing the HTA file

Posted on 2007-12-03
14
1,016 Views
Last Modified: 2010-04-21
Hi,

I got this Hta file from EE.Need some editingThis script gets lots of details on the machine name entered.What i want is the HTA file asks for a file (txt) file that has many machinenames in it.So that it finds the logged in users and many details.

'==============
<head>
<title>Login Details of a Machine</title>
<HTA:APPLICATION
     APPLICATIONNAME="Login Details"
     BORDER="thin"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="normal"
>
</head>

<script language="VBScript">

Sub Window_onLoad
      Me.ResizeTo 400,300
    Me.MoveTo ((Screen.Width / 2) - 200),((Screen.Height / 2) - 150)
End Sub

Sub Default_Buttons
      If Window.Event.KeyCode = 13 Then
            btn_logindetails.Click
      End If
End Sub

Sub Get_Login_Details
   
      strComputer = txt_computer.value
     
      if strComputer = "" Then
            msgbox "Please enter a computer name or IP Address",vbOKOnly,"No Computer Name or IP Address"
            Exit Sub
      End If
     
      If Ping(strComputer) = False Then
        msgbox strComputer & " did not respond to ping. No action could be taken.",vbOkOnly, "Cannot continue script."
        Exit Sub
      End If      
     
      Set objWMIService = GetObject("winmgmts:" _
          & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
     
      Set colComputer = objWMIService.ExecQuery _
          ("Select * from Win32_ComputerSystem")
     
      Set colComputerIP = objWMIService.ExecQuery _
          ("Select * from Win32_NetworkAdapterConfiguration")
     
      Set colSystemInfo = objWMIService.ExecQuery _
          ("Select * from Win32_OperatingSystem",,48)
       
      For Each objComputer in colComputer
          strUserName = "User Name: " & objComputer.UserName
          strHostName = "Host Name: " & objComputer.Name
      Next
     
      For Each IPConfig in colComputerIP
            If Not IsNull(IPConfig.IPAddress) Then
              For intIPCount = LBound(IPConfig.IPAddress) _
                  to UBound(IPConfig.IPAddress)
                      strIPAddress = strIPAddress & "IP Address: " & IPConfig.IPAddress(intIPCount) & "~"
            next
            end if
      Next
     
      If Right(strIPAddress, 1) = "~" Then
            strIPAddress = Left(strIPAddress, Len(strIPAddress) - 1)
      End If
      strIPAddress = Replace(strIPAddress, "~", vbCrLf)
     
      For Each objItem in colSystemInfo
           strOS_Caption = "Caption: " & objItem.Caption
           strOS_SPVersion = "SP Version: " & objItem.CSDVersion
           strOS_VerNumber = "Version Number: " & objItem.Version
      Next
     
      MsgBox strUserName & vbcrlf & strHostName & vbcrlf & _
           strIPAddress & vbcrlf & strOS_Caption & vbcrlf & _
           strOS_SPVersion & vbcrlf & strOS_VerNumber, vbOKOnly, "Login Details"
   
End Sub

Function Ping(strComputer)
      Dim objShell, boolCode
      Set objShell = CreateObject("WScript.Shell")
      boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
      If boolCode = 0 Then
            Ping = True
      Else
            Ping = False
      End If
End Function

</script>

<body STYLE="font:14 pt arial; color:white;filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=1, StartColorStr='#000033', EndColorStr='#0000FF')" onkeypress='vbs:Default_Buttons'>
      <table width='80%' height = '100%' align='center' border='0'>
            <tr height='20%'>
                  <td>
                  </td>
            </tr>
            <tr height='10%'>
                  <td align='center'>
                        Computer name or IP Address:
                  </td>
            </tr
            <tr height='20%'>
                  <td align='center'>
                        <input type="text" value="172.16.2.48" name="txt_computer" maxlength='15' size='16'>
                  </td>
            </tr>
            <tr height='30%'>
                  <td align='center'>
                        <input type="button" value="Check Machine" name="btn_logindetails"  onClick="Get_Login_Details">
                  </td>
            </tr>
            <tr height='20%'>
                  <td>
                  </td>
            </tr>

      </table>

</body>
'==============

I have many other ways to find the details but need editiing this script only as this fetches details realy fast and without any supporing tools.

Regards
Sharath
0
Comment
Question by:bsharath
  • 7
  • 7
14 Comments
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20404081
I think it would be better if it is a vbscript rather than HTA for multiple machines

regards
Chandru
0
 
LVL 11

Author Comment

by:bsharath
ID: 20404191
Chandru if a vbs can do the same thing fast enough as the HTA and with all the details i have no problem.
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20404353
HTA is just an user interface and vbs code is integrated in it. So vbs should do the work much faster
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 11

Author Comment

by:bsharath
ID: 20404382
ok done...
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20404676
Try this script........... for the whole domain and all machines


regards
Chandru
On error resume next
 
Const ADS_SCOPE_SUBTREE = 2
 
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
 
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
    "Select Name, Location from 'LDAP://DC=DOMAIN,DC=local' " _
        & "Where objectClass='computer'"  
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
 
Do Until objRecordSet.EOF
    
    ' Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
    strComputer = objRecordSet.Fields("Name").Value
    
    Set objShell = CreateObject("WScript.Shell")
    strCommand = "%comspec% /c ping -n 3 -w 1000 " & strComputer & ""
    Set objExecObject = objShell.Exec(strCommand)
 
'clears echo replies left in strText from the previous loop
strText=""
 
 
Do While Not objExecObject.StdOut.AtEndOfStream
        strText = objExecObject.StdOut.ReadAll()
        If Instr(strText, "Reply") > 0 Then
 
 
            Set objWMIService = GetObject _
                ("winmgmts:\\" & strComputer & "\root\cimv2")
 	    Set colItems = objWMIService.ExecQuery _
                ("Select * From Win32_OperatingSystem")  
	    Set colItems2 = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
           ' Wscript.Echo Err.Description
	    Set colItems3 = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
	    Set colItems4 = objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)
 
	    For Each objItem in ColItems
                strOS = objItem.Caption
	    Next
		
	    For Each objItem in colItems2
		strDellTag = objItem.SerialNumber
		strManu = objItem.Manufacturer
	    Next
 
	    For Each objItem in colitems3
	        strUserName = objItem.Username
		strModel = objItem.Model
		strRAM = objItem.TotalPhysicalMemory
		strTimeZone = (objItem.CurrentTimeZone / 60)
		strDayLightSavings = objItem.DaylightInEffect
	    Next
	
	    For Each objItem in colitems4
		strProcessor = objItem.Name
            Next
		
		If Err.Number > 0 then
		  strErrorSystems =  strComputer & ", " & strErrorSystems 
		else
		  Wscript.Echo "-------------------------------------------------------------"
		  Wscript.Echo "Computer Name: " & strComputer & ", " & strUserName
		  Wscript.Echo "-------------------------------------------------------------"
	          Wscript.Echo "Operating System: " & strOS 
                  Wscript.Echo "Current User: " & strUserName
		  Wscript.Echo "::::"
		  WScript.Echo "Manufacturer: " & strManu
		  Wscript.Echo "Model: " & strModel
		  Wscript.Echo "Dell Service Tag: " & strDellTag
		  Wscript.Echo "Processor type: " & strProcessor
		  Wscript.Echo "RAM: " & strRAM
		  Wscript.Echo "Time Zone: " & strTimeZone
		  Wscript.Echo "Daylight Savings in effect: " & strDayLIghtSavings
		  Wscript.Echo "-------------------------------------------------------------"
 
		end if
		
			    
	    'flushes error code from the previous loop
	    Err.Clear
	    
		
            ' 
 
        Else
            '
	     UnavailableSystems =  strComputer & ", " & UnavailableSystems
 
	   End If
    Loop
 
	  
    objRecordSet.MoveNext
Loop
 
Wscript.Echo "The following systems were unavailable: " & UnavailableSystems 
Wscript.Echo " "
Wscript.Echo "The following systems were on, but returned an error: " & strErrorSystems 

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 20409322
I dont know what's happening with this script.Its running from 4 hrs.a command window flashes and goes and the wscript process is running since then.
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20409442
It is for the whole domain. It will take time to complete.

Does it output the results or the results is empty?

regards
Chandru
0
 
LVL 11

Author Comment

by:bsharath
ID: 20409454
There is no file created and just now stopped the process.For 3000 machines will it take 4 hrs?
Can you make the script to get data for 1 machines as testing...
0
 
LVL 12

Accepted Solution

by:
chandru_sol earned 500 total points
ID: 20409899
Try this,

Change the OU=Computerss to suit your needs. Try and do it an OU with less computers

regards
chandru
On error resume next
 
Const ADS_SCOPE_SUBTREE = 2
 
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
 
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
    "Select Name, Location from 'LDAP://OU=Computers,DC=DOMAIN,DC=local' " _
        & "Where objectClass='computer'"  
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
 
Do Until objRecordSet.EOF
    
    ' Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
    strComputer = objRecordSet.Fields("Name").Value
    
    Set objShell = CreateObject("WScript.Shell")
    strCommand = "%comspec% /c ping -n 3 -w 1000 " & strComputer & ""
    Set objExecObject = objShell.Exec(strCommand)
 
'clears echo replies left in strText from the previous loop
strText=""
 
 
Do While Not objExecObject.StdOut.AtEndOfStream
        strText = objExecObject.StdOut.ReadAll()
        If Instr(strText, "Reply") > 0 Then
 
 
            Set objWMIService = GetObject _
                ("winmgmts:\\" & strComputer & "\root\cimv2")
 	    Set colItems = objWMIService.ExecQuery _
                ("Select * From Win32_OperatingSystem")  
	    Set colItems2 = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
           ' Wscript.Echo Err.Description
	    Set colItems3 = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
	    Set colItems4 = objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)
 
	    For Each objItem in ColItems
                strOS = objItem.Caption
	    Next
		
	    For Each objItem in colItems2
		strDellTag = objItem.SerialNumber
		strManu = objItem.Manufacturer
	    Next
 
	    For Each objItem in colitems3
	        strUserName = objItem.Username
		strModel = objItem.Model
		strRAM = objItem.TotalPhysicalMemory
		strTimeZone = (objItem.CurrentTimeZone / 60)
		strDayLightSavings = objItem.DaylightInEffect
	    Next
	
	    For Each objItem in colitems4
		strProcessor = objItem.Name
            Next
		
		If Err.Number > 0 then
		  strErrorSystems =  strComputer & ", " & strErrorSystems 
		else
		  Wscript.Echo "-------------------------------------------------------------"
		  Wscript.Echo "Computer Name: " & strComputer & ", " & strUserName
		  Wscript.Echo "-------------------------------------------------------------"
	          Wscript.Echo "Operating System: " & strOS 
                  Wscript.Echo "Current User: " & strUserName
		  Wscript.Echo "::::"
		  WScript.Echo "Manufacturer: " & strManu
		  Wscript.Echo "Model: " & strModel
		  Wscript.Echo "Dell Service Tag: " & strDellTag
		  Wscript.Echo "Processor type: " & strProcessor
		  Wscript.Echo "RAM: " & strRAM
		  Wscript.Echo "Time Zone: " & strTimeZone
		  Wscript.Echo "Daylight Savings in effect: " & strDayLIghtSavings
		  Wscript.Echo "-------------------------------------------------------------"
 
		end if
		
			    
	    'flushes error code from the previous loop
	    Err.Clear
	    
		
            ' 
 
        Else
            '
	     UnavailableSystems =  strComputer & ", " & UnavailableSystems
 
	   End If
    Loop
 
	  
    objRecordSet.MoveNext
Loop
 
Wscript.Echo "The following systems were unavailable: " & UnavailableSystems 
Wscript.Echo " "
Wscript.Echo "The following systems were on, but returned an error: " & strErrorSystems    

Open in new window

0
 
LVL 11

Author Closing Comment

by:bsharath
ID: 31412358
Thanks a lot Chandru...Excellen job.... :-)
0
 
LVL 11

Author Comment

by:bsharath
ID: 20409983
Chandru i would be interested on the first script as well.Can you tell me if there is some thing i need to change as that scans all machines in the Domain no matter which OU they are.
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20409993
Can i know the reason why as this script solves the purpose?
0
 
LVL 11

Author Comment

by:bsharath
ID: 20410010
We have different OU's and i need to change it once each time one OU is finished.If it is too difficult never mind...
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20410068
No nothing is difficult. I think we have the option to select OU from a list file. let me check
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mapAB Challlenge 35 146
Do Psexec queries install files on remote computers 6 64
Control Number of Log Files -Perl 7 74
Excel file not created as expected 7 72
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question