• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

A way to pop up a windows on each machine on log on and ask for information

Hi,
I want a way to popup a small windows which asks for user information
say
Name
Age
Computer name
etc
And all the information has to be saved to a excel sheet after the user enters the information on a remote machine
Is there a way to do this.

Regards
Sharath
0
bsharath
Asked:
bsharath
  • 7
  • 6
1 Solution
 
RobSampsonCommented:
Sharath,

You could put in a log in script that would ask for this information, but if this were to happen at every log in, wouldn't the user get fairly annoyed by this?  I have a script in my environment that logs their username, ip address, computer name, and time to a text file (not excel, because sharing that spreadsheet is troublesome), without any user interaction......would that suit?

Regards,

Rob.
0
 
bsharathAuthor Commented:
Yes i think that can be helpful...
0
 
RobSampsonCommented:
OK, have a go at this, there's a bit of instruction on what you can change listed at the top:
'==========
Option Explicit
'On Error Resume Next

Dim strServerShare, WSHShell, WSHProcess, strUserName, strHostName, strCommand

'==========================
'   There are three parameters that you can change in this script:
'   1. strServerShare            - which is the shared folder that will store your user's TXT log files.
'      2. The usernames and server names (strHostName's) in the line that will prohibit the recording
'         of the login details for those users and servers.
'      3. The IP Address subnets that match your environment.  This ensures that the script outputs
'         the correct LAN IP Address
'      4. intMaxLinesAllowed      - which limits the number of lines per user's text file. -1 for unlimited.
'==========================

' This is the shared folder that will store each user's text file
strServerShare = "\\NTFP\UserLogins$\"
If Right(strServerShare, 1) <> "\" Then strServerShare = strServerShare & "\"

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Set WSHShell = CreateObject("Wscript.Shell")
Set WSHProcess = WSHShell.Environment("Process")

strUserName = WSHProcess("USERNAME")
strHostName = WSHProcess("COMPUTERNAME")

