-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateVNCFromEnummedHosts.vbs
130 lines (108 loc) · 4.1 KB
/
CreateVNCFromEnummedHosts.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
'Option Explicit
On Error Resume Next
Dim sComputerName, sInput, oWMIService, colComputers, colRunningServices, sArgument, oService,oFSO, oFile, aComputers, WshShell, curDir, wShell, file, filename
Set wShell = WScript.CreateObject("Shell.Application")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
'If no arguments are provided, run the script on the local computer.
'
If Wscript.Arguments.Count = 0 Then
sComputerName = "."
Call ServStat
Wscript.Quit
End If
sInput = lcase(Wscript.Arguments(0))
Select Case sInput
Case "file"
'BEGIN COMMENT LINE
'Give the INPUT_FILE_NAME constant a value and specify that you'll be reading the file.
Const INPUT_FILE_NAME = "Enumhosts.txt"
Const FOR_READING = 1
'BEGIN COMMENT LINE
'Create an object for the file.
Set oFSO = CreateObject("Scripting.FileSystemObject")
'BEGIN COMMENT LINE
'Open the file.
Set oFile = oFSO.OpenTextFile(INPUT_FILE_NAME, FOR_READING)
'BEGIN COMMENT LINE
'Read the file and assign its contents to the sComputerName variable.
sComputerName = oFile.ReadAll
'BEGIN COMMENT LINE
'Close the file.
oFile.Close
aComputers = Split(sComputerName, vbCrLf)
For Each sComputerName in aComputers
'WScript.Echo vcCrLf & "Results From"& vbTab & sComputerName & vbCrLf
Call ServStat
Next
Wscript.Quit
Case "all"
'Wscript.Echo "Script will check all computers running WMI."
'Set colComputers = GetObject(LDAP://CN=Computers, DC=labrynth, DC=com).
For Each oComputer in colComputers
sComputerName = oComputer.CN
Call ServStat
Next
Case "/?"
Wscript.Echo "Instructions"
Wscript.Echo "This script checks service status on the selected computer(s)"
Wscript.Echo "so long as they're running WMI."
Wscript.Echo "To check service status for all hosts in the Active Directory"
Wscript.Echo "type 'all'."
Wscript.Echo "To read server names from a file, type 'file'."
Wscript.Echo "To check status on the local computer provide no arguments."
Case Else
For Each sArgument in WScript.Arguments
sComputerName = sArgument
'WScript.Echo vcCrLf & "Results From"& vbTab & sComputerName & vbCrLf
Call ServStat
Next
End Select
Sub ServStat
'BEGIN COMMENT LINE
'Connect to the WMI service on the target computer.
Set oWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & sComputerName& "\root\cimv2")
'BEGIN COMMENT LINE
'Get a list of available services.
Set colRunningServices = oWMIService.ExecQuery _
("Select * from Win32_Service")
'BEGIN COMMENT LINE
'Run through the list and report the service's name and status.
For Each oService in colRunningServices
If InStr (oService.DisplayName, "Terminal") Then
If InStr (oService.State, "Running") Then
'Wscript.Echo sComputerName & ": " & oService.DisplayName & VbTab & oService.State
Set OutPutFile = FileSystem.OpenTextFile(sComputerName & ".vnc",2,True)
OutPutFile.WriteLine "[Connection]"
OutPutFile.WriteLine "Host=" & sComputerName
OutPutFile.WriteLine "[Options]"
OutPutFile.WriteLine "UseLocalCursor=1"
OutPutFile.WriteLine "UseDesktopResize=1"
OutPutFile.WriteLine "FullScreen=0"
OutPutFile.WriteLine "FullColour=0"
OutPutFile.WriteLine "LowColourLevel=1"
OutPutFile.WriteLine "PreferredEncoding=ZRLE"
OutPutFile.WriteLine "AutoSelect=1"
OutPutFile.WriteLine "Shared=0"
OutPutFile.WriteLine "SendPtrEvents=1"
OutPutFile.WriteLine "SendKeyEvents=1"
OutPutFile.WriteLine "SendCutText=1"
OutPutFile.WriteLine "AcceptCutText=1"
OutPutFile.WriteLine "DisableWinKeys=1"
OutPutFile.WriteLine "Emulate3=0"
OutPutFile.WriteLine "PointerEventInterval=0"
OutPutFile.WriteLine "Monitor="
OutPutFile.WriteLine "MenuKey=F8"
OutPutFile.WriteLine "AutoReconnect=1"
End If
End If
Next
End Sub
curDir = WshShell.CurrentDirectory
OutPutFile.Close
Set wShell = Nothing
Set WshShell = Nothing
Set FileSystem = Nothing
Set OutPutFile = Nothing
WScript.Quit(0)