Page 1 of 1 1
Topic Options
#206978 - 2013-03-27 07:16 AM Translate Trend Micro VBS Install Script
eyeontech Offline
Fresh Scripter

Registered: 2013-03-18
Posts: 6
Loc: Australia
Hi all,

I need a lot of help translating a Trend Micro VBS Script into KIX32.
I have tried the Group Policy route but I would like to keep the existing KIX environment and roll out the new AV Agents the KIX way.

Here is the code:

 Code:
pathOfWFBSHInstaller="msiexec /qn /i \\SERVER\netlogon\Kix32\Apps\TrendMicro\Agent_Installer.msi"
strComputer = "." 
strOutput = ""
serviceCount = 0
totalServiceCountToCheck = 3

' check if WFBS-SVR is installed by detecting service ntrtscan, tmlisten, svcGenericHost are exist or not
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service")
For Each objService in colItems
	strOutput = strOutput & objService.name & vbCr & vbLf
	If objService.name = "ntrtscan" Then
		serviceCount = serviceCount + 1
'		Wscript.Echo "Service " & objService.Caption & " is " & objService.Started 
	ElseIf objService.name = "tmlisten" Then
		serviceCount = serviceCount + 1
'		Wscript.Echo "Service " & objService.Caption & " is " & objService.Started 
	ElseIf objService.name = "svcGenericHost" Then
		serviceCount = serviceCount + 1
'		Wscript.Echo "Service " & objService.Caption & " is " & objService.Started 
	End If
Next

If serviceCount <> totalServiceCountToCheck Then
	Dim WshShell
	Set WshShell = CreateObject("WScript.Shell")
	WshShell.Run pathOfWFBSHInstaller
End if


Any takers?

Top
#206980 - 2013-03-27 08:00 AM Re: Translate Trend Micro VBS Install Script [Re: eyeontech]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Hi, and welcome to KORG!

Here's your code:
 Code:
$pathOfWFBSHInstaller="msiexec /qn /i \\SERVER\netlogon\Kix32\Apps\TrendMicro\Agent_Installer.msi"
$strComputer = "." 
$strOutput = ""
$serviceCount = 0
$totalServiceCountToCheck = 3

; check if WFBS-SVR is installed by detecting service ntrtscan, tmlisten, svcGenericHost are exist or not
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $strComputer + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_Service")
For Each $objService in $colItems
  $strOutput = $strOutput + $objService.name + @CRLF
  Select
    Case $objService.name = "ntrtscan"
      $serviceCount = $serviceCount + 1
      ;? "Service " + $objService.Caption + " is " + $objService.Started
    Case $objService.name = "tmlisten"
      $serviceCount = $serviceCount + 1
      ;? "Service " + $objService.Caption + " is " + $objService.Started
    Case $objService.name = "svcGenericHost"
      $serviceCount = $serviceCount + 1
      ;? "Service " + $objService.Caption + " is " + $objService.Started
  EndSelect
Next

If $serviceCount <> $totalServiceCountToCheck
  Dim $WshShell
  $WshShell = CreateObject("WScript.Shell")
  $WshShell.Run($pathOfWFBSHInstaller)
EndIf

Top
#207021 - 2013-04-02 08:27 AM Re: Translate Trend Micro VBS Install Script [Re: Arend_]
eyeontech Offline
Fresh Scripter

Registered: 2013-03-18
Posts: 6
Loc: Australia
Thanks so much for replying.

I am setting up the script to also log changes.
Are there any good lines you would add to create a log file on a network share.
With say; Computer name, user, date & time, fail or success?

I added this: ? "Any error for: " " " + @ERROR
Ultimately I would like to create a log file and figure out if it installed the update and ran successfully.
I have tested the script as is, I did not receive any errors, but the software did not install either.
Output:
Service OfficeScanNT RealTime Scan is -1
Service OfficeScan NT Listener is 00
Any error for: 0

The users are not local admin either, which I suspect could be contributing to the software not installing.

Top
#207025 - 2013-04-02 01:19 PM Re: Translate Trend Micro VBS Install Script [Re: eyeontech]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
I have a function called fMsg() that I use for all logging. Latest version is in the Kix library of my web site. It can display on screen, file, or both, timestamps the log data, and can even suppress output unless $DEBUG is true for dynamic debugging messages.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#207039 - 2013-04-03 03:00 AM Re: Translate Trend Micro VBS Install Script [Re: Glenn Barnas]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I would start by replacing:
 Code:
If $serviceCount <> $totalServiceCountToCheck
  Dim $WshShell
  $WshShell = CreateObject("WScript.Shell")
  $WshShell.Run($pathOfWFBSHInstaller)
EndIf


with:
 Code:
If $serviceCount <> $totalServiceCountToCheck
  shell $pathOfWFBSHInstaller
  if @error
   "the installer failed with error:" @error
   get $
  endif
EndIf
_________________________
!

download KiXnet

Top
#207040 - 2013-04-03 03:03 AM Re: Translate Trend Micro VBS Install Script [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
oh, and I do not know what security settings you have in place but running MSI directly from netlogon is not so cool. but, run the script with the kix shell and see what kinda errors you get.
_________________________
!