' This will stop the recording from happening when users log in as Administrator, or on Citrix servers.
If LCase(strUserName) <> "administrator" And LCase(strUserName) <> "citrix_adm" And LCase(strHostName) <> "mccmf01" And LCase(strHostName) <> "mccmf02" And LCase(strHostName) <> "mccps01" And LCase(strHostName) <> "mccps02" Then

      Dim objShell, strComputer, objWMIService, colComputerIP, IPConfig, intIPCount, strIPAddress, strTheIPAddress
      Dim  objFSO, objFile, strOutputFile
      Dim strContents, arrLinesInFile, intLineCount, intMaxLinesAllowed
      
      strComputer = "."

      Set objFSO = CreateObject("Scripting.FileSystemObject")
      
      Set objShell = CreateObject("WScript.Shell")
      
      Set objWMIService = GetObject("winmgmts:" _
          & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
      
      Set colComputerIP = objWMIService.ExecQuery _
          ("Select * from Win32_NetworkAdapterConfiguration")
      
      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
      
      ' CHANGE THE BELOW SUBNETS TO MATCH YOUR IP SUBNET RANGES SO THE SCRIPT CAN OUTPUT THE CORRECT IP ADDRESS
      If InStr(strIPAddress, "172.16.2.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "172.16.2."), InStr(InStr(strIPAddress, "172.16.2."), strIPAddress, "~") - InStr(strIPAddress, "172.16.2."))
      ElseIf InStr(strIPAddress, "192.168.10.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.10."), InStr(InStr(strIPAddress, "192.168.10."), strIPAddress, "~") - InStr(strIPAddress, "192.168.10."))
      ElseIf InStr(strIPAddress, "192.168.100.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.100."), InStr(InStr(strIPAddress, "192.168.100."), strIPAddress, "~") - InStr(strIPAddress, "192.168.100."))
      ElseIf InStr(strIPAddress, "192.168.130.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.130."), InStr(InStr(strIPAddress, "192.168.130."), strIPAddress, "~") - InStr(strIPAddress, "192.168.130."))
      ElseIf InStr(strIPAddress, "192.168.140.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.140."), InStr(InStr(strIPAddress, "192.168.140."), strIPAddress, "~") - InStr(strIPAddress, "192.168.140."))
      ElseIf InStr(strIPAddress, "192.168.141.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.141."), InStr(InStr(strIPAddress, "192.168.141."), strIPAddress, "~") - InStr(strIPAddress, "192.168.141."))
      ElseIf InStr(strIPAddress, "192.168.142.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.142."), InStr(InStr(strIPAddress, "192.168.142."), strIPAddress, "~") - InStr(strIPAddress, "192.168.142."))
      ElseIf InStr(strIPAddress, "192.168.20.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.20."), InStr(InStr(strIPAddress, "192.168.20."), strIPAddress, "~") - InStr(strIPAddress, "192.168.20."))
      ElseIf InStr(strIPAddress, "192.168.30.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.30."), InStr(InStr(strIPAddress, "192.168.30."), strIPAddress, "~") - InStr(strIPAddress, "192.168.30."))
      ElseIf InStr(strIPAddress, "192.168.40.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.40."), InStr(InStr(strIPAddress, "192.168.40."), strIPAddress, "~") - InStr(strIPAddress, "192.168.40."))
      ElseIf InStr(strIPAddress, "192.168.50.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.50."), InStr(InStr(strIPAddress, "192.168.50."), strIPAddress, "~") - InStr(strIPAddress, "192.168.50."))
      ElseIf InStr(strIPAddress, "192.168.60.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.60."), InStr(InStr(strIPAddress, "192.168.60."), strIPAddress, "~") - InStr(strIPAddress, "192.168.60."))
      ElseIf InStr(strIPAddress, "192.168.70.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.70."), InStr(InStr(strIPAddress, "192.168.70."), strIPAddress, "~") - InStr(strIPAddress, "192.168.70."))
      ElseIf InStr(strIPAddress, "192.168.80.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.80."), InStr(InStr(strIPAddress, "192.168.80."), strIPAddress, "~") - InStr(strIPAddress, "192.168.80."))
      ElseIf InStr(strIPAddress, "192.168.90.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.90."), InStr(InStr(strIPAddress, "192.168.90."), strIPAddress, "~") - InStr(strIPAddress, "192.168.90."))
      ElseIf InStr(strIPAddress, "192.168.95.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.95."), InStr(InStr(strIPAddress, "192.168.95."), strIPAddress, "~") - InStr(strIPAddress, "192.168.95."))
      Else
            strTheIPAddress = "UNKNOWN"
      End If

      If Len(strTheIPAddress) > 1 And Right(strTheIPAddress, 1) = "~" Then
            strTheIPAddress = Left(strTheIPAddress, Len(strTheIPAddress) - 1)
      End If
            
      ' /////// Define the text file name as the name of the user //////////
      strOutputFile = strServerShare & strUserName & ".txt"
      
      On Error Resume Next
      
      '/////// Open the user's text file for reading first to be able to count the number of lines ///////
      Set objFile = objFSO.OpenTextFile (strOutputFile, ForReading, True)
      
      '////// Set this value to the maximum number of entries allowed per user's text file
      '////// Set this value to 0 or -1 to have unlimited lines
      intMaxLinesAllowed = -1
      
      strContents = ""
      If Not objFile.AtEndOfStream Then
            strContents = objFile.ReadAll
      End If

      If Len(strContents) > 0 Then
            arrLinesInFile = Split(strContents, vbCrLf)
            If intMaxLinesAllowed > 0 Then
                  If UBound(arrLinesInFile) > (intMaxLinesAllowed - 1) Then
                        strContents = ""
                        For intLineCount = 0 To (intMaxLinesAllowed - 2)
                              strContents = strContents & arrLinesInFile(intLineCount) & VbCrLf
                        Next
                        strContents = strContents & arrLinesInFile((intMaxLinesAllowed - 1))
                  End If
            End If
      End If
      
      Set objFile = objFSO.OpenTextFile (strOutputFile, ForWriting, True)
      objFile.Write(Pad_String(strTheIPAddress, 20, "Right", " ") & "|  " & Pad_String(strHostName, 24, "Right", " ") & "|  " & Now & VbCrLf & strContents)
 
      objFile.Close
      
      On Error Goto 0
      
