VBS Script to validate RDP Connection

I am working on a VBS script to confirm if RDP Connection is working on remote servers. I know some server administrators check it via Telnet on default RDP port 3389. But, it is not completely reliable. I need to open an RDP Connection to a server, capture
the result, if the connection is working or not, document the results on a text file and close the window just opened. My code follows below:
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("servers.txt", ForReading)
Set oFSO = CreateObject("Scripting.FilesyStemObject")
Outputfile="RDP.txt"
Set ofile = ofso.createTextFile(OutputFile, True)
ofile.writeline "computer" &vbtab& "Status"
Dim arrFileLines(), computer, pingable
i = 0
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
For Each computer in arrFileLines
Select Case RDPTest(computer)
Case "RDP is working"
wscript.echo computer &""& " RDP is working"
ofile.writeline computer &""& vbtab & " RDP is working"
Case "RDP is NOT working"
wscript.echo computer & " RDP is not working"
ofile.writeline computer &""& vbtab & " RDP is NOT working"
End Select
'WScript.Echo strLine
Next
Private Function RDPTest(ByVal strComputer)
Dim objShell, objExecObject, strText
Set objShell = CreateObject("Wscript.Shell")
Set wshShell = CreateObject("WScript.Shell")
Set objExecObject = wshShell.Exec("%comspec% /c mstsc /v:" & strComputer) 'Calls RDP Connection to the target server as per servers.txt list
ret = wshShell.AppActivate(strComputer & " - Remote Desktop") 'Check out if the RDP window is opened for the target server
If ret = True Then
RDPTest = "RDP is working" 'Confirms RDP is working
wshShell.SendKeys "%{F4}" 'Close up the RDP window
Else
RDPTest = "RDP is NOT working" 'Confirms RDP is not working
wshShell.SendKeys "%{F4}" 'Close up the RDP-error window
End If
Do While Not objExecObject.StdOut.AtEndOfStream
strText = strText & objExecObject.StdOut.ReadLine()
Loop
End Function
The part that calls a remote server and open RDP by the servername provided on the servers.txt list is working. The problem is with the part that confirms the RDP window opened and close it posting the results. I need help to fix it. As it is the code is not
recognizing the RDP window just opened by the script, it is not closing the window and not reporting the connections as working. I tested it by opening RDP manually to a server, then ran the script, and the window I opened before running the script was recongnized
by the script, but it was not closed.
I thank in advance any help on this question.

