Capture users login, computer name and variable

Hi all.  I am looking for a little script VBS that can write to a text file, the username and computer name of the logged in user as well as popping up a message box that asks a question and then adds this information to the file when pressing ok?  anyone have one?
stefanjocAsked:
Who is Participating?
 
TakedaTCommented:
Like this?
'On Error Resume Next
Const ForReading = 1, ForWriting = 2, ForAppending = 8

strComputer = "."
Set objShell = CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set objFSO = CreateObject("Scripting.FileSystemObject")

envUserName = objShell.ExpandEnvironmentStrings("%username%") : envCompName = objShell.ExpandEnvironmentStrings("%computername%")
strInput =  InputBox("Enter your popup here")
CreateLog
Sub CreateLog
	strLogFile = envUserName&".txt"
	If objFSO.FileExists(strLogFile) then
		Set objLogFile = objFSO.OpenTextFile(strLogFile,ForAppending)
	Else
		Set objLogFile = objFSO.CreateTextFile(strLogFile,True)
	End If
	objLogFile.WriteLine(envUserName&","&envCompName&","&strInput)
	objLogFile.Close
End Sub

Open in new window

0
 
dmarinenkoCommented:
Here is a login logoff script.  You may have to customize your own a little for what you want.
http://community.spiceworks.com/scripts/show/70-track-login-and-logout
0
 
Brent387Commented:
I tried this out and it worked. Make sure you save the file as .vbs and have the text file already created.
Const ForReading = 1
Const ForAppending = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("\\server\path\input.txt", ForReading)
objFile.Close

strInput = Inputbox("Input dialogue.")

Set WshNtwk = WScript.CreateObject("WScript.Network")
PropertyINfo = "User Input" & vbTab & "=  " & strInput & vbCrLf & _
"Computer Name" & vbTab & "=  " & WshNtwk.ComputerName  & vbCrLf & "User Name" _
  & vbTab & "=  " & WshNtwk.UserName   & vbCrLf

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set OFile = oFSO.OpenTextFile("\\server\path\info.txt", ForAppending)
oFile.WriteLine PropertyInfo
OFile.Close

Open in new window

0
 
stefanjocAuthor Commented:
Perfect many thanks.  Many thanks to all who contributed to this answer as always.  :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.