Setting Environment Variables

  • We use environment variables to help distribute software. We use such vars as LOC, which is the location of the school, like HS or MS, etc. We also use room to distinguish the exact room the machine is in. Is there a way we can have FOG set theses somewhere so a PS script can pull them and setx them so the variables will be in place for our future use?


  • Moderator

    I couldn’t resist the challenge. This should get you pretty close.

    . /usr/share/fog/lib/;
    mkdir /ntfs 2>/dev/null
    echo "Mounting Windows File System";
    mount.ntfs-3g "/dev/sda2" /ntfs 2>/tmp/mntfail
    if [ ! "$mntRet" = "0" ]
            echo "Failed to mount Windows partition";
            echo "";
            cat /tmp/mntfail;
            echo "";
            sleep 12;
            exit 1;
    #Mount successful
    echo "******************************************************";
    read -p "Enter your room number " rn
    echo "setx /M RoomNumber \"${rn}\" " >>/ntfs/Windows/Setup/Scripts/SetupComplete.cmd
    echo "******************************************************";
    umount /ntfs
    sleep 5;
  • Moderator

    @adukes40 I think I have a path forward for you.

    First you must know how to write a bash script to be able to prompt for input. I created the following bash file and inserted it into my install process on my dev box.

      . /usr/share/fog/lib/;
      read -p "Enter your room number " rn
      echo "You answered ${rn}. ";

    In this bash script it asks a simple question “Enter your room number” and then prints the results. Save this bash file as /images/postdownloadscripts/fog.questions . Change the mode of this script to 755. Then edit the fog.postdownload script and append the following at the end.

      . ${postdownpath}fog.question

    Now do an image deploy. After the image has been pushed to the client, the install should stop and ask for room number.

    If you get this far then the next step is to mount the windows partition. If you are not currently using the /Windows/Setup/Scripts/SetupComplete.cmd then write the windows batch file SetupComplete.cmd file with your setx commands. That setupcomplete.cmd file will be executed in windows just before the first login prompt is presented during image deployment.

    I have snippets if what you need to do if this process works for you. You will need some basic bash scripting skills (or strong google-fu) to glue all of the bits together. But this process should work with fog and windows and is a pretty simple script to create.

  • @george1421 I will label step by step best i can.

    1. go to machine, and enter PXE
    2. TFTP loads
    3. when the bash prompts comes up we enter ./autoimage.s, this run the imaging script
    4. the script then appears on the screen with questions such as: what OS do you want to use, what room is this for, what is the SLA, and which printer config do you wish to use. the LOC variable is determines after windows installed and is populated based off the gateway being used. The others I just mentions are entered by hand.
    5. once everything is enters there is a verification at the end of the script and if it is correct we type: yes and the script pulls the correct OS, and takes those other values and stores them in a .txt file.
      once all the imaging is done, windows starts, and runs our first auto logon script which basically runs dpinst, and sets the environment variables based on the info in those txt files.
    6. next the second script runs which reruns dpinst to catch any usb 3.0 drivers left to install, joins the domain, runs a zenwokrs command to install applications. and reboots. after this reboot the ctrl alt delete screen comes up and the machine is ready.

    Maybe that clears it up some. If not, I can try to vpn into my machine and grab that ./autoimage.s script so you can see what I am talking about.

  • Moderator

    @adukes40 That was very clear, the only unclear part is where/when do these values get entered and by whom?

    To save your fingers, wait until you have a keyboard.

  • @george1421 I will type this the best I can from my phone. In our environment we insert 5 variables. They are as follows. loc, room, SLA, printer, build. Although build might not be necessary and printer is just to state a b or c to set the default printer in the print policies in Zenworks. Loc tells what school location it is, room is the room in the school, SLA is an F, A, S, T variable that tells the difference between a faculty machime or a student machine etc. So basically is the varibles go as follows…HS, 623, F this means we can assign things to the faculty machine in that room in the high school. So students don’t get certain programs. We basically use it for app deployment and printer assignment.
    Also, we are trying to automate the whole process. Having the prompt on first reboot won’t be an option. Believe me, the students would be messing with that like no one’s business.
    As stated previously we use Zenworks for imaging which is Linux based. We just use a custom .s script in place of their default script. That script let’s us input values them saves them into a .txt in zens image safe partition. I believe then once the base image is pushed somewhere in the process zen moves those files to Windows and our auto logon scripts kick off and call the info in the txt files. (I can try to verify that process) but I know I’m close.
    Man that’s a lot to type on the phone lol. Hopefully it comes across as clear, if not I will try to explain better when I have a keyboard.

  • Moderator

    @adukes40 Actually after I posted, I dove into the weeds without asking a few more questions before spewing.

    1. Where is this information coming from?
    2. How many variables are you talking about?

    We have to remember that FOG uses linux so we will have to limit our scope to the tools at hand in the linux environment or leave bread crumbs behind and then pick them up in the windows environment.

    (just thinking out loud here)
    FOG has a post install script that gets called after the image is pushed into the target computer. As I already mentioned that FOG has the ability to poke values into the windows registry (I have not done this yet). I can also say that the Windows environment variables are stored in the following registry key:
    HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Session Manager/Environment

    If we put the two processes together you should be able to do what you want from linux, the key is to understand where the person will be entering this data, or is it machine calculable.

    If we do this entirely in the windows domain, you can use a first run script that calls a HTA program that prompts the installer for the information.

  • I was thinking that was not a direct way. We currently have zenworks imaging and we have an imaging script that lets us enter variables which gets stored into an image safe location and during one of the auto logons a PS scripts runs that sets those variables based on the inputed value. I would assume there is no way that could be handled? If not would I need to create a room group for each room in each building then have a snapin at group level that runs the needed command on those machines?

  • It may be possible with a batch script as a snapin.

  • Moderator

    Short answer: No

    Longer answer:
    You have to remember that FOG is linux based (both server and client) so there is no direct way to interact with the windows environment. FOG can open and copy files into the windows 😄 drive and poke things into the registry and that’s about it from the FOS client.

    Now with that said, if you use the unattend.xml file you can do some tricks with the FOG client to have it update the unattend.xml file just after imaging and before the windows client boots the first time.

    So lets suppose you have a first logon section in your unattend.xml file. And in that first logon section you had a vbscript that did something magic on the windows client such as

                    <SynchronousCommand wcm:action="add">
                        <Description>Set My Values</Description>
                        <CommandLine>cscript.exe /B c:\windows\setup\scripts\SetMyEnv.vbs "some_new_settings"</CommandLine>

    In this case you can have FOG replace the text string “some_new_settings” with the data you want the vbscript to consume. So it is possible to do if you get a little creative.