BryanMorrow

VB.NET - Silently install Windows based robots

Discussion created by BryanMorrow on Mar 15, 2011
Latest reply on Apr 1, 2011 by BryanMorrow

I have been working on a VB script that can remotely deploy Windows based robots. This script is the first thing I have ever written in VB and as I am also a neophyte programmer I thought I would paste it here for improvement suggestions. I will walk through the steps and provide the install files I use, the input text file and the .vb file itself.

 

Download the installation directory, input text file, psexec and the executable.

Remote_Robot_Deploy.zip

 

 

  1. Grab the needed information from a Comma-Separated file (controller.cfg information, username, password)
  2. Create the controller.cfg file
  3. Net use into the machine with information from the input file (I know there is better ways but this was easier than the other options for me)
  4. Copy the 'Nimsoft' directory included to C:\Program Files (x86)\Nimsoft on the remote machine (Again, this could be a variable from the input file or a GUI could be created but this is version 1)
  5. Use PSEXEC to run the /bin/nimbus.exe -install command (-remove uninstalls since no ADD/REMOVE Program entry)
  6. request.cfg calls for the robot_update (5.11 is the version being installed)
Notes:
I am not installing the VC redistributables yet in the script so this is a flaw.
Also, it seems the HDB and Spooler may not start right after the initial install but after the robot_update to 5.23 they came online for me.
More packages could be added to request.cfg
The install.log was more to test my command strings, not actual logging yet
Things I would like to add:
Better authentication
VC Redistributable Installation if needed
Error handling (haven't figured this one out yet)
Actual logging
**GUI
**Hub installation option
**Request.cfg additions
---Code from Module1.vb below---
Imports System Imports System.IO Imports System.Diagnostics Imports System.Runtime.InteropServices Imports System.Security.Principal Imports System.Security.Permissions  Module Module1      Sub Main()         WriteRobotCfg()     End Sub      Private Sub WriteRobotCfg()          Dim strRobotIp As String         Dim strRobotName As String         Dim strHubIp As String         Dim strFirstPort As String         Dim strDomain As String         Dim strHub As String         Dim strHubName As String         Dim strHubPort As String         Dim strSystemUser As String         Dim strSystemDomain As String         Dim strSystemPass As String         Dim readFile As StreamReader          Using Writer As StreamWriter = New StreamWriter("D:\fileCopy\Nimsoft\robot\robot.cfg")              readFile = New StreamReader("d:\fileCopy\server_list.txt")              While Not readFile.EndOfStream                  Dim Content As String = readFile.ReadLine()                  If Content.StartsWith("#") Then                      Console.WriteLine()                 Else                      Using writeFile As StreamWriter = New StreamWriter("D:\fileCopy\install.log")                          Dim split As String() = Content.Split(New [Char]() {","})                         strRobotIp = split(0)                         strRobotName = split(1)                         strHubIp = split(2)                         strFirstPort = split(3)                         strDomain = split(4)                         strHub = split(5)                         strHubName = split(6)                         strHubPort = split(7)                         strSystemUser = split(8)                         strSystemDomain = split(9)                         strSystemPass = split(10)                          Writer.WriteLine("<setup>")                         Writer.WriteLine("   service_user = ")                         Writer.WriteLine("   service_passwd = ")                         Writer.WriteLine("</setup>")                         Writer.WriteLine("<controller>")                         Writer.WriteLine("   robotip = " & strRobotIp)                         Writer.WriteLine("   robotname = " & strRobotName)                         Writer.WriteLine("   hubip = " & strHubIp)                         Writer.WriteLine("   first_probe_port = " & strFirstPort)                         Writer.WriteLine("   domain = " & strDomain)                         Writer.WriteLine("   hub = " & strHub)                         Writer.WriteLine("   hubrobotname = " & strHubName)                         Writer.WriteLine("   hubport = " & strHubPort)                         Writer.WriteLine("   access_0 = 0")                         Writer.WriteLine("   access_1 = 1")                         Writer.WriteLine("   access_2 = 2")                         Writer.WriteLine("   access_3 = 3")                         Writer.WriteLine("   access_4 = 4")                         Writer.WriteLine("   secondary_domain = ")                         Writer.WriteLine("   secondary_hub = ")                         Writer.WriteLine("   secondary_hubrobotname = ")                         Writer.WriteLine("   secondary_hubip = ")                         Writer.WriteLine("   secondary_hubport = ")                         Writer.WriteLine("   secondary_hub_dns_name = ")                         Writer.WriteLine("   robotip_alias = ")                         Writer.WriteLine("   secondary_robotip_alias = same")                         Writer.WriteLine("   loglevel = 0")                         Writer.WriteLine("   logsize = 100")                         Writer.WriteLine("   autoremove = yes")                         Writer.WriteLine("   suspend_on_loopback_only = yes")                         Writer.WriteLine("   config_locking = no")                         Writer.WriteLine("   hub_update_interval = 900")                         Writer.WriteLine("   temporary_hub_broadcast = yes")                         Writer.WriteLine("   system_uptime_qos = no")                         Writer.WriteLine("   set_qos_source = no")                         Writer.WriteLine("   unmanaged_security = domain_locked")                         Writer.WriteLine("   alarm_level_comfail_restart = ")                         Writer.WriteLine("   alarm_level_dispatch_error = major")                         Writer.WriteLine("   alarm_level_max_restarts = major")                         Writer.WriteLine("   alarm_level_start_error = major")                         Writer.WriteLine("   alarm_level_timed_not_finished = warning")                         Writer.WriteLine("   alarm_level_unregister = major")                         Writer.WriteLine("   alarm_level_request_error = major")                         Writer.WriteLine("   alarm_level_timed_error_return = warning")                         Writer.WriteLine("   alarm_level_postinstall = no alarm")                         Writer.WriteLine("   robot_mode = normal")                         Writer.WriteLine("</controller>")                          Dim strDomainUser As String = strSystemDomain & "\" & strSystemUser                          Dim strYourCommand As String                         Dim strDelete As String                         strDelete = "net use " & strRobotName & " /delete"                         strYourCommand = "net use \\" & strRobotName & "\c$ /user:" & strDomainUser & " """ & strSystemPass & """"                         Shell(strDelete, vbHide)                         Shell("cmd /c " & strYourCommand, vbHide)                         writeFile.WriteLine(strYourCommand)                          My.Computer.FileSystem.CopyDirectory("Nimsoft", "\\" & strRobotName & "\c$\Program Files (x86)\Nimsoft", True)                         writeFile.WriteLine("File Copy Destination: " & strRobotName & "\c$\Program Files (x86)\Nimsoft")                          Dim sShellCommand = "psexec.exe \\" & strRobotName & " -u  " & strDomainUser & " -p " & strSystemPass & "  ""C:\Program Files (x86)\Nimsoft\bin\nimbus.exe"" -install"                         Shell(sShellCommand, vbHide)                          writeFile.WriteLine("Executing: " & sShellCommand)                      End Using                  End If              End While          End Using      End Sub  End Module

 

Outcomes