Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need editing the HTA file

Posted on 2007-12-03
14
Medium Priority
?
1,023 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

722 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