Need Script - Never Wrote One

Posted on 2011-04-20
Last Modified: 2014-01-12
Very simple, I am sure, but I've viewed examples/samples online which I thought were similar to my situation but they all look different from one another, so was very tough trying to create my own from looking at others'.

I have two users in an SBS network who run Win7. I have a Kaseya agent package to install (executable) residing on the server in \docs and settings\all users\documents. I need a login script so that the agent will install automatically, in the background, once the users login to the network.

Question by:msiers
    LVL 8

    Assisted Solution

    what about installing the agent using the Kaseya user interface.  

    page 4..
    LVL 8

    Accepted Solution

    or may be you can use this script as well..

    @echo off 
    If not exist "%programfiles%\kaseya\agent\agentmon.exe" \\NETBIOSDOMAINNAME\Sysvol\domain.local\scripts\customername-workstation.exe /c /e /g=customername /s /i 

    Open in new window

    LVL 17

    Expert Comment

    by:Tony Massa
    FIrst, you need to determine the command required to install the software without user intervention.
    Then you have to figure out what registry keys or WMI product to look for to ensure that the program doesn't try to install every time the computer starts.

    Then, you write the script to:

    A) Check to see if the application is already installed
     - if not -
    B) Install the program

    Here's a script I wrote to install SAP PDF Print component which checks to see if it's already installed first, then if it's not, checks to see if the SAPGUI client is installed (our requirement).

    This should fit right in to what you should just be able to change some of this stuff around to fit your needs.
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Const HKEY_LOCAL_MACHINE = &H80000002
    Const EVENT_SUCCESS = 0
    Const EVENT_FAIL = 1
    On Error Resume Next
    strComputer = "."
    Set objRegistry = GetObject("winmgmts:\\" & _ 
        strComputer & "\root\default:StdRegProv")
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objResults = objFSO.OpenTextFile("\\server\share\Install-SAP-PDF.log", ForAppending)
    Set objShell = WScript.CreateObject ("")
    Set WSHNetwork = CreateObject("WScript.Network")
    strComputerName = WSHNetwork.ComputerName
    'Check the following registry value to determine if SAP PDF is already installed
    strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\SAPPdfPrint\"
    strValueName = "DisplayName"
    objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
    If IsNull(strValue) Then
    	'SAP PDF programs is NOT currently installed
    	'  Next, Check for SAPGUI client software
    	strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\SAPGUI710\"
    	strValueName = "DisplayName"
    	objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
    	If IsNull(strValue) Then
    		objResults.Writeline strComputerName & vbTab & "SAP GUI Not Installed" & vbTab & Now()
    		'SAP GUI is not Installed.  Requirements not met...exit script
    		'SAP GUI is installed.  Continue to SAP PDF Install
    		'Now copy the exe locally to the root of C:\
    		objShell.Run ("xcopy \\server\shares\SAPGUI\xPDFPrint.exe c:\"),0,True
    		'Install the application in SILENT mode
    		Set objExec = objShell.Exec("C:\xPDFPrint.exe /Silent")
    		'Check every 10 seconds to see if the installation process is complete
    		Do While objExec.Status = 0
    			WScript.Sleep 10000
    		If objExec.ExitCode = 0 Then
    			objResults.Writeline strComputerName & vbTab & "SAP PDF Component Installed" & vbTab & Now()
    			objShell.LogEvent EVENT_SUCCESS, "SAP PDF Printer Installation was successful"
    			objResults.Writeline strComputerName & vbTab & "SAP PDF Component Failed to Install" & vbTab & Now()
    			objShell.LogEvent EVENT_FAIL, "SAP PDF Printer Installation failed with code: " & objExec.ExitCode
    		End If
    	End If
    	objResults.Writeline strComputerName & vbTab & "SAP PDF Component Installed Previously" & vbTab & Now()
    End If

    Open in new window


    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (…
    Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  ( Here (http…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now