• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 948
  • Last Modified:

Batch file or vb script that logs remote desktop client start and stop times

Hello,
I would like to create a vb script or batch file that starts a remote desktop connection and logs the start and stop times for the connection to a log file.
Thanks,
Joe
0
VNI-Joe
Asked:
VNI-Joe
  • 2
1 Solution
 
Shift-3Commented:
Paste the script below into a text file with a .vbs extension.  Customize the value of the strHost variable on line 4 with the name or IP of the computer to connect to.  Customize the value of the strReport variable on line 5 with the location of the log file to create.

Running the script will log the date and time to the file, start a Remote Desktop connection, then write the date and time to the file when the connection is closed.


Const ForAppending = 8
Const TriStateUseDefault = -2
 
strHost = "server01"
strReport = "c:\files\log.txt"
 
On Error Resume Next
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objReport = objFSO.OpenTextFile(strReport, ForAppending, True, TriStateUseDefault)
objReport.WriteLine "Connection opened: " & Now
 
Set objShell = CreateObject("WScript.Shell")
objShell.Run "mstsc /v:" & strHost, 1, True
 
objReport.WriteLine "Connection closed: " & Now
objReport.WriteBlankLines(1)
objReport.Close

Open in new window

0
 
VNI-JoeAuthor Commented:
Thank you, Shift-3. Solution looks great. I hadn't asked for this in the original question but how would I use a drop down list to assign value to variable "strHost". I would like this to run from a .HTA. I've been tinkering with it since I posted the original question but haven't been able to pass the value of the selected item in drop-down list to the "strHost" variable.
Thanks again!
Joe
0
 
Shift-3Commented:
The HTA Helpomatic provides listbox examples.

If you need further help, please use the ask a related question link and provide a detailed description of what you'd like the .hta to do.
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

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