Else
      'MsgBox "The login details will not be logged when an Administrator logs in."
End If

Function Pad_String(strOriginalString, intTotalLengthRequired, strPaddingSide, strCharacterToPadWith)
      If LCase(strPaddingSide) <> "left" And LCase(strPaddingSide) <> "right" Then
            strPaddingSide = "right"
      End If
      Select Case LCase(strPaddingSide)
            Case "left"
                  Pad_String = Right(String(intTotalLengthRequired, Left(strCharacterToPadWith, 1)) & strOriginalString, intTotalLengthRequired)
            Case "right"
                  Pad_String = Left(strOriginalString & String(intTotalLengthRequired, Left(strCharacterToPadWith, 1)), intTotalLengthRequired)
      End Select
End Function
'==========

Regards,

Rob.
0
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.

 
bsharathAuthor Commented:
Is this a vbs which i need to run on a GPO.

Where shoul;d i specify the machine names.

I just ran it on my machine and not data is being capture.
I have changed the share folder path in the script
0
 
RobSampsonCommented:
Yes, it would run as a login script in a GPO, and therefore no machine names need to be speicified. It is run by every user on every machine that the GPO is applied to.

For testing though, just keep running it manually on your machine.  What is should log a file to the strServerShare shared folder, called &username%.txt
There is no visual output from this script, as that is not desired in a login script.

Once the script has run, go to that share, and the text file should be there.

Regards,

Rob.
0
 
bsharathAuthor Commented:
I ran this script as test on my machine  but a txt file is not created in the shared folder.
0
 
RobSampsonCommented:
Sharath, OK try this version. I took out the On Error Resume Next and also made a check to see if the file exists first anyway.

This way, we'll get an error if it has trouble creating the file (just for testing)

'=============
Option Explicit
'On Error Resume Next

Dim strServerShare, WSHShell, WSHProcess, strUserName, strHostName, strCommand

'==========================
'   There are three parameters that you can change in this script:
'   1. strServerShare            - which is the shared folder that will store your user's TXT log files.
'      2. The usernames and server names (strHostName's) in the line that will prohibit the recording
'         of the login details for those users and servers.
'      3. The IP Address subnets that match your environment.  This ensures that the script outputs
'         the correct LAN IP Address
'      4. intMaxLinesAllowed      - which limits the number of lines per user's text file. -1 for unlimited.
'==========================

' This is the shared folder that will store each user's text file
strServerShare = "\\NTFP\UserLogins$\"
If Right(strServerShare, 1) <> "\" Then strServerShare = strServerShare & "\"

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Set WSHShell = CreateObject("Wscript.Shell")
Set WSHProcess = WSHShell.Environment("Process")

strUserName = WSHProcess("USERNAME")
strHostName = WSHProcess("COMPUTERNAME")

