Question : Problem: Creating UltraVNC .vnc connection files automatically using a script, sql database etc

I have been looking for a solution for our school system for UltraVNC.  We have been using UltraVNC for a long time now and lately we have changed our computer naming scheme to fix naming problems.  Instead of our old name scheme where we would do  (SchoolName-room#-Comp#)  we have now changed it to (SchoolName-ServiceTag) and are using the computer description as our location information etc.

This has become a hassle and I have been looking for a nice VNC Console that is free to import all of the computers so that teachers that have labs of 30 dont have to type in ex. LHSS-0011X1X to connect to computer #1 and so on, and instead just click on LHSS-000-01 and are directly connected to LHSS-0011X1X.

UVNC has come out with a UltraVNC DirectX app that holds vnc file favorites which is what i want, but it uses .vnc files which contain the code below (Code# 1) and uses the file name LHSS-000-01.vnc to display the computer name in the favorites list in UltraVNC DirectX.

I am wanting a script of some kind that can generate these .vnc files for each computer or workstation. I can export a list of computer names and there descriptions out of Active Directory to use but I am not a programmer at all to create a script in PHP, VBS, etc.

I do have experience in MySQL or MSSQL and very very little in PHP.

Is there a way of doing this if so how, or does anyone know of a very nice free program which does this better without any scripting.

If this above is unclear please comment.

I have also attached a vnc file.
Code Snippet:
1:
2:
3:
4:
(Code# 1)
            [connection]
            host=LHSS-0011X1X
            port=5900
Open in New Window Select All

Answer : Problem: Creating UltraVNC .vnc connection files automatically using a script, sql database etc

Hi MightyElectro,

Ok I have modified things a bit..

I thought rather than reading the AD into the array then writing it out I would just get the script to create the input file and then use the old script to create the folders and files.

So in a nutshell

  • Script queries the AD and finds every machine 
  • Script writes out the machine followed by a comma and then the OU the machine is in 
  • The old script reads this file in and then creates a folder for each OU and then dumps VNC config files in 

This does mean that you could REM out the second section and edit the file if needs be..

This shoudl be able to be scheduled somewhere and then when new machines are added to the domain they shoudl appear in the list.

The only thing that you might want to look out for is the crude way that I get the OU.. using the Split function.. It should get the correct values for your domain but just check it..

If you have any problems then post back.. I think it is waht you wanted but if you want a little more modification then give me a shout...

Dont forget to run it with a users that has the correct permissions to the input files and the AD...!

Cheers!

PS It is not my neatest work but managed to whip this one out before going home..! Fingers crossed!

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:
Option Explicit
 
'----------------------------------- Script Description ----------------------
'This script takes an input file and writes out in another folder
'a file vnc conenction file for each of the machines in the text file
'-----------------------------------------------------------------------------
 
Dim InputFile, OutputFolder, InputDescriptionFile
Dim oFSO, oInputFile, MachineName, sNextLine
Dim OutputFile, oOutputFile, x, TempSplit
Dim oRootDSE, strDNC, objDomain, objMember
Dim CN, ADSPath, UB, OU
 
'--------------------- Constants ----------------------
Const FailIfNotExist   =  0
Const OverwriteIfExist = -1
Const OpenAsDefault    = -2
Const CreateIfNotExist = -1
Const OpenAsASCII   = 0
Const OpenAsUnicode = -1
Const ForReading   = 1
Const ForWriting = 2
Const ForAppending = 8
'--------------------- END Constants --------------------
 
'--------------------- Variables -------------------------
        InputFile = "E:\Scripts and Utilities\Generate VNC files\vnchosts\hosts.txt" ' This is the file containing the machine names, one on each line..
		OutputFolder = "E:\Scripts and Utilities\Generate VNC files\vncfiles\" 'This the folder to output the vnc connection files to. Make sure you trial with a slash - "\"
'--------------------- END Variables -------------------------
'-------------------- MAIN PROCEDURE--------------------------
	Set oRootDSE = GetObject("LDAP://RootDSE")
	strDNC = oRootDSE.Get("defaultNamingContext")
	Set oFSO = CreateObject("Scripting.FileSystemObject")
	Set oInputFile = oFSO.OpenTextFile(InputFile, ForWriting, CreateIfNotExist, OpenAsASCII) ' Open the Input File
		GetListAD(strDNC) 
		CreateTheFiles()
 '-------------------- MAIN PROCEDURE END -------------------------- 
 
Function CreateTheFiles()
Set oFSO = CreateObject("Scripting.FileSystemObject")
 
Set oInputFile = oFSO.OpenTextFile(InputFile, ForReading) ' Open the Input File
x = 0
Do Until oInputFile.AtEndOfStream 'Read each line in
    sNextLine = oInputFile.Readline
   
    TempSplit = Split(sNextLine,",")
    	MachineName = TempSplit(0) ' Each line is equal to a machine name
    	OutputFile = TempSplit(1) ' Each line is equal to a machine name
		If Not oFSO.FolderExists(OutputFolder & OutputFile) Then 	
			oFSO.CreateFolder(OutputFolder & OutputFile)
		End If
    	OutputFile = OutputFolder & OutputFile & "\" & MachineName & ".vnc" ' Create the Output File, from the Output folder and the machine name
    	Set oOutputFile = oFSO.OpenTextFile(OutputFile, ForWriting, CreateIfNotExist)
        	oOutputFile.WriteLine("[connection]")
        	oOutputFile.WriteLine("host=" & MachineName)
        	oOutputFile.WriteLine("port=" & "5900")
        	oOutputFile.Close ' Clean up
        	MachineName = Null ' Clean up
   
        x = x + 1
Loop ' Repeat until end of stream...
End Function
 
Function GetListAD(strDNC)
	Set objDomain = GetObject("LDAP://" & strDNC) ' Bind to the top of the Domain using LDAP using RootDSE 
'	WScript.Echo "Connected to: " & strDNC
	x = 0
	Call enummembers(objDomain)
	oInputFile.Close
End Function
 
Sub enumMembers(objDomain)
	For Each objMember In objDomain 
		If ObjMember.Class = "computer" Then
			x = x + 1 
			Cn = ObjMember.CN
			ADSPath = ObjMember.ADSPath	
			ADSPath = Split(ADSPath,",")
			UB = (UBound(ADSPath) - 2)
			OU = Split(ADSPath(UB),"=")
			'WScript.Echo Cn & "," & OU(1)
			oInputFile.WriteLine Cn & "," & OU(1) 
		End If 
  
  		' If the AD enumeration runs into an OU object, call the Sub again to itinerate 
  
  		If objMember.Class = "organizationalUnit" Or OBjMember.Class = "container" Then 
      		enumMembers (objMember) 
  		End If 
  	Next
End Sub
Open in New Window Select All
Random Solutions  
 
programming4us programming4us