3 Replies Latest reply on Aug 24, 2009 5:52 PM by Dataspike

    Environment Variables in a custom script

    dgaines Apprentice

      I am trying to use an environment variable in a custom script.  I am trying to reference the variable from the computer's inventory record in the Environment - Variable - ProgramFiles section.  The script isn't subsistituting the value contained in this item.   Has anyone used one of these inventory items in a custom script?  I appreciate the help and I am sure that this is just something obvious that I am overlooking.

        • 1. Re: Environment Variables in a custom script
          Specialist

          Are you talking about Managed Scripts or Security and Patch Manager?  Also, which version, and service pack?  Be sure to use the Tags section in the first post to help.

           

          Chris

          • 2. Re: Environment Variables in a custom script
            dgaines Apprentice

            8.8 SP3 and managed scripts.

            • 3. Re: Environment Variables in a custom script
              Specialist

              OK...

               

              From what I've seen and done, the "%programfiles%" variable does not work when called via a Remote Execute such as this

               

              [MACHINES]
              REMEXEC1=notepad.exe %programfiles%\script.txt

               

              The only way I've done it, is via calling a VBScript that went to the location needed, or called the specific application.

               

              [MACHINES]
              REMEXEC1=wscript.exe \\<coreserver>\sharename\vbs\script.vbs

               

              ' Script.vbs

               

              strProgramFiles = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%programfiles%")

              Set WshShell = WScript.CreateObject("WScript.Shell")

               

              rc = WshShell.Run("notepad.exe " & strProgramFiles & "\script.txt",, True)

               

              ' You can also run applications

              ' Remember that QUOTES are needed if the path contains a SPACE

               

              rc = WshShell.Run("""" & strProgramFiles & "\Windows Media Player\wmplayer.exe" & """",, True)

              Hope that points you in the right direction.