Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1595
  • Last Modified:

how to make a vbscript to find users logged into network??

i am trying to make a vbscript that i can run and the results i am looking for are users currently logged into the network and what machine they are logged onto and if possible a date and time and i also want the results saved to a file.  All help is greatly appreciated.
0
amoos
Asked:
amoos
  • 7
  • 5
1 Solution
 
Chris BottomleyCommented:
Hello amoos,

As a strter for 10, check out the following and see what you think:

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_24079828.html?sfQueryTermInfo=1+chri+log+pc+sharath

Regards,
Chris
0
 
amoosAuthor Commented:
chris

that sounds great and is what i need help accomplishing.  but do i need to make an excel sheet for the script to reference??  if so what do the columns need to be??  will this script return an popup window with the info or is it strickly saved to a file??  awwesome link thank you.
0
 
Chris BottomleyCommented:
That script requires a workbook to pre-exist, the macro sits therein.

As is it has all the machines logged iin column Q to establish the logged in user it then does some additional processing to record how many machines a user is logged into.  For your purposes the likliehood is that the first part is all you want.

If so and it's acceptable i'll work on it in the morning, do you want to shrink the columns to just the two for example a list of the machines that you will populate in column Q or A if you prefer and for the script to populate column B for example with the logged in user for the machine?

ANy more specific requests ought to be viable, but it does require that you define the machines to be searched.

Chris
0
Independent Software Vendors: 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!

 
amoosAuthor Commented:
chris

below is a script that i found on the net that does some what of what i need.  please let me know what you think.  what do you think i could add to it to make it come up with more info like maybe a time stamp and to save the output to a file.  great help thank you

On Error Resume Next
' Scheduled Tasks usage:
'  %comspec% /c cscript //nologo c:\path\script.vbs > c:\output.txt
 
' enter the DN of the container you want to base your search in
' leave blank to search the entire domain
strContainer = "" 
 
Set objRootDSE = GetObject("LDAP://rootDSE")
 
If strContainer = "" Then
  strADsPath = objRootDSE.Get("defaultNamingContext")
Else
  strADsPath = strContainer & "," & objRootDSE.Get("defaultNamingContext")
End If
 
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
 
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
 
 
 
objCommand.CommandText = _
  "<LDAP://" & strADsPath & ">;" & _
    "(objectCategory=computer)" & _
    ";distinguishedName,name;subtree"
 
Set objRecordSet = objCommand.Execute
 
While Not objRecordSet.EOF
 
  LoggedOn objRecordSet.Fields("Name")
  objRecordSet.MoveNext
 
Wend
 
objConnection.Close
 
 
Sub LoggedOn(strComputer)
 
  Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
  Set colComputer = objWMIService.ExecQuery _
      ("Select * from Win32_ComputerSystem")
 
  For Each objComputer in colComputer
    Wscript.Echo "Computer: " & strComputer & vbCrLf _
                 & "Logged-on user: " & objComputer.UserName _
                 & vbCrLf & " "
  Next
 
End Sub
0
 
Chris BottomleyCommented:
I'll check it out in the morning, output to a text file ok?

Chris
0
 
amoosAuthor Commented:
awesome.  thanks chris for the help.  yes output to a text file is great.  also i know this might be too much to ask but could you see if there is a way to add a time stamp or see the time they are logged in??

just to let you know i am working on making a script like this that will allow you to choose a computer and then see who is currently logged into it.  if you have any ideas on how to do this please let me know.  again thanks for all you help, it is greatly appreciated
0
 
amoosAuthor Commented:
chris

below is some things i would like to put into the script to allow a user to enter in a computer name or a username and see who is logged into the computer.  please let me know what you think.  obviously the code below is wrong for what i need but it is something to start with.  thanks for all your help

'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set WSHSHell = wscript.createObject("wscript.shell")

Dim sNewCname      'Variable to Hold Computer Name you enter in the inputbox
Dim sOldCname            'computers current name

'First param is message text, second is message title
sOldCname = InputBox("Please Enter The Current Name of The PC", "The Campus Computer Rename Script")
sNewCname = InputBox("Please Enter The PCs New Name", "The Campus Computer Rename Script")
0
 
Chris BottomleyCommented:
At the present I haven't been able to get anywhere largely because i'm now away from the office so na access to a network.

I will do some more invest in the meantime and look again next week if that's ok.  Although with a bit of luck someone'll look in before then and give an answer.

Chris
0
 
amoosAuthor Commented:
chris

no problem.  also i included some more code below that i am working on that works for one computer but not all.  let me know what you think on this to please.

ComputerName = InputBox("Enter the name of the computer you wish to query")

winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//"& ComputerName &""

Set UserSet = GetObject( winmgmt1 ).InstancesOf ("Win32_ComputerSystem")

for each User in UserSet
      MsgBox "The user name for the specified computer is: " & User.UserName
Next
0
 
amoosAuthor Commented:
chris

check this out.  i got it for the computer.  now if i could just get it for searching by username that would be awesome.  tell me what you think.

'Asks to start the backup
X=MsgBox("Are You Ready To Find Out Who Is On A Computer ? Todays Date Is " & Date & " ?",36," Person Finder")
If X = 6 Then 'If MsgBox is answered YES
 X=MsgBox("You Can Enter In A IP Address Or Computer Name ",48,"Person Finder")
Else
 WScript.Quit 'If MsgBox is answered NO
End If
ComputerName = InputBox("Enter the name of the computer you wish to query", "Find That User")

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & ComputerName & "\root\cimv2")

Set colComputer = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
 
For Each objComputer in colComputer
    MsgBox "The User Name For The Person Logged Into The Specified Computer Is: " & objComputer.UserName
Next

0
 
Chris BottomleyCommented:
APologies ... I thought I had posted a response but it seems I failed to upload.

I have searched a lot in the last few days to try and find a way to query the network for a user but they all come back to querying the machines for the user and picking it up that way.  I would expect there is a way to do as you want but I'm not up to it.

The initial post I made merely searches each known pc and then establishes the users in each case.  It does not search directly for the user as you know and i'm afraid i'll have to cry off this question due to my inability to be of any use.

Apologies
Chris
0
 
amoosAuthor Commented:
chris no problem you have been a great help and i appreciate all your help.  thanks again.  please if you come up with anything in the future that relates to this please post it.

thanks
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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