Solved

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

Posted on 2009-07-08
3
921 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 24806214
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
ID: 31601197
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
ID: 24806412
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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Cause of ransomware attack 13 157
Time server on domain 3 62
Batch Script:  Password contain a > character 6 36
domain controller shut down question 6 57
If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

737 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