' This will stop the recording from happening when users log in as Administrator, or on Citrix servers.
If LCase(strUserName) <> "administrator" And LCase(strUserName) <> "citrix_adm" And LCase(strHostName) <> "mccmf01" And LCase(strHostName) <> "mccmf02" And LCase(strHostName) <> "mccps01" And LCase(strHostName) <> "mccps02" Then

      Dim objShell, strComputer, objWMIService, colComputerIP, IPConfig, intIPCount, strIPAddress, strTheIPAddress
      Dim  objFSO, objFile, strOutputFile
      Dim strContents, arrLinesInFile, intLineCount, intMaxLinesAllowed
      
      strComputer = "."

      Set objFSO = CreateObject("Scripting.FileSystemObject")
      
      Set objShell = CreateObject("WScript.Shell")
      
      Set objWMIService = GetObject("winmgmts:" _
          & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
      
      Set colComputerIP = objWMIService.ExecQuery _
          ("Select * from Win32_NetworkAdapterConfiguration")
      
      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
      
      ' CHANGE THE BELOW SUBNETS TO MATCH YOUR IP SUBNET RANGES SO THE SCRIPT CAN OUTPUT THE CORRECT IP ADDRESS
      If InStr(strIPAddress, "172.16.2.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "172.16.2."), InStr(InStr(strIPAddress, "172.16.2."), strIPAddress, "~") - InStr(strIPAddress, "172.16.2."))
      ElseIf InStr(strIPAddress, "192.168.10.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.10."), InStr(InStr(strIPAddress, "192.168.10."), strIPAddress, "~") - InStr(strIPAddress, "192.168.10."))
      ElseIf InStr(strIPAddress, "192.168.100.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.100."), InStr(InStr(strIPAddress, "192.168.100."), strIPAddress, "~") - InStr(strIPAddress, "192.168.100."))
      ElseIf InStr(strIPAddress, "192.168.130.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.130."), InStr(InStr(strIPAddress, "192.168.130."), strIPAddress, "~") - InStr(strIPAddress, "192.168.130."))
      ElseIf InStr(strIPAddress, "192.168.140.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.140."), InStr(InStr(strIPAddress, "192.168.140."), strIPAddress, "~") - InStr(strIPAddress, "192.168.140."))
      ElseIf InStr(strIPAddress, "192.168.141.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.141."), InStr(InStr(strIPAddress, "192.168.141."), strIPAddress, "~") - InStr(strIPAddress, "192.168.141."))
      ElseIf InStr(strIPAddress, "192.168.142.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.142."), InStr(InStr(strIPAddress, "192.168.142."), strIPAddress, "~") - InStr(strIPAddress, "192.168.142."))
      ElseIf InStr(strIPAddress, "192.168.20.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.20."), InStr(InStr(strIPAddress, "192.168.20."), strIPAddress, "~") - InStr(strIPAddress, "192.168.20."))
      ElseIf InStr(strIPAddress, "192.168.30.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.30."), InStr(InStr(strIPAddress, "192.168.30."), strIPAddress, "~") - InStr(strIPAddress, "192.168.30."))
      ElseIf InStr(strIPAddress, "192.168.40.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.40."), InStr(InStr(strIPAddress, "192.168.40."), strIPAddress, "~") - InStr(strIPAddress, "192.168.40."))
      ElseIf InStr(strIPAddress, "192.168.50.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.50."), InStr(InStr(strIPAddress, "192.168.50."), strIPAddress, "~") - InStr(strIPAddress, "192.168.50."))
      ElseIf InStr(strIPAddress, "192.168.60.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.60."), InStr(InStr(strIPAddress, "192.168.60."), strIPAddress, "~") - InStr(strIPAddress, "192.168.60."))
      ElseIf InStr(strIPAddress, "192.168.70.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.70."), InStr(InStr(strIPAddress, "192.168.70."), strIPAddress, "~") - InStr(strIPAddress, "192.168.70."))
      ElseIf InStr(strIPAddress, "192.168.80.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.80."), InStr(InStr(strIPAddress, "192.168.80."), strIPAddress, "~") - InStr(strIPAddress, "192.168.80."))
      ElseIf InStr(strIPAddress, "192.168.90.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.90."), InStr(InStr(strIPAddress, "192.168.90."), strIPAddress, "~") - InStr(strIPAddress, "192.168.90."))
      ElseIf InStr(strIPAddress, "192.168.95.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.95."), InStr(InStr(strIPAddress, "192.168.95."), strIPAddress, "~") - InStr(strIPAddress, "192.168.95."))
      Else
            strTheIPAddress = "UNKNOWN"
      End If

      If Len(strTheIPAddress) > 1 And Right(strTheIPAddress, 1) = "~" Then
            strTheIPAddress = Left(strTheIPAddress, Len(strTheIPAddress) - 1)
      End If
            
      ' /////// Define the text file name as the name of the user //////////
      strOutputFile = strServerShare & strUserName & ".txt"
      
      'On Error Resume Next
      
      '/////// Open the user's text file for reading first to be able to count the number of lines ///////
      If objFSO.FileExists(strOutputFile) = True Then
            Set objFile = objFSO.OpenTextFile (strOutputFile, ForReading, True)
            
            '////// Set this value to the maximum number of entries allowed per user's text file
            '////// Set this value to 0 or -1 to have unlimited lines
            intMaxLinesAllowed = -1
            
            strContents = ""
            If Not objFile.AtEndOfStream Then
                  strContents = objFile.ReadAll
            End If
      
            If Len(strContents) > 0 Then
                  arrLinesInFile = Split(strContents, vbCrLf)
                  If intMaxLinesAllowed > 0 Then
                        If UBound(arrLinesInFile) > (intMaxLinesAllowed - 1) Then
                              strContents = ""
                              For intLineCount = 0 To (intMaxLinesAllowed - 2)
                                    strContents = strContents & arrLinesInFile(intLineCount) & VbCrLf
                              Next
                              strContents = strContents & arrLinesInFile((intMaxLinesAllowed - 1))
                        End If
                  End If
            End If
      End If
      
      Set objFile = objFSO.OpenTextFile (strOutputFile, ForWriting, True)
      objFile.Write(Pad_String(strTheIPAddress, 20, "Right", " ") & "|  " & Pad_String(strHostName, 24, "Right", " ") & "|  " & Now & VbCrLf & strContents)
 
      objFile.Close
      
      'On Error Goto 0
      
