February 28, 2021
Hot Topics:

Obtaining Client-Specific Information with a Web Application

  • By Paul Kimmel
  • Send Email »
  • More Articles »

Creating an ActiveX Object

ActiveX objects for ascertaining client information include WScript.Network and WScript.Shell. WScript.Network can be used to determine the active user, for example, and WScript.Shell can be used to query information like the path to the MyDocuments folder. For a complete reference for these ActiveX libraries refer to the MSDN help documentation.

Tip: You can use script languages to run JavaScript at a command prompt by running the .js script file in the WScript.exe host.

To create an instance of the desired ActiveXObject you can invoke new ActiveXObject passing in the name of the library as a string that you want to create. The following code demonstrates how to use the debugger; statement to break into the code and create an instance of WScript.Network and WScript.Shell. With these two objects the UserName and the path to the special folder MyDocuments is obtained (refer to Listing 1).

Listing 1: Some JavaScript in a Web page that obtains client-specific information using ActiveX.

          <script type="text/javascript">
            var o = new ActiveXObject("WScript.Network");
            var w = new ActiveXObject("WScript.Shell");
            var jsonObject = { "UserName": o.UserName,
              "MyDocuments": w.SpecialFolders("MyDocuments")

The end of the listing contains a statement that starts with var jsonObject. Programmers used to create objects by writing new Object() and referring to the desired properties. The revised syntax above is part of JSON (pronounced Jason), or JavaScript Object Notation. JSON is a lightweight data-interchange format that is a subset of JavaScript. JSON is used in objects and arrays in a highly readable form, and the technology plays in the same space as XML. The statement above creates an object with two properties: UserName and MyDocuments.


Now that you have the tools to configure a browser for ActiveX features and obtain client-specific information, it is up to you to figure out how you are going to use it. To recap JavaScript debugging is enabled automatically when Visual Studio starts an instance of IE8. Security settings like ActiveX support are managed by zone. For local workstation ActiveX support modify the Local Intranet zone. You can choose between enabling ActiveX support or prompting for permission. (I choose the latter, so I turn it off when not needed.) Finally, two of the objects that support discovering client-side information are WScript.Shell and WScript.Network. You can explore the integrated MSDN help for more information.

As a final note JavaScript Object Notation (JSON) was briefly introduced. JSON is subset of JavaScript and is a lightweight data-interchange format. JSON is picking up steam and becoming more popular, so I wedged it into the sample.


Paul Kimmel is the VB Today columnist for www.codeguru.com and has written several books on object- oriented programming and .NET. Check out his upcoming book Professional DevExpress ASP.NET Controls (from Wiley) now available on Amazon.com and fine bookstores everywhere. Look for his upcoming book Teach Yourself the ADO.NET Entity Framework in 24 Hours (from Sams). You may contact him for technology questions at pkimmel@softconcepts .com. Paul Kimmel is a Technical Evangelist for Developer Express, Inc, and you can ask him about Developer Express at paulk@devexpress.com and read his DX blog at http:// community.devexpress.com/blogs/paulk.

Page 2 of 2

This article was originally published on August 27, 2009

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date