none
VBscript - Enter a value (variable windows) on the path of downloading the installation file RRS feed

  • Question

  • Hello All,

    My name is Diego and i need so much help with this VBscript,

    The script works well but I just need to call (SRV) windows System variable

    that contains the name of the local server.

    All client machines (winxp) already have a system variable name (SRV) with

    value (name of local server)for example SRVADS001, because in our environment

    we have many offices with low-speed links, so need to get the download installation  file on the local serverr, so we avoid bandwidth consumption.

    How i can Call SRV Variable and puts it on path
    FULL_INSTALL_PATH = (INSTALL_PATH & STR_PARAMETERS) ?

    I need that the installation path of the file is correct to all offices, each office has a local server defined on Windows XP variable System :

    INSTALL_PATH = Chr (34) & "\\SRV (Variable)\Agent\AgInstall.exe" & Chr (34)


    FY = The SRV variable just contains the name of local server, do not contain \\

     

    VBscript

    ' Variable Declarations
    '==================================
    Dim ipAddress, agentVersion, dataPath, xmlDoc, ElemList, regExist
    Dim REQUIRED_AGENT_VERSION
    Dim REQUIRED_SERVER_IP
    Dim INSTALL_PATH
    Dim STR_PARAMETERS
    Dim FULL_INSTALL_PATH

    '======================================
    ' MUST CHANGE VARIABLES IN THIS SECTION
    '======================================
    REQUIRED_AGENT_VERSION="4.6.0"
    REQUIRED_SERVER_IP="192.168.1.100:12300"
    INSTALL_PATH = Chr(34) & "\\Server\NETLOGON\AgInstall.exe" & Chr(34)
    STR_PARAMETERS = " /FORCEINSTALL /INSTALL=AGENT /INSTDIR=" & Chr(34) &

    "%PROGRAMFILES%\Framework\" & Chr(34) & " /SILENT"
    FULL_INSTALL_PATH = (INSTALL_PATH & STR_PARAMETERS)

    '======================================
    ' END CHANGE VARIABLES SECTION
    '======================================
    Const HKEY_LOCAL_MACHINE = &H80000002

    CheckRegExist()

    If (regExist=TRUE) Then

    '==================================
    ' Get Registry Values
    '==================================
    agentVersion = ReadReg("HKEY_LOCAL_MACHINE\SOFTWARE\Network\Framework\Data

    Path")
    'WScript.Echo "Agent Version: " & agentVersion

    dataPath = ReadReg("HKEY_LOCAL_MACHINE\SOFTWARE\Network\Framework\Data Path")
    'WScript.Echo "Data Path: " & dataPath

    '==================================
    ' Read XML Sitelist
    '==================================

    Set xmlDoc = CreateObject("Msxml2.DOMDocument")
    xmlDoc.load(dataPath & "\SiteList.xml")

    Set ElemList = xmlDoc.getElementsByTagName("SpipeSite")
    ipAddress = ElemList.item(0).getAttribute("ServerIP")
    ' MsgBox ipAddress & " " & InStr(REQUIRED_SERVER_IP,ipAddress)

    '==================================
    ' Check Agent Version, ServerIP
    '==================================

    IF (agentVersion<REQUIRED_AGENT_VERSION) OR InStr

    (REQUIRED_SERVER_IP,ipAddress) < 1 THEN

    InstallNewAgent(FULL_INSTALL_PATH)

    'MsgBox("Your agent is now up to date and configured correctly.")

    ELSE

    'MsgBox("Your agent is currently up to date and configured correctly.")

    END IF

    'Install Agent if Reg Does NOT exist

    ELSE
    InstallNewAgent(FULL_INSTALL_PATH)
    END IF

    '==================================
    ' Registry Reader
    '==================================

    Function ReadReg(RegPath)
    Dim objRegistry, Key
    Set objRegistry = CreateObject("Wscript.shell")
    Key = objRegistry.RegRead(RegPath)
    ReadReg = Key
    End Function

    '==================================
    ' Agent Installation
    '==================================

    Function InstallNewAgent(FULL_INSTALL_PATH)
    Dim wshShell
    Set wshShell = WScript.CreateObject ("WSCript.shell")

    ' MsgBox("Installing New Agent...")

    wshshell.run FULL_INSTALL_PATH, 6, True
    set wshshell = nothing
    End Function

    '==================================
    ' Check if Reg Key Exists
    '==================================

    Function CheckRegExist ()
    Dim strComputer, objRegistry, strKeyPath, strValueName, strValue
    strComputer = "."
    Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root

    \default:StdRegProv")

    strKeyPath = "SOFTWARE\Network\Shared Components\Framework"
    strValueName = "Version"

    objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

    If IsNull(strValue) Then
    'Wscript.Echo "The registry key does not exist."
    regExist=FALSE
    Else
    'Wscript.Echo "The registry key exists. (" & strValue & ")"
    regExist=TRUE
    End If
    End Function

    Thursday, March 20, 2014 8:26 PM

Answers

All replies

  • My name too is Diego....They used to call me Diego Rivera but now nobody knows who he was.  Diego is a lost name.

    The Shell has the environment in VBScript.

    var = Shell.Environment("process")("SRV")

    http://technet.microsoft.com/en-us/library/ee156595.aspx


    ¯\_(ツ)_/¯

    Thursday, March 20, 2014 8:34 PM
  • Thank you Diego Rivera for instant reply! Sorry my name is Diego Bem, I don't have a lot of experience with VBscript, Would greatly appreciate it if you include the line correctly in my script. could you help me?
    Thursday, March 20, 2014 8:45 PM
  • Here -a present from Frida: http://technet.microsoft.com/en-us/scriptcenter/dd772284

    Learning to paint is far more valuable then looking at a painting.


    ¯\_(ツ)_/¯

    Thursday, March 20, 2014 9:13 PM
  • Yes I can study, it turns out that I need to solve this as soon as possible and if you're not willing to help me ........ =/ thank you.
    Thursday, March 20, 2014 10:32 PM
  • Yes I can study, it turns out that I need to solve this as soon as possible and if you're not willing to help me ........ =/ thank you.

    I do not understand what you want.  I cannot edit your file.  I have no idea what it does.  Just follow the example in the code I posted.  Place it in your code where you think it goes.  Post back with what you have done and any information on your errors.

    This is a do-it-yourself forum for technician.  It is not a  user help desk.  We can help you but we cannot really do your editing for you.


    ¯\_(ツ)_/¯

    Thursday, March 20, 2014 10:38 PM
  • This code is a Agent Antivirus product installation, Thank you the solution is

    on line 

    Chr(34) & "\\%SRV%\Share\AgInstall.exe" & Chr(34) 

    I appreciate your education! thank you!


    Thursday, March 20, 2014 11:44 PM
  • Sorry but that won't work.  You didn't even read the example I posted and you igmnored the exact line of code that I posted.

    I am sorry but I will leave you to find someone else as it is clear you are not interested in my answer.


    ¯\_(ツ)_/¯

    Thursday, March 20, 2014 11:51 PM
  • If you want to use run with a variable then this is how:

     wshshell.run  "cmd /c \\%SRV%\Share\AgInstall.exe"

    By running a command under CMD you can get the env variable converted.  By itself it won't convert.

    The Chr(34) are not needed here.

    Converting in VBScript As I posted is better usually:

    var = Shell.Environment("process")("SRV")
    wshshell.run  "\\" & var & "\Share\AgInstall.exe"


    ¯\_(ツ)_/¯

    Friday, March 21, 2014 12:06 AM
  • Thank you man.. 

    worked only by calling the variable that exists in all the client machines with windows XP this way

    Chr (34) & "\\%SRV%\Share\AgInstall.exe" & Chr (34)

    this Script runs on windows startup, the machines with Windows XP  have recognized the variable because the SRV variable  contains the name of the local server where is the AgInstall.exe to installation

    The installation worked successfully.

    Thanks anyway!

    Friday, March 21, 2014 1:24 AM
  • How inventive.  Windows is like an amusement park.  There are Leprechauns everywhere.

    ¯\_(ツ)_/¯

    Friday, March 21, 2014 1:54 AM