Else
      'MsgBox "The login details will not be logged when an Administrator logs in."
End If

Function Pad_String(strOriginalString, intTotalLengthRequired, strPaddingSide, strCharacterToPadWith)
      If LCase(strPaddingSide) <> "left" And LCase(strPaddingSide) <> "right" Then
            strPaddingSide = "right"
      End If
      Select Case LCase(strPaddingSide)
            Case "left"
                  Pad_String = Right(String(intTotalLengthRequired, Left(strCharacterToPadWith, 1)) & strOriginalString, intTotalLengthRequired)
            Case "right"
                  Pad_String = Left(strOriginalString & String(intTotalLengthRequired, Left(strCharacterToPadWith, 1)), intTotalLengthRequired)
      End Select
End Function
'=============

Regards,

Rob.
0
 
bsharathAuthor Commented:
Rob .

I ran this script but still no file is created .When i run the vbs script i cannot see any process running.Can you give a box which says done after the process is over...
0
 
RobSampsonCommented:
Hi, try this.  I have added three MsgBox's, so when you have finished testing, you can just comment those out by placing an apostrophe in front of those lines.  One will display:
Attempting to write to file <<filepath>>

The other just says "Done" at the end.

If you don't get either of these, then is it possible that you have included your username or computer name as described by point 2 in the instructions, in which case it's not logging the details for you?

If that's the case, the third message box that I added will give you:
The login details will not be logged when an Administrator logs in.

'==============
Option Explicit
'On Error Resume Next

Dim strServerShare, WSHShell, WSHProcess, strUserName, strHostName, strCommand

'==========================
'   There are three parameters that you can change in this script:
'   1. strServerShare            - which is the shared folder that will store your user's TXT log files.
'      2. The usernames and server names (strHostName's) in the line that will prohibit the recording
'         of the login details for those users and servers.
'      3. The IP Address subnets that match your environment.  This ensures that the script outputs
'         the correct LAN IP Address
'      4. intMaxLinesAllowed      - which limits the number of lines per user's text file. -1 for unlimited.
'==========================

' This is the shared folder that will store each user's text file
strServerShare = "\\NTFP\UserLogins$\"
If Right(strServerShare, 1) <> "\" Then strServerShare = strServerShare & "\"

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Set WSHShell = CreateObject("Wscript.Shell")
Set WSHProcess = WSHShell.Environment("Process")

strUserName = WSHProcess("USERNAME")
strHostName = WSHProcess("COMPUTERNAME")

