Windows Environment Variable Extraction to HTML / WEB

Posted on 2007-07-27
Medium Priority
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
  • 4
LVL 40

Expert Comment

by:Richard Quadling
ID: 19581704
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

Richard Quadling earned 2000 total points
ID: 19581749
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

by:Richard Quadling
ID: 19581756
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

ID: 19585360
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 "unusualsuspex.wmn.cc/index.php" 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

by:Richard Quadling
ID: 19590874
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses
Course of the Month15 days, 1 hour left to enroll

840 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