download KiXnet

Top
#207041 - 2013-04-03 03:17 AM Re: Translate Trend Micro VBS Install Script [Re: Lonkero]
eyeontech Offline
Fresh Scripter

Registered: 2013-03-18
Posts: 6
Loc: Australia
 Originally Posted By: Lonkero
oh, and I do not know what security settings you have in place but running MSI directly from netlogon is not so cool. but, run the script with the kix shell and see what kinda errors you get.


Yeah, not sure on the security set up here.
I was given a crash course on the network then the previous admin left.
I am still patching up bits and pieces but it is taking up a lot of time.

Could you suggest a line of code to copy the msi to the local disk then launch from there rather than off the network share.
Chances are it will slow down a fair bit if I even tried launching this on a couple of computers.

Users are not local admins so I am guessing a better place would be to create a new folder in %USERPROFILE%.

Thanks

Top
#207042 - 2013-04-03 12:45 PM Re: Translate Trend Micro VBS Install Script [Re: eyeontech]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Installing software during the login process is a generally bad idea, especially when users are not local admins (a GOOD THING!).

Software installation is an admin function, so approach it as such. I have a simple bat file that I use with our SWDIST product.. It is copied it to the user's workstation (C:\Temp), then a scheduled task is created using network credentials that are also a local admin (a DOMAIN\Computer Admins group). The BAT file maps a network drive to the install share and invokes an unattended installation directly from the share (NOT NetLogon!). Runs as admin, behind the scenes. No disruption to the user and no chance that the user can gain elevated rights.

With a deployment share and this batch file I can deploy to hundreds of systems a day.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#207046 - 2013-04-03 05:15 PM Re: Translate Trend Micro VBS Install Script [Re: Glenn Barnas]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Glenn is absolutely correct in his assertion that installations during login is a bad idea. But since you are probably in a bind, I modified the code just a bit to make the copying and execution easier.

 Code:
$WFBSHInstaller = "Agent_Installer.msi"
$pathOfWFBSHInstaller = "\\SERVER\netlogon\Kix32\Apps\TrendMicro"
$pathOfLocalWFBSHInstaller = "%USERPROFILE%\Kix32\Apps\TrendMicro"
$strComputer = "."
$strOutput = ""
$serviceCount = 0
$totalServiceCountToCheck = 3

; check if WFBS-SVR is installed by detecting service ntrtscan, tmlisten, svcGenericHost are exist or not
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $strComputer + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_Service")
For Each $objService in $colItems
  $strOutput = $strOutput + $objService.name + @CRLF
  Select
    Case $objService.name = "ntrtscan"
      $serviceCount = $serviceCount + 1
      ;? "Service " + $objService.Caption + " is " + $objService.Started
    Case $objService.name = "tmlisten"
      $serviceCount = $serviceCount + 1
      ;? "Service " + $objService.Caption + " is " + $objService.Started
    Case $objService.name = "svcGenericHost"
      $serviceCount = $serviceCount + 1
      ;? "Service " + $objService.Caption + " is " + $objService.Started
  EndSelect
Next

If $serviceCount <> $totalServiceCountToCheck
  Copy $pathOfWFBSHInstaller+"\"+$WFBSHInstaller $pathOfLocalWFBSHInstaller
  Shell "msiexec /qn /i "+$pathOfLocalWFBSHInstaller+"\"+$WFBSHInstaller
  If @error
    "the installer failed with error:" @error
    get $
  Endif
EndIf

Top
#207047 - 2013-04-03 06:51 PM Re: Translate Trend Micro VBS Install Script [Re: ShaneEP]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Why copy the MSI file to the local computer before execution?
Any reason not to install directly from the share on the central server?
If you copy it locally, when do you remove the install file that's no longer needed?
Do you need to check each workstation for the status of the installation?

As for my earlier recommendation, I want to clarify one point.. when you create a scheduled task event, you don't actually schedule it to run at a set time, you simply define the TASK event without any TRIGGER, then EXECUTE the task remotely. All of this can be done with the tcLib UDF library.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#207048 - 2013-04-03 11:25 PM Re: Translate Trend Micro VBS Install Script [Re: Glenn Barnas]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
msi doesn't always install from an unc path, so indeed copying the file to local drive in a network which computers are not quaranteed to behave the same is a good thing.
_________________________
!

download KiXnet

Top
#207050 - 2013-04-04 12:07 AM Re: Translate Trend Micro VBS Install Script [Re: Lonkero]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Installing programs that modify the network settings may break the link during install. When I install the Cisco VPN client, I have to copy it to a local drive because of that.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#207052 - 2013-04-04 03:19 AM Re: Translate Trend Micro VBS Install Script [Re: Les]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Not sure if it's luck or skill, but of the over 220 apps I have in my SWDIST library, only three require a pre-copy to the local disk to work properly. All - as Les pointed out with his Cisco example - put a wrapper around the network stack and temporarily drop the connection. Two are the Cisco VPN and VoIP Softphone clients and the other is the SonicWall VPN client. The Cisco SoftPhone app will actually install OTN unless you need CDP and dual-IP capability, features which mess with the network stack.