' This will stop the recording from happening when users log in as Administrator, or on Citrix servers.
If LCase(strUserName) <> "administrator" And LCase(strUserName) <> "citrix_adm" And LCase(strHostName) <> "mccmf01" And LCase(strHostName) <> "mccmf02" And LCase(strHostName) <> "mccps01" And LCase(strHostName) <> "mccps02" Then

      Dim objShell, strComputer, objWMIService, colComputerIP, IPConfig, intIPCount, strIPAddress, strTheIPAddress
      Dim  objFSO, objFile, strOutputFile
      Dim strContents, arrLinesInFile, intLineCount, intMaxLinesAllowed
      
      strComputer = "."

      Set objFSO = CreateObject("Scripting.FileSystemObject")
      
      Set objShell = CreateObject("WScript.Shell")
      
      Set objWMIService = GetObject("winmgmts:" _
          & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
      
      Set colComputerIP = objWMIService.ExecQuery _
          ("Select * from Win32_NetworkAdapterConfiguration")
      
      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
      
      ' CHANGE THE BELOW SUBNETS TO MATCH YOUR IP SUBNET RANGES SO THE SCRIPT CAN OUTPUT THE CORRECT IP ADDRESS
      If InStr(strIPAddress, "172.16.2.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "172.16.2."), InStr(InStr(strIPAddress, "172.16.2."), strIPAddress, "~") - InStr(strIPAddress, "172.16.2."))
      ElseIf InStr(strIPAddress, "192.168.10.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.10."), InStr(InStr(strIPAddress, "192.168.10."), strIPAddress, "~") - InStr(strIPAddress, "192.168.10."))
      ElseIf InStr(strIPAddress, "192.168.100.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.100."), InStr(InStr(strIPAddress, "192.168.100."), strIPAddress, "~") - InStr(strIPAddress, "192.168.100."))
      ElseIf InStr(strIPAddress, "192.168.130.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.130."), InStr(InStr(strIPAddress, "192.168.130."), strIPAddress, "~") - InStr(strIPAddress, "192.168.130."))
      ElseIf InStr(strIPAddress, "192.168.140.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.140."), InStr(InStr(strIPAddress, "192.168.140."), strIPAddress, "~") - InStr(strIPAddress, "192.168.140."))
      ElseIf InStr(strIPAddress, "192.168.141.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.141."), InStr(InStr(strIPAddress, "192.168.141."), strIPAddress, "~") - InStr(strIPAddress, "192.168.141."))
      ElseIf InStr(strIPAddress, "192.168.142.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.142."), InStr(InStr(strIPAddress, "192.168.142."), strIPAddress, "~") - InStr(strIPAddress, "192.168.142."))
      ElseIf InStr(strIPAddress, "192.168.20.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.20."), InStr(InStr(strIPAddress, "192.168.20."), strIPAddress, "~") - InStr(strIPAddress, "192.168.20."))
      ElseIf InStr(strIPAddress, "192.168.30.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.30."), InStr(InStr(strIPAddress, "192.168.30."), strIPAddress, "~") - InStr(strIPAddress, "192.168.30."))
      ElseIf InStr(strIPAddress, "192.168.40.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.40."), InStr(InStr(strIPAddress, "192.168.40."), strIPAddress, "~") - InStr(strIPAddress, "192.168.40."))
      ElseIf InStr(strIPAddress, "192.168.50.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.50."), InStr(InStr(strIPAddress, "192.168.50."), strIPAddress, "~") - InStr(strIPAddress, "192.168.50."))
      ElseIf InStr(strIPAddress, "192.168.60.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.60."), InStr(InStr(strIPAddress, "192.168.60."), strIPAddress, "~") - InStr(strIPAddress, "192.168.60."))
      ElseIf InStr(strIPAddress, "192.168.70.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.70."), InStr(InStr(strIPAddress, "192.168.70."), strIPAddress, "~") - InStr(strIPAddress, "192.168.70."))
      ElseIf InStr(strIPAddress, "192.168.80.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.80."), InStr(InStr(strIPAddress, "192.168.80."), strIPAddress, "~") - InStr(strIPAddress, "192.168.80."))
      ElseIf InStr(strIPAddress, "192.168.90.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.90."), InStr(InStr(strIPAddress, "192.168.90."), strIPAddress, "~") - InStr(strIPAddress, "192.168.90."))
      ElseIf InStr(strIPAddress, "192.168.95.") > 0 Then
            strTheIPAddress = Mid(strIPAddress, InStr(strIPAddress, "192.168.95."), InStr(InStr(strIPAddress, "192.168.95."), strIPAddress, "~") - InStr(strIPAddress, "192.168.95."))
      Else
            strTheIPAddress = "UNKNOWN"
      End If

      If Len(strTheIPAddress) > 1 And Right(strTheIPAddress, 1) = "~" Then
            strTheIPAddress = Left(strTheIPAddress, Len(strTheIPAddress) - 1)
      End If
            
      ' /////// Define the text file name as the name of the user //////////
      strOutputFile = strServerShare & strUserName & ".txt"
      
      'On Error Resume Next
      
      '/////// Open the user's text file for reading first to be able to count the number of lines ///////
      If objFSO.FileExists(strOutputFile) = True Then
            Set objFile = objFSO.OpenTextFile (strOutputFile, ForReading, True)
            
            '////// Set this value to the maximum number of entries allowed per user's text file
            '////// Set this value to 0 or -1 to have unlimited lines
            intMaxLinesAllowed = -1
            
            strContents = ""
            If Not objFile.AtEndOfStream Then
                  strContents = objFile.ReadAll
            End If
      
            If Len(strContents) > 0 Then
                  arrLinesInFile = Split(strContents, vbCrLf)
                  If intMaxLinesAllowed > 0 Then
                        If UBound(arrLinesInFile) > (intMaxLinesAllowed - 1) Then
                              strContents = ""
                              For intLineCount = 0 To (intMaxLinesAllowed - 2)
                                    strContents = strContents & arrLinesInFile(intLineCount) & VbCrLf
                              Next
                              strContents = strContents & arrLinesInFile((intMaxLinesAllowed - 1))
                        End If
                  End If
            End If
      End If
      
      MsgBox "Attempting to write to file:" & VbCrLf & strOutputFile & VbCrLf & VbCrLf & "Detail:" & VbCrLf & Pad_String(strTheIPAddress, 20, "Right", " ") & "|  " & Pad_String(strHostName, 24, "Right", " ") & "|  " & Now & VbCrLf & strContents
      Set objFile = objFSO.OpenTextFile (strOutputFile, ForWriting, True)
      objFile.Write Pad_String(strTheIPAddress, 20, "Right", " ") & "|  " & Pad_String(strHostName, 24, "Right", " ") & "|  " & Now & VbCrLf & strContents
 
      objFile.Close
      
      'On Error Goto 0
      MsgBox "Done"
      
