Submitted By: Satej Christanand Mirpagar

Enables RDP remote access on all the computers in a domain.

Visual Basic
Edit|Remove
<head>
<title>WMI Remote Control [ Using ADSI ] Beta1 </title>
<HTA:APPLICATION 
     APPLICATIONNAME="WMI Remote Control"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="normal"

>
</head>


<script language="VBScript">


'List all the domain computers:
'=======================================

Sub FillClassDropDown

'Note:Please change the domain name

strdomain = "Hello"
set colcomputers = getobject("WinNT://" &strdomain)
BasicTextbox.Value = strdomain
colcomputers.filter = Array("computer")
for each objcomputer in colcomputers 
Set objNewOption = document.createElement("OPTION")
objNewOption.Text = objcomputer.name
computers.options.Add(objNewOption)
Next
End Sub



'Ping test:
'===========

Sub PingTest
For Each objOption In computers.Options
If objOption.Selected = True Then
strcomputer = objOption.Text
set x = getobject("winmgmts:\\" &strcomputer &"\root\cimv2")
set y = x.execquery("select * from Win32_pingstatus where address = '"&strcomputer&"'")
for each z in y 
if z.statuscode = 0 then
DataArea.innerHTML = "<font color = 'green'><b>Ping test is successful</b></font>"
else
DataArea.innerHTML = "<font color = 'red'><b>System not responding to ping request</b></font>"
end if
Next
end if 
next
End Sub


'Remote desktop connection to the system:
'=======================================

Sub Remote
Const enable = 1
For Each objOption In computers.Options
      If objOption.Selected = True Then
      strcomputer = objOption.Text
Set objshell = CreateObject("Wscript.shell")
Set x = GetObject("winmgmts:\\" &strcomputer &"\root\cimv2")
strmessage = "A RDP session is made to the system..."


'Enabling Remote Desktop:
'========================

Set y = x.execquery("select * from win32_terminalservicesetting")

For Each z In y 

z.setsinglesession(enable)
returncode = z.setallowTSconnections(enable)

If returncode = 0 Then


'Making RDP session:
'===================

Set process = x.execquery("select * from win32_process where name = 'mstsc.exe' ")
If process.count = 0 Then
objshell.Run "mstsc.exe /v:" &strcomputer
End If 


'Sending a netsend message to the client:
'======================================

objShell.Run "net send " & strcomputer & " " &strmessage


Else

DataArea.innerHTML = "Remote desktop is not enabled"

End If 

Next

End if 

Next

End Sub


</script>

<body bgcolor = silver onLoad=FillClassDropDown>
<font color="black" size="3"><b>Computer</b></font>

<select name="Computers"></select>
<font color="black" size="3"><b>Domain</b></font>
<input type="text" name="BasicTextbox" size="30"><p>
<input onClick=PingTest type="submit" value="PingTest"></input>
<input onClick=Remote type="submit" value="Connect"></input>
<p><p>
<span id = "DataArea"></span>
</body>