kevin_lane Posted May 8, 2007 Posted May 8, 2007 How do i get a some ones login user name for when they have logged on i need to get it using either vb or php any ideas ? :?
altecsole Posted May 8, 2007 Posted May 8, 2007 I wrote a couple of vbscripts that we set to run at logon and logoff. Basically they write a logon entry to a mySQL database when users logon, and then delete it when they logoff. It's then pretty simple to check who's logged on and where. I can post the scripts if anyone's interested?
NetworkGeezer Posted May 8, 2007 Posted May 8, 2007 @Kevin It depends what you want to do. This what Plexer and Matt were hinting at: set WshShell = WScript.CreateObject("WScript.Shell") WScript.Echo "I am " & WshShell.ExpandEnvironmentStrings("%USERNAME%") Alternatively if you talking about doing this remotely then you have to delve into WMI or just used psloggedon (from PSTools) with an appropriate grep filter.
wesleyw Posted May 8, 2007 Posted May 8, 2007 @altecsole : Could be interesting to see how you've done that? Wes
mac_shinobi Posted May 8, 2007 Posted May 8, 2007 I wrote a couple of vbscripts that we set to run at logon and logoff. Basically they write a logon entry to a mySQL database when users logon, and then delete it when they logoff. It's then pretty simple to check who's logged on and where. I can post the scripts if anyone's interested? maybe a dumb question here but if you delete it after they log off then how do you check whose logged on if its deleted ie if you check the database after they have logged off and hence its been deleted ?
kingswood Posted May 8, 2007 Posted May 8, 2007 I wrote a couple of vbscripts that we set to run at logon and logoff. Basically they write a logon entry to a mySQL database when users logon, and then delete it when they logoff. It's then pretty simple to check who's logged on and where. I can post the scripts if anyone's interested? maybe a dumb question here but if you delete it after they log off then how do you check whose logged on if its deleted ie if you check the database after they have logged off and hence its been deleted ? Hey Shane. I suppose because it's really about checking who is logged on and where, rather than *who was* logged on and where. :?: Paul
kevin_lane Posted May 9, 2007 Author Posted May 9, 2007 Hi thanks for the reply. I was thinking more along the lines of if they go to our web server to do an internet survey. ( which i hate doing) it would just fill in their names e.g like what you get on xp start menu. I was thinking that if i get this to work to use some sort of data base so that it would know if they have alrdy filled in the survey and just pass them on to our local intranet
limbo Posted May 9, 2007 Posted May 9, 2007 I know this is real easy in asp so it must be just as easy in php. This is a list of server variables you can request (which includes the username). http://www.w3schools.com/asp/coll_servervariables.asp This page is biased towards asp so this page looks like it show how to incoprorate it into php http://www.developerfusion.co.uk/show/3703/5/ the LOGON_USER variable is probably most appropriate if it is going to be for machines on your network. You will probably have to disable anonomous login on the file / folder in question so that it makes sure it fetches the page.
DSapseid Posted June 6, 2007 Posted June 6, 2007 I have now been asked to do this. However they want it to write to a central database rather than one per machine!! Is this possible??
strawberry Posted June 6, 2007 Posted June 6, 2007 Quick and dirty: echo %username%>c:\name.txt do you know how to do this for time and machine name too?
Geoff Posted June 6, 2007 Posted June 6, 2007 Time: Time /T > time.txt Machine name: echo %COMPUTERNAME% > pcname.txt
DSapseid Posted June 6, 2007 Posted June 6, 2007 Quick and dirty: echo %username%>c:\name.txt do you know how to do this for time and machine name too? just been playing and can get it to do this by putting the below in a bach file all i need to do is get it to write to a database echo %username% %computername% %date% %time%>c:\test.txt
DSapseid Posted June 6, 2007 Posted June 6, 2007 one thing i have just found with this is that it wont add to the text file it jsut keeps overwritting what is already there.
mattx Posted June 6, 2007 Posted June 6, 2007 AutoIT script which may help: ; AutoIt Version: 3.10 ; Language: English ; Platform: WinXP ; Author: Matt Marsh ; Script Function: Script that records logon details in log file ; Date: Oct 2005 Dim $sLogPath = "c:\logs\logger.txt" Dim $sLogMsg = "User: " _FileWriteLog($sLogPath, $sLogMsg) Func _FileWriteLog($sLogPath, $sLogMsg) Local $sDateNow Local $sTimeNow Local $sMsg Local $hOpenFile Local $hWriteFile Local $user Local $cname Local $ip $sDateNow = "On " & @YEAR & "-" & @MON & "-" & @MDAY $sTimeNow = @HOUR & ":" & @MIN & ":" & @SEC $user = @UserName $cname = @ComputerName $ip = @IPAddress1 $sMsg = $sDateNow & " " & $sTimeNow & " : " & $sLogMsg & $user & " Logged On To PC: " & $cname & "," & " IP Address: " & $ip $hOpenFile = FileOpen($sLogPath, 1) If $hOpenFile = -1 Then SetError(1) Return 0 EndIf $hWriteFile = FileWriteLine($hOpenFile, $sMsg) If $hWriteFile = -1 Then SetError(2) Return 0 EndIf FileClose($hOpenFile) Return 1 EndFunc Make a dir and file - c:\logs\logger.txt Everytime this is run - [ you will need to compile it ], it will add a line to the txt file. This will record details for a local PC only.
djm968 Posted June 6, 2007 Posted June 6, 2007 VB would be something like this. Set objNetwork = CreateObject("Wscript.Network") strUser = objNetwork.UserDomain & Chr(92) & objNetwork.UserName Which would give you domain\username or strUser = objNetwork.UserName Which would give you just the username
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now