Else
      MsgBox "The login details will not be logged when an Administrator logs in."
End If

Function Pad_String(strOriginalString, intTotalLengthRequired, strPaddingSide, strCharacterToPadWith)
      If LCase(strPaddingSide) <> "left" And LCase(strPaddingSide) <> "right" Then
            strPaddingSide = "right"
      End If
      Select Case LCase(strPaddingSide)
            Case "left"
                  Pad_String = Right(String(intTotalLengthRequired, Left(strCharacterToPadWith, 1)) & strOriginalString, intTotalLengthRequired)
            Case "right"
                  Pad_String = Left(strOriginalString & String(intTotalLengthRequired, Left(strCharacterToPadWith, 1)), intTotalLengthRequired)
      End Select
End Function
'==============

Regards,

Rob.
0
 
bsharathAuthor Commented:
Rob.

This is working great.Can you remove the boxes...Popups....
0
 
RobSampsonCommented:
OK, so why is it actually writing the file now? Did you find that out?

Also, just to remove the prompts, do a search for
MsgBox
then, at each line, decide if you want to show that box, and if not, put an apostrophe in front of it.
For example, to remove the following prompt:
MsgBox "Done"

just change it to
'MsgBox "Done"

which has the apostrophe in front of it.

Also, what script editor are you using?  Since you are using quite a few scripts now, you should look at using something like VBSEdit 3.3 from www.vbsedit.com to edit them.  It is great to structure the script, and shows the syntax highlighting and stuff, and you can easily identify a commented out line of code, because it is green.

Regards,

Rob.
0
 
bsharathAuthor Commented:
Rob

I dont use any editor thanks for the link i shall start using the editor.

I was running this from the administrator login sorry for that..Once i ran from a users login it worked fine...

0
 
RobSampsonCommented:
No problem.  You will find VBSEdit useful.  I cannot imagine trying to decipher a script in Notepad anymore, I couldn't do it!

Regards,

Rob.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now