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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding the PC a user is logged on to in a domain

Status
Not open for further replies.

milnet01

Programmer
Jun 26, 2009
4
0
0
ZA
thread329-462925

Hi guys, the below script, submitted by browolf, is exactly what I need but I can't get it to search for other users but my own. How do I get it to check other users:

<code>
on error resume next
'wscript.echo "Logging....."
const ForAppending = 8

dim net,fso,f

Set net = WScript.CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")
set wshell = wscript.createobject("wscript.shell")
Set WshSysEnv = WShell.Environment("SYSTEM")

'uname = net.username
uname = wshell.ExpandEnvironmentStrings("%USERNAME%")

'wscript.echo "! " & uname

datetemp = date
ttemp = time

cname = net.ComputerName
'cname = wshell.ExpandEnvironmentStrings("%COMPUTERNAME%")

'path1=list of ppl who have used computer cname
'path2=list of computers person uname has used
'path3=list of shortcuts install in startmenu

path1 = "\\server\logs\" & lcase(cname) & ".txt"
path2 = "\\server\logs\" & lcase(uname) & ".txt"
path3 = "\\server\logs\shortcuts\" & lcase(cname) & ".txt"

If (fso.FileExists(path3)) Then
fso.DeleteFile(path3)
end if

Set f1 = fso_OpenTextFile(path1, ForAppending, True)
Set f2 = fso_OpenTextFile(path2, ForAppending, True)

f1.writeline "was used by " & lcase(uname) & " on " & datetemp & " at " & ttemp
f2.writeline "used computer " & lcase(cname) & " on " & datetemp & " at " & ttemp

if WshSysEnv("OS")="" then
WShell.Run "%comspec% /c dir " & chr(34) & "c:\windows\start menu\*.lnk" & chr(34) & " /a-d /b /s >> " & path3 ,0,true
end if

f1.close
f2.close

wscript.echo "Logging Done"
</code>

This script also gives the current date and time, is there a way to check the last time used or time logged on.

Thanks
 
Easiest way to go about this is to use a logon script and have it modify the user description to log where they are currently logged on.

Another method is to query each PC via vbscript.


I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thanks Mark.

Unfortunately, both solutions won't help me here. Reason I can't query every PC is that I work in a large organisation where there are over 30 000 PC's.

I can't get a log in script to change eather as I am not a domain admin and a simple thing like that was rejected as it is deemed not necessary to implement in the organisation.

I can, however, query DC's to check for that info but not sure of the script to do that.

Basically, what I need is to know what PC / PC's a user is logged on to for costing purposes. It also has other uses like checking why a user is locked out excetera.

Thanks.
 
Start reviewing your security logs then.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thanks, you have just given me the perfect idea on how to proceed. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top