Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-07-08
3
Medium Priority
?
926 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 2000 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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…
Suggested Courses

730 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