Solved

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

Posted on 2009-07-08
3
912 Views
Last Modified: 2013-12-26
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
Comment
Question by:VNI-Joe
  • 2
3 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
Comment Utility
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
 

Author Closing Comment

by:VNI-Joe
Comment Utility
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
 
LVL 38

Expert Comment

by:Shift-3
Comment Utility
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

Featured Post

Why spend so long doing email signature updates?

Do you spend loads of your time carrying out email signature updates? Not very interesting are they? Don’t let signature updates get you down. Let Exclaimer Cloud - Signatures for Office 365 make managing email signatures a breeze.

Join & Write a Comment

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Know what services you can and cannot, should and should not combine on your server.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now