Windows Environment Variable Extraction to HTML / WEB

Posted on 2007-07-27
Last Modified: 2010-04-16
We are making a simple HTML website.
We need to extract Windows Environment variables (Ie the ones set is Computer - Properties)
The variable we have set at dos level is called storename
We would also like to retrieve the IP Address and Default gateway of the PC
If we need to store these in environment variables too we will
Thanks in advance
Question by:Wizard_IT
    LVL 40

    Expert Comment

    Do you want the CLIENT's computer name/IP address/gateway or the SERVER's computer name/IP address/gateway.

    If it is the client's you want, then you will have to either ask them very nicely to enter it into a form or construct a java or activex app to get them (and there may be limits as to what you can get hold of).

    Client side JS cannot access this info.

    LVL 40

    Accepted Solution

    If you are using PHP, then ...

    exec('ipconfig', $a_IPConfig);
    foreach($a_IPConfig as $s_ConfigLine)
          if (preg_match('`(IP Address|Default Gateway)[^\d]*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})`sim', $s_ConfigLine, $a_Matches))
                $s_Var = str_replace(' ', '_', $a_Matches[1]);
                $$s_Var = $a_Matches[2];

    echo 'The storename is ', (isset($_ENV['storename']) ? $_ENV['storename'] : 'undefined'), PHP_EOL;
    echo 'The IP Address is ', $IP_Address, PHP_EOL;
    echo 'The Default Gateway is ', $Default_Gateway, PHP_EOL;

    for me, results in ...

    The storename is undefined
    The IP Address is
    The Default Gateway is

    If I set the storename to Bob's Shack of Tools

    I get ...

    The storename is Bob's Shack of Tools
    The IP Address is
    The Default Gateway is
    LVL 40

    Expert Comment

    The php solution can be easily adapted to any decent scripting language, but this still wouldn't give you CLIENT details, just server details.

    Author Comment

    Thanks qualding!!!
    I uploaded a test page online containing the script you suggested and when browsing to the page i receive the following:
    "Warning: exec() has been disabled for security reasons in /home/jay/public_html/index.php on line 13

    Warning: Invalid argument supplied for foreach() in /home/jay/public_html/index.php on line 14
    The storename is undefined The IP Address is The Default Gateway is "

    the url of the page is "" if you want to take a look at source code
    please help, i really need to get this working for monday!
    Thanks in advance.
    LVL 40

    Expert Comment

    The first error of "Warning: exec() has been disabled for security reasons in /home/jay/public_html/index.php on line 1", means that your ISP has disabled the ability for you to run external applications. Even such things as ipconfig.

    This is a security setting made by the ISP and as such there is no work around using PHP. You could try using Perl (no idea what to code), but I suspect Perl has a similar mechanism on restrictions.


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
    Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
    Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    728 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

    18 Experts available now in Live!

    Get 1:1 Help Now