5 Replies Latest reply on Jun 4, 2008 3:41 AM by FrankScholer

    How to read a netinstall variable set in VBScript in NetInstall project

    eldorado2006 Rookie
      Hi,

      I've written a VBScript where I've extracted the content of xUser using NiGetVar("xUser"), manipulate the content. Then I set the manipulated value to another variable say X using NiSetVar, so that I can read the value of X inside my NetInstall project but not getting it right.

      My objective is to read the value of a variable set in VBScript in my NetInstall project.

      Please help.

      Thanks,
      El
        • 1. Re: How to read a netinstall variable set in VBScript in NetInstall project
          eldorado2006 Rookie
          Even a simple NiGetVar("ComputerName") is not working from VBScript. Do I need to do any change in the settings in NetInstall Manager to make it work?

          Any help would be appreciated.

          Thanks,
          El
          • 2. Re: How to read a netinstall variable set in VBScript in NetInstall project
            Klaus Salger Expert
            Hi El,

            NiGetVar("") and NiSetVar"", should work without any special settings. The following example shows how to use the commands to get and set NetInstall variables from VBS.

            The netinstall script might look like this:

            Set('NIVar1','myString')
            CallScript(.\extern$\myScript.vbs)
            MsgBox
              NIVar1=%NIVar1%
              NIVar2=%NIVar2%
            EndProc


            The VBS might look like this:

            var1=NiGetVar("NIVar1")
            var2=var1 & "-new"
            NiSetVar "NIVar2",var2


            The expected result is a message box with the following content:
            NIVar1=myString
            NIVar2=myString-new

            If the result is not what you expect take a look into the NetInstall log. If there's something wrong with the variables or there is a syntax error in the VBS you will see it there.

            Hope this helps
              Klaus
            • 3. Re: How to read a netinstall variable set in VBScript in NetInstall project
              eldorado2006 Rookie
              Klaus,

              Thanks for your reply. I'm still not able to get the values of my variables. I'm not sure what I'm missing here. My netinstall log doesn't talk about any error or failure or warnings too.

              I tried reading just NiGetVar("ComputerName") in my VBS and tried to print it in a text file, it doesn't even writes this value in the text file.

              Thanks,
              El
              • 4. Re: How to read a netinstall variable set in VBScript in NetInstall project
                eldorado2006 Rookie
                Klaus,

                I figured out the problem. The actual problem was in the way I was invoking my VBScript. I've used execute command instead of callscript.

                I don't know somehow execute is executing the VBS file using CScript but not retrieving the variable values. With CallScript, it is working fine.

                Now it is working fine. Thanks for your inputs.

                Thanks,
                El
                • 5. Re: How to read a netinstall variable set in VBScript in NetInstall project
                  FrankScholer Master
                  Hi El,

                  the cause you have to invoke your script via "CallScript" is that if you are using this command, then NetInstall is the script host. If you are invoking it via "Execute" then wscript.exe or cscript.exe is the host (the "host" is the application that loads the script interpreter engine, here vbscript.dll, and passes the script to it. The engine and the host then share the same execution context and can therefore exchange information). Other script hosts are for example Internet Explorer (that is the cause you can use VBScript code inside your html-pages) oder IIS (the scripts are then normally called ASP-pages).

                  As "NIGetVar" and "NISetVar" are no "normal" VBScript commands (you can't use these commands in any script not called by NetInstall), but they are provided by the NIRT (NetInstall Runtime) which acts as a the script host.

                  Please keep in mind, that you CANNOT use any methods/commands that are provided by the Windows scripthost (eg wscript.sleep or wscript.quit), because wscript is not involved when calling the script from inside NI and thus these commands would cause your script to fail.

                  HTH, regards
                  Frank