Solved

Need editing the HTA file

Posted on 2007-12-03
14
1,011 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
 
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Wallpaper not updating when file is swapped out 6 52
Convert MSI to MSM 1 49
ICACL switch help. How to include current folder 2 36
Excel file not created as expected 7 48
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

914 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now