You cannot do it like that.
To test RPP use PortQry and check the returned string.  Use PowerShell.
foreach($computers in $computers){
    $results=PortQryV2 -n $computer -p tcp -e 3389
    # process results
That is all it takes.
http://www.microsoft.com/en-us/download/details.aspx?id=17148
¯\_(ツ)_/¯

Similar Messages

  • Script to check RDP connection status

    Hi all,
    Could anyone provide me a script to check whether multiple remote servers are able to RDP or not. I just want to check the connectivity status. I have checked with past threads available in form, but none has worked for me. Powershell or Batch or VBS scripts
    ... anything would be good....
    I am not that much good at writing scripts.. So please help me.
    Thanks in Advance..
    Vinay..

    Run this script on one of the servers:
    Get-Wmiobject -Class Win32_Terminal -Property *
    It should return a number of information including, fEnableTerminal. For servers that have RDP enabled, fEnableTerminal should be 1, for the servers with RDP not enabled, fEnableTerminal should be 0.
    Once you can confirm that this is the case, I will provide the full script to run this on multiple servers with input from AD query of text file
    That still won't tell you if the TS is accessible.  PortQry or Net Tcp are the fastest and easiest ways to do this.
    Your code also only orks on WS2008R2 and later but, s posted, ill not work on any system.  Have you actually tried it?
    The other bigger issue is that the Win32_Terminal class will always return enabled on any server even if the terminal server is inaccessible and even if it is in Admin mode.  All Servers since 2003 have Terminal Server running by default but not in
    Terminal Server mode.
    PortQry to 3389 will tell us that the TS is alive and available.  Win32_Terminal will report enabled even if the service is stopped.
    Win32_Terminal is only useful to admins and PortQry can be used by anyone.
    The above PowerShell code can be run on any system instead of installing PortQry or other software.
    The original question was "Check RDP connection".  RDP is available on all systems since XP.  The Win32_Terminal class is only available on Server class machines and it does not check to see if the RDP connection is available.
    ¯\_(ツ)_/¯

  • Server 2008 R2 RDP: limit max number of rdp connections per user group?

    Hello everyone,
    I have a Windows Server 2008 R2 with RDP installed.
    I want to create a couple of user groups which will have 5 different users in each. Then I would like to limit RDP connections, let's say 2 connections for the first group and 3 connections for the second group. For example, if 2 users from Group 1 are connected
    then when a 3rd user from Group 1 tries to connect it will be rejected to connect, but 3 users from Group 2 still can connect. Is it doable?
    Thanks in advance.

    Hi,
    I would like to check if you need further assistance.
    If you need help to create script, please post your questions in our related forums.
    http://social.technet.microsoft.com/Forums/scriptcenter/en-US/home
    Thanks.
    Jeremy Wu
    TechNet Community Support

  • VBS Script

    I'm running some VBS which connects to an ftp and pulls down files. It's running on a network location from an existing server and I'm now trying to run from a new server. 
    The VBS itself sits on a network drive, as well as the config file. 
    I've copied the VBS script and config file & renamed. I've amended within the VBS references to the config file.
    It runs fine, connects to the ftp site, and places items on the network directory. However it fails when placing on local directory. 
    It gives an error 
    Script: Z:\Folder\Subfolder\scriptname.vbs
    Line: 173
    Char:1
    Error: Path Not found
    Lines 171-173 are as follows.
    171  'delete and create local directory based on filename.
    172   if fso.FolderExists (strLocalDir & "\" & strTodayDateID) then fso.DeleteFolder (strLocalDir & "\" & strTodayDateID)
    173   fso.CreateFolder(strLocalDir & "\" & strTodayDateID)
    in the old/current config file it refers to local directory as follows. 
    #LocalDir:
    E:\foldername\download
    I've amended the new config file as follows
    #LocalDir:
    C:\foldername\download
    However I get the aforementioned error. 
    What am I missing ? 

    "Path not found" means just what it says. Since we don't have access to your network and we can't see your screen, there's not really a way we can troubleshoot it.
    -- Bill Stewart [Bill_Stewart]

  • Is it possible to read the contents of an Excel cell in DIAdem and assign its value to a variable in a VBS script.

    Hi All,
    Initially I thought this little problem would be relatively straight forward but now I’m not so sure. I am familiar with the mechanism by which DIAdem communicates with Excel and how to change the contents of a cell via a VBS script. In my task the contents of the cell in the first row, first column of MyProblem.xls contains the text “DIAdem”. I would like to be able to read this value and assign it to the variable MyString. I originally thought of doing something simple like this:
    Dim MyString
    Dim Excel, ExcelSheet
    Set Excel = CreateObject(“Excel.Application”)
    Excel.Workbooks.Open(“C\MyProblem.xls”)
    Set ExcelSheet = Excel.Workbooks(“MyProblem.xls”).Sheets(“Sheet1”)
    MyString = ExcelSheet.Cells(1,1)
    At this point I would have hoped that MyString would have been set equal to “DIAdem” and I could have used MyString to change the name of a channel in the data portal if I desired using the following code:
    Data.Root.ChannelGroups(1).Channels(1).Name = MyString
    Doesn’t seem to work though. I’m guessing it is because MyString has not picked up the value of the contents of the cell? Can anybody propose a solution to my problem or indeed confirm whether what I am proposing to do is technically feasible.
    Thanks in advance for any responses.
    Matthew

    Hi Matthew,
    Just staring at your ActiveX code, it looks fine to me.  My first thought is that this should work as you outlined it, and I've done this sort of thing many times, so I know it can work.  My second thought though, is that what you probably really want is a DataPlugin and not a VBScript.  Then you could just drag&drop the Excel file into the Data Portal and load all the properties and channels you want from the Excel file.  If you have DIAdem 2010 or later you can use the SpreadSheet reader object in the DataPlugin to avoid the Excel ActiveX functions (and Excel's jealously with other applications trying to read a file it has open already).
    Feel free to send me a few sample Excel files and describe what you want to load from the various cells, and I'd be happy to help you get a DataPlugin written to load your data.  You can also email me at [email protected]
    Brad Turpin
    DIAdem Product Support Engineer
    National Instruments

  • Prob & Solution: Unable to make RDP connection using newly added Microsoft Account to win10 tech preview hosted on AzureVM

    Problem description:
    After VM deployment is finished, remote desktop into the Windows 10 client OS with the created admin credentials
    Open PC Settings -> Users and Accounts -> manage other users (this is the new UX not the old classic add user dialog)
    Add a Microsoft account to the desktop, leave it as a standard user
    Log Out
    Make RDP connection using login of DNSName\[email protected]
    Note: DNSName = connection string you are using in RDP
    [email protected] is whatever liveID you are using.
    Problem: If it was working you will get a message that this user does not have access rights to remote desktop to the computer
    Error: Unknown user or bad password is what I would get
    Solution:
    Log back on as admin user with RDP
    Using the new UX from " PC Settings -> Users and Accounts -> "  delete the recently created microsoft account
    Create a local (not microsoft account) account where with the name that would be before the @ (i.e. user77)
    Go to the Old user management interface (either the computer management MMC or the "System Properties->Remote" tab and give the created local user remote desktop access rights.
    Now log off as admin
    Remote desktop and use username of DNSName\User77  (note no @outlook.com)
    Let the login process finish
    Make sure any feedback questions are answered
    Now navigate to the new UX using " PC Settings -> Users and Accounts -> " and link the local account with your Microsoft account.
    You will have to authorize the microsoft account, typically with a text message + verification code
    Wait 2 minutes (using a A1 size VM there seemed to be some background stuff for account linking)
    Log out
    Now log in using DNSName\[email protected]
    Success!
    I hope this helps anyone else who is using Azure VM's to test out Windows 10 client technical preview.
    -N
    neilgo

    Hi
    We use a custom imagine and experience this quite alot.  Usually host name is missing and we have to redeploy.
    Seems to have gotten worse as we add more vms.
    Should we not sysprep when capturing a vm?
    Orginal vm came from the gallary and we've simply resized os to 30gb.
    Main role for our vms is job processing so stop deallocate when finish to keep costs down buts prooving to be more trooblesome that expected due vms dieing.
    We have a number which we don't shut down which are problem free.  so I suspect the stop deallocate and self heal are still early days.
    My monitor has reported issues with 40+ vms this evening.  Are there issues or updates going on in western europe?

  • AD "Log on to" restriction causes RDP connections with network level authentication to fail

    I am running a Server 2008 R2 environment and have recently enabled network level authentication for RDP connections. Since the change, users who have their logons restricted to specific servers via AD, now get an error when logging on via RDP:
    An Authentication error has occured
    The Local security authority cannot be contacted
    After investigating this error and reading technet I found that removing the "log on to" restriction within their user object solved the problem even tho they had rights to this server. Adding the users client PC name to the "Log on
    to" list also solves this issue.
    My question is, is there another way around this? We have an environment where some users may require an RDP connection from a client PC not on the same domain (over VPN) as the server. It will not be practical to add many different client PC names
    to the log on to list and I don't understand why client PC's must be specified in the Log on to list and not just the actual server they are logging onto.
    Any pointers appreciated

    I have just come across this problem on one of my client’s domains; they have recently enforced a policy to “Allow connections only from computers running Remote Desktop with Network Level Authentication (more secure)”  and users with “Log on To” restrictions
    on their account are no longer able to RDP using their second account.
    After a lot of fiddling around I finally resolved the problem by adding the connecting computer name into “Log on To” list.  Ultimately it appears that Network Level Authentication (NLA) requires authentication to take place on both the host initiating
    the connection and the remote host.

  • Vbs script to manage aspect ratios in PowerPoint (16:9 vs. 4:3)

    Hello. Can someone help me with the following?
    I need a VBS script to make PowerPoint's default slide size to 16:9 from 4:3.
    Thank you for any help here.
    Jrene

    Hello. Can someone help me with the following?
    I need a VBS script to make PowerPoint's default slide size to 16:9 from 4:3.
    Try this Google query:
    PowerPoint aspect ratio vbscript

  • How to capture events from vbs script in java

    Hello all
    i have vbs script that executing some actions after its done running or after its fails the vbs script
    returns string , my question is how can i execute this script but also capture in java the returned string from the vbs script
    Thanks

    Hello
    nop im talking about java here is what i got untill now .. ( not working )
    for example say i have vbscript that do only that :
    myVbs.vbs :
    set WshShell = WScript.CreateObject("WScript.Shell")
    WScript.Echo "Hello World!" and i like to capture this "Hello World!" string in my java code how can it be done?
    this is my java code , but its does not working ..
    public class ExcVbs {
         public static void main(String args[]) throws InterruptedException{
              Process p = null;
              try {
                   p = Runtime.getRuntime().exec( "rundll32 url.dll,FileProtocolHandler myVbs.vbs" );
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              p.waitFor();
              OutputStream pus = p.getOutputStream();
              System.out.println(pus.toString());
              System.out.println( "Code=" + p.exitValue() );
    }

  • Can't establish RDP-Connection; 2 CALs available? 2008R2 RDS

    Hi,
    i encountered a suspect problem.
    We have a Windows Server 2008R2 with installed RDS-Role. For many years, we used a 5-User-CAL - no problems.
    No we got some new Users (8 in total), so we bought a separate 5-User-RDS-Cal (2012 R2, downgraded it to 2008 by phone).
    Actual, we have the problem, that only 6 Users can connect via RDP to the server. If the 7. tries to connect, the RDP-Connection can't be established; error (translated from german): "This computer cannot establish a connection to the remote computer".
    If i kick a user from the server, i can immediatly connect from my workstation.
    The RDS-Licensemanager is installed on the same system; it show's 2x5 CALs (correctly installed). If i run a report, it says:8 from 10 total licenses used - so we should have 2 free.
    Here's a screenshot from the report: ddlw.org/img/h5mrh1qv.jpg (sorry, can't insert pictures at this moment)
    The Best-practice-analyzer for RDS show's up no error, even in the the eventlog there are no RDS-relevant Errors/Warnings/Informations.
    Both CALs are definitly RDS-USER-Cals, and the RDS-Host is setup for User-Cals.
    Maybe, someone has a solution for our problem?

    Hi,
    On the server, please log on as an admin and open RD Session Host Configuration (tsconfig.msc).  Next double-click on RDP-Tcp.  On the Network Adapter tab, please make sure Unlimited Connections is selected.
    After making the above change please test to see if you are able to have all users log on at the same time.
    Thanks.
    -TP

  • Error in vbs script using HFMClient Object

    I would like to make a VBS script to logout all users from a HFM application but I get this error:
    "Hyperion.HFMErrorHandler.1: <?xml version="1.0"?>
    <EStr><Ref>{0B24FBEE-81B4-4649-A84B-D106DCF5BD85}</Ref><AppName/><User/><DBUpdat
    e>1</DBUpdate><ESec><Num>-2147023174</Num><Type>0</Type><DTime>7/3/2012 3:56:46
    PM</DTime><Svr>LVZH11-DB</Svr><File>CHFMCASSecurity.cpp</File><Line>89</Line><Ve
    r>11.1.2.1.000.3082</Ver></ESec><ESec><Num>-2147023174</Num><Type>0</Type><DTime>
    7/3/2012 3:56:46 PM</DTime><Svr>LVZH11-DB</Svr><File>CHsxServer.cpp</File><Line>
    3446</Line><Ver>11.1.2.1.000.3082</Ver></ESec><ESec><Num>-2147023174</Num><Type>
    0</Type><DTime>7/3/2012 3:56:46 PM</DTime><Svr>LVZH11-DB</Svr><File>CHsxClient.
    cpp</File><Line>4081</Line><Ver>11.1.2.1.000.3082</Ver></ESec></EStr>"
    the code I used is:
    Sub killUs
    Dim hfmCl
         Set hfmCl = CreateObject("Hyperion.HfmClient")
         hfmCl.KillUsers "Cluster Name", False, "Application Name", True, ""
    End Sub

    Why? This is not a javascript forum.
    In any case, run it in firefox which has decent Javascript error handling functionality, then do some Google searches on Javascript event handling to try and figure out what you're doing wrong. It might be something browser specific and I suggest you look into using something like JQuery for standardized and proven ways to do things like event handling logic in stead of rolling your own Javascript stuff.

  • Service stack update 2871777 to enable installation of RDP Connection Broker on 2012 domain controller - downloaded file will not execute.

    service stack update 2871777 to enable installation of RDP Connection Broker on 2012 domain controller - downloaded file will not execute.
    Downloaded x64 update for server 2012 R2 (KB2871777) -  file downloaded is named Windows8-RT-KB2871777-x64.msu
    When downloaded to server 2012 R2, upon launching the files, the message reads "Windows Update Standalone Installer"
    "The update is not applicable t your computer"
    If this is the wrong update please point me to the correct one - I cannot find another instance of this update anywhere.
    I am unable to remove the active directory from this server, so I need to use this fix if at all possible, in order to use RDP.
    I have tried every workaround I can find.  The goal is to have remote users access RDP to run a remote session and access apps and files
    on the server.  we have Hyper-V enabled and have successfully deployed 10 RDP licenses to the license server) also on the PDC.
    I read one post that suggested installing RD Connection Broker in one instance of a VM and AD DS in the other - not sure if that means we remove
    AD DS from physical server.  We only have one 2012 server (plus a server 2008 with Ad DS) and  a server 2003.  Trying to make this all work so we can deploy 10 remote desktop users.

    KB2871777 appears to be for 2012 (non R2) only.
     As to the other problem maybe this one helps.
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/bbf47aa2-8ae5-4f22-9827-afee5a11417a/install-remote-desktop-services-failed-on-windows-2012-server?forum=winserverTS
    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows]
    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

  • Installed Photoshop Elements 13.  Upon activation, get through sign in screen, but when doing serial number validation, validate goes round but does not validate.  Connect Later is only way out of screen.  How do I validate.  Checked account but product n

    How do one validate Photoshop 13. (Windows 8) Upon activation, get through to sign in screen, but when doing serial number validation, validate goes round but does not validate.  Connect Later is only way out of screen.  Checked account but product not listed.  Installed with serial number that was sent  by Adobe.  Have attempted numerous times at different times of the day.  On-line connection working.

    Have you bothered to do any research at all? Not every app was upgrade to 5.5. Those that weren’t will next be upgraded to CS6.
    Bob

  • VBS-Scripting: DATAFILEIMPORT (ASCII) only imports first 20 channels

    Hello,
    I've got some problems with the automated DataFileImport via VBS-Script. The command DATAFILEIMPORT works, but it only imports the first 20 channels that are present in the data-file. The remaining 30 channels are ignored. If I import the same data file with the menu-command 'open' in the File-Menu in DIAdem-Navigator all data is imported correctly. What is the problem here?
    I'm using DIAdem 9.01 Service Pack 1.
    This is the command I'm using:
    Call DATAFILEIMPORT("D:\Messdaten\August_04\12.08.2004\Ergebnisse\2004-08-12_16-00-00_19-00-00_10sec.txt","asciiFilter",False)
    Thanks in advance
    Stefan

    Hallo Stefan,
    Problem erkannt! Du hast die STP-Datei mit einer Datendatei erstallt, die 20 Kanäle hatte und versuchst diese STP-Datei auf eine Datendatei mit 46 Kanälen anzuwenden. Hier liegt das Problem, denn eine STP-Datei kann für mehrere Datendateien nur dann benutzt werden, wenn die Struktur dieser Dateien identisch ist dh. alle Dateien die gleiche Anzahl Kanäle haben. Das dass interaktiv funktioniert liegt an einer Defaultannahme, die für Kanäle getroffen wird - aber die muss natürlich nicht stimmen (interaktiv kann das ja noch korrigiert werden per Script aber nicht). Zu diesem Problem gibt es in DIAdem 9.0 keine andere Lösung als für jede unterschiedliche Datenstruktur einen STP-File zu erstellen. In DIAdem 9.1 haben wir mit den DataPlugins eine flexible Alternative geschaffen. Infos hierzu findest du auf www.ni.com/dataplugins.
    Gruß
    br>Walter

  • The Windows Installer does not permit installation from a RDP connection.

    Hello!
    Today when was installing Exchange 2013SP1 onto one of my virtual machines I got the following error:
    This error has suprised me in a lot of ways: 1) it was my 10th, or 20th or ... installation of Exchange on to the same test VM and this error has never arised before, 2) it's rather tardy error as Step1 and Step2 completed successfully in spite of
    "The Windows Installer does not permit installation from a RDP connection." 3) I was using
    Virtual machine connection - not RDP connection!
    Thank you in advance,
    Michael

    Hello!
    Today when was installing Exchange 2013SP1 onto one of my virtual machines I got the following error:
    This error has suprised me in a lot of ways: 1) it was my 10th, or 20th or ... installation of Exchange on to the same test VM and this error has never arised before, 2) it's rather tardy error as Step1 and Step2 completed successfully in spite of
    "The Windows Installer does not permit installation from a RDP connection." 3) I was using
    Virtual machine connection - not RDP connection!
    Thank you in advance,
    Michael
    It looks like the installation files are being shared over a terminal services connection (based on what you are saying, I'm guessing you're using Hyper-v and it's using TS to present the files).  I always run into mixed results when I run installs from
    a path not local to the server.  Can you copy the install paths locally and rerun setup?
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread

Maybe you are looking for