Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Read System Environment Variable from ASP w/o any dll

Posted on 2005-04-11
4
Medium Priority
?
1,769 Views
Last Modified: 2012-06-22
Need to access a system/user environment variable (of the server) from ASP. Haven't done anything like that till now and Googling dint help. Can't believe such a common scenario has no solution in ASP! Well, if there is a way, ppl here wld know! ;)

please help me to...

- Read a System environment variable like PATH (NOT session/application/servervariable)
- Without using a dll
- A round-about way involving SQL server should be okay
0
Comment
Question by:fozylet
  • 2
4 Comments
 
LVL 1

Expert Comment

by:g1bz
ID: 13759690
ASP is a framework, it's functionality is dependant on COM objects, the only ones built in (no 3rd party dll involved) are Response, Request and Server, these are purposefully of limited scope and cannot achieve what you want alone.

Server does provide .CreateObject, if permissions allow you could use this to invoke wscript.shell which I believe can access the variables you want.

As for a round-about way involving SQL server, most installations are locked down to the level of ASP, if this is on a shared hosting platform (assuming that's your reason for ruling out a COM dll), have you considered that the host does not want users accessing machine-level information?

If for some reason you do have full access to SQL Server but not wscript, you could use DTS + ActiveX Script packages to do this for you.
0
 
LVL 6

Expert Comment

by:infex
ID: 13759712
In ASP.NET, you can use the environment class, see

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemEnvironmentClassTopic.asp


In ASP you should invoke the cmd interpreter, using pipes to create a file. (eg. PATH > pathtext.txt {create a file with as content the result of the path command} )

Then read that file and parse it.


0
 
LVL 1

Accepted Solution

by:
g1bz earned 2000 total points
ID: 13759725
I decided to test wscript.shell:

<%
dim wshell : set wshell = Server.CreateObject("wscript.shell")
Response.Write(wshell.Environment.Item("path"))
%>

Worked as expected, but this is on my own machine, if your on a professional host, this should cause a security error message.

P.S. To turn %vars% into meaningful data you can enclose it in a wshell.ExpandEnvironmentStrings() call.

Response.Write(wshell.ExpandEnvironmentStrings(wshell.Environment.Item("path")))
0
 
LVL 8

Author Comment

by:fozylet
ID: 13759766
@g1bz,

great explanation! :)
am aware of the limitations and that is why i was sure a pure asp solution will not work. using WSH should be okay since WSH is installed as a standard add-on in most cases. the reason i ruled out a component is coz of the requirement at hand, not coz of remote hosting.

in short, ur solution works perfect! thank you! :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Integration Management Part 2
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

564 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