Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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

971 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