VB Script to check on Remote Desktop

Greetings,
I have a list of IP addresses and i would like to check if any of those IPs have the remote desktop service enabled. Currently i'm doing the check manually by inserting one by one into the remote desktop connection windows. could anyone help me to Script this process.

Thanks
HAKSAAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rajvjaCommented:
0
Malli BoppeCommented:
telnet servername 3389  You should get a black screen.You can test that for each and every server.
0
HAKSAAuthor Commented:
Thanks mboppe for the advice. How can i incorporate your idea into a VBS where i provide a list of IP addresses and i get back a list of the IPs along with thier RDC status weather enable or not.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Malli BoppeCommented:
I don't know if its can be scripted.This what i tried but just stops at the 1st server.Servers.txt should have a list of serversnames

for /f %%a in   (c:\servers.txt) do (

telnet %%a 3389


)
0
jostranderCommented:
Do you have admin privileges on all the hosts?  If so, read on...

You could use a script to check Win32_TerminalServiceSetting.  This method doesn't seem to work too well on Win7/Vista though.

Another method is to check the registry on the hosts.  Here's a script that I made for checking the registry on hosts specified in C:\servers.txt.  Tested on Win2K,XP,Vista and Win7.
ON ERROR RESUME NEXT

'Force CSCRIPT
Set WshShell=CreateObject("Wscript.Shell")
If instr(lcase(wscript.fullname),"wscript") then
	wshshell.run "cmd /k cscript //nologo " & chr(34) & wscript.scriptfullname & Chr(34),1,false
	wscript.quit
End If


Const HKEY_LOCAL_MACHINE 	= &H80000002

strFilename="c:\servers.txt"

Set fso=CreateObject("Scripting.FileSystemObject")

'Verify server list file exists
If NOT fso.FileExists(strFilename) then
	msgbox "Could not find file:  " & strFilename,vbExclamation,"Remote Desktop Check"
	wscript.quit
End If

'Read the server file
Set oFile=fso.OpenTextFile(strFilename,1)
text = oFile.ReadAll
oFile.Close

arrComputers = split(text,vbCrLf)

For Each strComputer in arrComputers
	
	status=""

	status=GetVal(strComputer,"fDenyTSConnections")
	
	If status="UNKNOWN" then
		status=GetVal(strComputer,"TSEnabled")
	End If
	
	wscript.echo strComputer & "=" & status

Next


Function GetVal(strComputer,strValueName)
	ON ERROR RESUME NEXT

	strKeyPath = "SYSTEM\CurrentControlSet\Control\Terminal Server"
	
	Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 
	strComputer & "\root\default:StdRegProv")

	If err.number <> 0 then 
		strValue=err.number
		err.clear
	Else
		oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
		If err.number <> 0 then 
			strValue=err.number
			err.clear
		End If
	End If
	
	IF strValueName="fDenyTSConnections" then
		If strValue="0" then
			strValue="1"
		ElseIf strValue="1" then 
			strValue="0"
		End If
	End If
	
	
	Select Case strValue
		Case "1"
			GetVal="Enabled"
		Case "0"
			GetVal="Disabled"
		Case "462"
			GetVal="UNAVAILABLE"
		Case "-2147217405"
			GetVal="ACCESS DENIED"
		Case Else
			GetVal="UNKNOWN"
	End Select
	
End Function

Open in new window

0
jostranderCommented:
Otherwise, if you're not opposed to using a free MS tool in addition to the script...

Download:
http://www.microsoft.com/downloads/details.aspx?FamilyID=89811747-C74B-4638-A2D5-AC828BDC6983&displaylang=en

Save/Extract PortQry.exe into:
c:\PortQryV2\PortQry.exe


ON ERROR RESUME NEXT
'Joe Ostrander
'03.31.2010
'Requires Free MS Tool:  PortQry
'http://www.microsoft.com/downloads/details.aspx?FamilyID=89811747-C74B-4638-A2D5-AC828BDC6983&displaylang=en


'Force CSCRIPT
Set WshShell=CreateObject("Wscript.Shell")
If instr(lcase(wscript.fullname),"wscript") then
	wshshell.run "cmd /k cscript //nologo " & chr(34) & wscript.scriptfullname & Chr(34),1,false
	wscript.quit
End If

Dim strPortQryEXE
Dim strFileName
Dim strPort
Dim strDelimiter

'------------------------------------
'	User Variables
'------------------------------------
strWindowTitle="Port Check"
strPortQryEXE="c:\PortQryV2\PortQry.exe"
strFilename="c:\servers.txt"
strLogFileName="c:\ports.txt"
strPort = 3389
strDelimiter = vbTab
'------------------------------------

Set fso=CreateObject("Scripting.FileSystemObject")

'Verify server list file exists
If NOT fso.FileExists(strFilename) then
	msgbox "Could not find file:  " & strFilename,vbExclamation,strWindowTitle
	wscript.quit
End If

'Verify portqry exists
If NOT fso.FileExists(strPortQryEXE) then
	msgbox "Could not find file:  " & strPortQryEXE,vbExclamation,strWindowTitle
	wscript.quit
End If

'create the logfile
Set LogFile=fso.OpenTextFile(strLogFileName,2,true)

'Read the server file
Set oFile=fso.OpenTextFile(strFilename,1)
text = oFile.ReadAll
oFile.Close

arrComputers = split(text,vbCrLf)

For Each strComputer in arrComputers
	
	CheckPort strComputer,strPort,"TCP"

Next


'Close the logfile
LogFile.close


Sub CheckPort(myHost,myPort,myProtocol)
	ON ERROR RESUME NEXT

	strCMD=Chr(34) & strPortQryEXE & Chr(34) & " -n " & myHost & " -e " & myPort & " -p " & myProtocol
	
	Set oExec=WshShell.Exec(strCMD)
	
	status="UNKNOWN"
	resolvedTo=""
	
	Do While Not oExec.StdOut.AtEndOfStream
		count=count+1
		line=oExec.StdOut.ReadLine
		
		posA=instr(line,"IP address resolved to")
		If posA>0 then resolvedTo=mid(line,posA+1)
		
		posB=instr(line,"Name resolved to")
		If posB>0 then resolvedTo=mid(line,posB+1)		
		
		If instr(line,"NOT LISTENING") then
			status="DISABLED"
		End If
		
		If instr(line,": LISTENING") then
			status="ENABLED"
		End If

	Loop

	wscript.echo myHost & strDelimiter & myPort & strDelimiter & myProtocol & strDelimiter & status
	LogFile.WriteLine myHost & strDelimiter & myPort & strDelimiter & myProtocol & strDelimiter & status

End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HAKSAAuthor Commented:
This is what i was looking for. Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.