Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

VBScript for RDP with exception

Posted on 2011-10-25
10
Medium Priority
?
688 Views
Last Modified: 2012-05-12
Hi,

I looking for a vbscript for RDP which will work in this way:

1) double click on the script and it will ask for the hostname to connect and press ok.
2) once entered the hostname or IP it will check whether this hostname exist in this text file (this text file will be on the network with all the exceptional hostnames)
3) if it exists dont RDP with a msg
4) if does not exist connect using RDP.

Please help.
0
Comment
Question by:Dhiraj Mutha
  • 4
  • 4
  • 2
10 Comments
 
LVL 4

Expert Comment

by:gwickert
ID: 37022989
Hmmm can I first of all ask why you want this? I assume you want to do this so that people can't access certain servers/workstations via RDP?

If you want to only allow RDP access for users to certain computers, and exclude them access on others, it would be best to:
-Make a 'Restricted RDP Group' in Active Directory (assuming your using AD here..)
-Create a 'Local Users and Groups' Group Policy Preference that adds the previously created AD group to the local 'Remote Desktop Users' group on all PCs that have this policy applied.
-Scope this GPO to the computers that you want the restricted users to access.
-Done.

Then whenever you want a user to be able to access the whitelist machines, simply add them to the 'Restricted RDP Group' in AD, then they will in turn be a member of the 'Remote Desktop Users' group on all of the whitelist PCs which have the above GPO scoped to them.  The users will not be able to access any computers/servers that do not have this group in their local 'Remote Desktop Users' group via RDP.

Does that sound a little something like what you want to achieve?
0
 
LVL 14

Author Comment

by:Dhiraj Mutha
ID: 37023193
I dont want them to restrict the users in login, I just want them to know that they are not suppose to perform the task (mentioned in the comment) on that server due to some maintainance happening on the server.

I miss typed it...

3) if it exists RDP with a msg.
4) if does not exist connect using RDP.

and the msg will be in the same text file... In the below format


HOSTNAME|COMMENT
0
 
LVL 4

Expert Comment

by:gwickert
ID: 37023241
Hm OK...Well I'll step oiut of this one then, VBS is not one of my strong points, sorry I couldn't help.

Glen
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 65

Expert Comment

by:RobSampson
ID: 37028261
Hi, is something like this what you're after?

Regards,

Rob.
strMaintenanceServers = "\\server\share\ServersUnderMaintenance.txt"

strHostName = InputBox("Enter host name:", "Host name")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Set objServers = objFSO.OpenTextFile(strHostName, ForReading, False)
Set objMsgs = CreateObject("Scripting.Dictionary")
objMsgs.CompareMode = vbTextCompare
While Not objServers.AtEndOfStream
	strLine = Trim(objServers.ReadLine)
	If strLine <> "" Then
		If InStr(strLine, "|") > 0 Then
			strServer = Split(strLine, "|")(0)
			strMsg = Split(strLine, "|")(1)
			If objMsgs.Exists(strServer) = False Then objMsgs.Add strServer, strMsg
		End If
	End If
Wend
strServers = ";" & Replace(objServers.ReadAll, VbCrLf, ";") & ";"
objServers.Close

If objMsgs.Exists(strHostName) = True Then
	MsgBox "You cannot connect to " & strHostName & " at this time." & VbCrLf & objMsgs(strHostName)
Else
	Set objShell = CreateObject("WScript.Shell")
	objShell.Run "mstsc -v " & strHostName, 1, False
End If

Open in new window

0
 
LVL 14

Author Comment

by:Dhiraj Mutha
ID: 37028766
I am getting an error on Line 7 Char 1

Error: File not found.

I have a proper file under the the mentioed drive. The file is in this format.

Hostname|Comment
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 1000 total points
ID: 37028946
Oops, please change
Set objServers = objFSO.OpenTextFile(strHostName, ForReading, False)

to this
Set objServers = objFSO.OpenTextFile(strMaintenanceServers, ForReading, False)

Rob.
0
 
LVL 14

Author Comment

by:Dhiraj Mutha
ID: 37028972
Now getting an error on Line 20

Error: Input past end of file
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37028980
Sorry again....try this.

Rob.
strMaintenanceServers = "\\server\share\ServersUnderMaintenance.txt"

strHostName = InputBox("Enter host name:", "Host name")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Set objServers = objFSO.OpenTextFile(strMaintenanceServers, ForReading, False)
Set objMsgs = CreateObject("Scripting.Dictionary")
objMsgs.CompareMode = vbTextCompare
While Not objServers.AtEndOfStream
	strLine = Trim(objServers.ReadLine)
	If strLine <> "" Then
		If InStr(strLine, "|") > 0 Then
			strServer = Split(strLine, "|")(0)
			strMsg = Split(strLine, "|")(1)
			If objMsgs.Exists(strServer) = False Then objMsgs.Add strServer, strMsg
		End If
	End If
Wend
objServers.Close

If objMsgs.Exists(strHostName) = True Then
	MsgBox "You cannot connect to " & strHostName & " at this time." & VbCrLf & objMsgs(strHostName)
Else
	Set objShell = CreateObject("WScript.Shell")
	objShell.Run "mstsc -v " & strHostName, 1, False
End If

Open in new window

0
 
LVL 14

Author Closing Comment

by:Dhiraj Mutha
ID: 37028983
Rob you are Superb... as usual... a genius.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37028987
Thanks.

Thanks for the grade.

Rob.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
If you have done a reformat of your hard drive and proceeded to do a successful Windows XP installation, you may notice that a choice between two operating systems when you start up the machine. Here is how to get rid of this: Click Start Clic…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

580 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