Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Networking Script

Status
Not open for further replies.

nateDiggs

IS-IT--Management
Jul 20, 2005
14
US
Hello--

I'm trying to write a windows 2000/XP script that will take a user's login name and resolve to the name of the computer the user is logged into. I've used many scripts that I've found that use net send and nbtstat -c commands to find computer names but I find them to be un-reilable. Is there anything out there that uses AD or Novell to do this? This would help my group out immensely. Thanks in advance for any help!
 
The COMPUTERNAME environment variable is not set ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
not sure, it doesn't really matter though. There are 10,000 computers in my company and I'm not counting on finding and changing the enviornment variables on computers that may not be setup correctly. Although, I don't think this is it because nbtstat won't cache my own computer name and I know that the enviornment variable is set. I'm looking for a DIFFERENT way to do this, not just improve the current way we are doing it.
 
nateDiggs,
not sure if this will help but found these 2 scripts awhile ago (i belive from markdmac thanks mark (^o^) you have a lot of helpful posts):
This script needs to run first.
Code:
'==========================================================================
'
' NAME: CreateWSList.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 3/18/2004
'
' COMMENT: <comment>
'
'==========================================================================

Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objDomain = getObject("LDAP://rootDSE")
Domain = objDomain.Get("defaultNamingContext")
LDPATH = Chr(39) & "LDAP://" & Domain & Chr(39)


Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
    "Select Name, Location from " & LDPATH _
        & "where objectClass='computer'"  
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    report = report & objRecordSet.Fields("Name").Value & vbCrLf
    objRecordSet.MoveNext
Loop


Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile ("wslist.txt", ForWriting)
ts.write report
ts.close
MsgBox "Done"
then this one:
Code:
'==========================================================================
'
' NAME: ReportLogonLocationsByPC.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 3/11/2004
'
' COMMENT: <comment>
'
'==========================================================================

On Error Resume Next

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

'open the data file
Set oTextStream = oFSO.OpenTextFile("wslist.txt")
'make an array from the data file
RemotePC = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close

Report = ""
For Each strComputer In RemotePC
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkConnection",,48)
    For Each objItem in colItems
       Report = Report & "UserName: " & objItem.UserName & "  is logged in at " & strComputer & vbCrLf
    Next
Next
Set ts = oFSO.CreateTextFile ("LogonLocationReport.txt", ForWriting)
ts.write Report
Set oTextStream = nothing
set ts = nothing
set oFSO = nothing
MsgBox "done"
i made 2 slight changes to the 2nd one, moved where the original Report = "" was in the code and added MsgBox "done".
I know the first one works because it created a good wslist in my environment. dont's know about the second one as it is still running. i think i'll see if i can change it a bit to see if i can get it working.
regards,
longhair
 
Thanks for recycling longhair.

nateDiggs the above script should do what you were asking. Main thing for you to remember is that your ID needs to have Admin rights on those machines that you list in the wslist file.

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top