I've packaged so many apps for OTN install, both internally and for clients, that I never copy files to a local system anymore.

Glenn

PS - I prefer to think it's "skill" \:D
_________________________
Actually I am a Rocket Scientist! \:D

Top
#207053 - 2013-04-04 05:42 AM Re: Translate Trend Micro VBS Install Script [Re: Glenn Barnas]
eyeontech Offline
Fresh Scripter

Registered: 2013-03-18
Posts: 6
Loc: Australia
I will be installing Trend Micro Antivirus agents, as well as uninstalling the older version.
It has a firewall component which does knock out the network connection at a point during the uninstall and the install.

I am not at all familiar with packaging the apps, I really like the idea of the schedule task for installs though.

I really have no reason for installing through KIX32, only that was the way the previous admin was rolling out Google Chrome installs, which was not working properly :).
I am still trying to piece together the old login scripts and I am looking to start from scratch.
Only using them for Drive Mapping, Printers, Default Browser, and I am sure they will become more complicated as I make my way through the mess.

Still learning as I go though. (I am really liking the idea of the schedule task though.)
I have been looking at alternatives for deploying updates for applications though.
Like ninite pro or puppet.

Top
#207054 - 2013-04-04 02:34 PM Re: Translate Trend Micro VBS Install Script [Re: eyeontech]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
If you're starting from scratch, you might want to look at our Universal Login Script. It's code-free, fast, flexible, and virtually bulletproof. We just deployed it at a large financial company and reduced the GPO-based login drive mapping from a random 20-27 seconds to a consistent 4.3 seconds! Its written in Kix (closed source) but you can extend its capabilities with your own scripts, even using the internal functions and variables.

The "Administrators Toolchest" is a collection of free, Kix-based utilities that help system administrators manage their environments.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#207072 - 2013-04-08 08:46 AM Re: Translate Trend Micro VBS Install Script [Re: Glenn Barnas]
eyeontech Offline
Fresh Scripter

Registered: 2013-03-18
Posts: 6
Loc: Australia
I have been looking at using PSEXEC to install the application using the system credentials.
This has not been so smooth but I am still trucking along.

I will update if I can figure out the code.

I think my problem is the fact that users do not have admin rights and cannot install applications. This explains which the script is failing.

I have been looking at running the KIX Script elevated but it may be simpler to just launch PSEXEC and remotely install that way.
I just have not been successful.

Top
#207074 - 2013-04-08 01:08 PM Re: Translate Trend Micro VBS Install Script [Re: eyeontech]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
It's actually simple as 1, 2, 3... ;\)
1. copy the install media to a shared folder. Create a BAT file there that will start the installation in unattended mode.
2. Create a bat file on the remote computer that maps a drive to your install share and runs the installation bat file.
3. Create and execute a scheduled task on the remote computer that runs the above bat file

The bat file to install the application is up to you.. it is installed in the folder on the network share with the application setup files.

The bat file to map to the share and run the install file (RmtInst.bat) would be something like this:
 Code:
@Echo Off
Rem Map a drive - define your server and share
Net Use Y: \\server\install_share
y:
REM CD to the folder where the app is stored
CD \AppFolder
REM Run the install bat file you created in step 1
Call MySetup.BAT
This must be copied to the workstation, possibly the C:\TEMP folder. DO NOT use %TEMP% as it is unique per user. THIS PART can be triggered by the login script - code to determine if the required app is missing or outdated can be run by the users even without admin access. They can also copy the local script to the C:\Temp folder.

At this point, I usually write a file to a share somewhere with the workstation name in it. A process running on that server finds the file, extracts the computer name, and performs the following script to run the installation with elevated rights:
 Code:
Break On
; load the tcLib UDF Library
Call 'C:\UDF_Library\tclib.kxf'


; NOTE: The name of the target computer has been extracted from the file or
; otherwise provided in the $Target variable!!


tcInit()                      ; init the library

; Define the APPlication to run, a CoMmenT, and enable the Delete When Done option
$RV = tcDefineTask(“APP=C:\Temp\RmtInst.bat CMT=Remote Installer DWD=1”)

; Define the user account and password to run the task with
$RV = tcDefineTask (“USR=username PWD=password”)

; Save the task to the remote computer using the AppInstall task name
$RV = tcSetEvent($Target, 'AppInstall')

; Run the task created above immediately
$RV = tcExecute($Target, 'AppInstall')
So, in just a few lines, you can create a remote task and execute it with whatever credentials you wish. We have a product that employs this basic methodology, and installations can be triggered by the login script and executed within seconds.

Unless you specify credentials (clear text) to PSExec, you can't use network resources. Installing software via the SYSTEM account isn't a good idea either.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#207121 - 2013-04-19 05:37 AM Re: Translate Trend Micro VBS Install Script [Re: Glenn Barnas]
eyeontech Offline
Fresh Scripter

Registered: 2013-03-18
Posts: 6
Loc: Australia
Brilliant, thanks so much for all the help.
I am hard at working doing the cleaning up and I will have this place in tip top shape.
Good times are ahead.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 874 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.039 seconds in which 0.014 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org