Click here to Skip to main content
Click here to Skip to main content
Go to top

How to get mobile information using VBScript

, 28 May 2009
Rate this:
Please Sign up or sign in to vote.
An easy way to get mobile model number, vendors, screen size etc.

Introduction

This article will show you basic user agent / mobile capabilities (mobile model, vendors etc.,) profiling using simple VBScript.

Background

I created a WAP application for getting information about mobile hand set models and their vendors and store it in a simple text file. At first, I decided to create an application using Java, but the problem is that people need to download and install the application; finally, I decided to create a simple WML encoding ASP page.

Using the code

We will now discuss about the ways you can store the handset models and their vendors. At first, I would like to show you the basic UAProfile attribute fetching routine where I use Msxml2.dll, and it has no internal dependencies. The sample code is given below:

'Function GetValue(): used for HTTP POST/Get and XML parsing 

Function GetValue(ByVal url, ByVal name)

//###############################################
// Author: Md. Marufuzzaman
// Basic UapProfile attribute fetching routine
// Internal Dependencies: None
// !!! Mother of all UAP Routines
// ###############################################

    On Error Resume Next
    Dim http
    Dim document
    Dim namespaces
    Dim node
    Dim xpath

    Set http = Server.CreateObject("Msxml2.XMLHTTP")
    http.Open "GET", url, False
    http.Send
    
    
    If http.Status <> "200" Then
         GetValue = Nothing
         Exit Function
    End If

    Set document = Server.CreateObject("Msxml2.DOMDocument")
    document.async = False
    document.validateOnParse = False
    document.resolveExternals = False
    document.load http.responseBody

    If document.parseError.errorCode <> 0 Then
         GetValue = Nothing
         Exit Function
    End If
         
    document.setProperty "SelectionLanguage","XPath"
    xpath = "//*[local-name() = '" & name & "']"

    Set node = document.selectSingleNode(xpath)

    If Not node Is Nothing Then
         GetValue = node.Text
    Else
         GetValue = Nothing
    End If

    Set document = Nothing
    Set http = Nothing


End Function

'Function GetWidth(): Get mobile screen width

Function GetWidth()
//##################################################
// Author: Md. Marufuzzaman
// Gets the Screen Height of the Mobile screen 
// !!! Local Function Defendencies:              
// GetValue()                                 
// Revision:                                
//##################################################

    profile=replace(Request.ServerVariables("HTTP_PROFILE"),chr(34),"")
    xwapprofile=replace(Request.ServerVariables("HTTP_X_WAP_PROFILE"), _
                        chr(34),"")
    profileurl=    profile
    if profile= "" then
         vProf = split(xwapprofile,",")
         profileurl= vProf(0)
    end if
        
            
    //-----------------------------------------------------------
    retval = GetValue(profileurl,"ScreenSize")
    if retval <> "" then
        screenpara = split(retval,"x") //ok 
        GetWidth= screenpara(lbound(screenpara)) //OK
    else
        GetWidth= 144 //<------- the default width
    end if
    //-----------------------------------------------------------

End Function


'Function GetHeight(): Get mobile screen height

Function GetHeight()

//##################################################
// Author: Md. Marufuzzaman
// Gets the Screen Height of the Mobile screen //
// !!! Local Function Defendencies:              //
// GetValue()                                 //
// Revision:                                //
//###########################################
            
    profile=replace(Request.ServerVariables("HTTP_PROFILE"),chr(34),"")
    xwapprofile=replace(Request.ServerVariables("HTTP_X_WAP_PROFILE"), _
                        chr(34),"")
    profileurl=    profile
    if profile= "" then
         vProf = split(xwapprofile,",")
         profileurl= vProf(0)
    end if
    
    //-----------------------
    retval = GetValue(profileurl,"ScreenSize")
    
    if  retval <> "" then
        screenpara = split(retval,"x") //ok 
        GetHeight=screenpara(ubound(screenpara))
    else
        GetHeight= 176 //<---- the default height 
    end if
    //--------------

End Function

'Function Is_PDA(): Return true if the request from Windows PDA browser.

Function Is_PDA()

//###############################################
// Author: Md. Marufuzzaman
// Detect Windows CE/OS PDA
// // ###############################################

    Dim varUAProfile
    Dim varArray
    Dim variCounter
                            
    varUAProfile = Request.ServerVariables("HTTP_USER_AGENT")
    
    varUAProfile = varUAProfile & " #"    
    varArray = split(varUAProfile, " " )
        
    variCounter = 0

        while varArray(variCounter) <> "#"
            
            if ucase(varArray(variCounter)) = "WINDOWS" OR _
               ucase(varArray(variCounter+1)) = "CE" then

                Is_PDA = True
                Exit Function
            else
                Is_PDA = False
            end if
            
            variCounter = variCounter + 1
        wend
End Function

'Function HandSetMode(): Get the device model and the vendors 
'                        and store into a text file.

Function HandSetMode ()
//###########################################
// Author: Md. Marufuzzaman                   
// Revision:                               
//##########################################


  Dim fs,fname
  Dim varVendor,varHandSetModel,varData
  Dim varProf,varWapProfile
  Dim varProfile 
    
  varProfile=replace(Request.ServerVariables("HTTP_PROFILE"),chr(34),"")
  varWapProfile=replace(Request.ServerVariables("HTTP_X_WAP_PROFILE"),chr(34),"")

  profileurl = varProfile

    if varProfile= "" then
        varProf = split(varWapProfile,",")
          profileurl=varProf(0)
    end if        
    
    varVendor= ucase(GetValue(profileurl,"Vendor"))
    varHandSetModel= ucase(GetValue(profileurl,"Model"))
        
    varData = "Vendor:-" & varVendor & ", HandSet_Model # " & _
              varHandSetModel & ", UAProf:" & profileurl & _
              ", TimeStamp # " & Now()

    set fs=Server.CreateObject("Scripting.FileSystemObject")
    set fname=fs.OpenTextFile(Server.MapPath("HandSetList.txt"),8,true)
    // 8 = ForAppending

    fname.WriteLine(varData)

    fname.Close
    
    set fname=nothing
    set fs=nothing

End Function

Sample code of ASP page with WML encoding:

// Include the header file UAProfiling.in (VBScript files)

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" 
   "http://www.wapforum.org/DTD/wml_1.1.xml">

<wml>
<card id="profileview" title="Mobile Capabilities">

<p align="center">

<%

' Call the VBScript function

%>

</p>
</card>
</wml>

In thr above function GetValue(), I create two objects:

  1. Msxml2.XMLHTTP, used for the HTTP GET.
  2. Msxml2.DOMDocument, used for the XML parsing.

Conclusion

I hope that it might be helpful to you. Enjoy!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Md. Marufuzzaman
CEO
Bangladesh Bangladesh
A highly experienced leader with successful track record of software development, product innovations, brand management and corporate communication etc. Some successful product innovations have also achieved and awards “Most Valuable Professional” (MVP) at 2010 and 2011 by codeproject.com and also selected as a mentor of codeproject.com. Published over 100 technical articles in various software development resource sites (i.e., codeprojetc.com, Microsoft MSDN, and IEEE & IBM (In progress)) and various IT Forums, Blogs etc.
 
Over ten years of professional experiences in ICT field having extensive experience in formulating corporate vision and long term strategy. Leading development related functions including design, development, services, data management and analytics, customer experience management, content services, digital analytics and optimization.
 
An individual with results-driven approach and relentless in pursuit of excellence from a business and organizational standpoint. Believes in transparency, commitment and teamwork.
 
Expertise: Software/Solution Architect, SaaS platform base application, Large scale win32/web based business software solutions, enterprise applications, integration, etc.
 
Technologies/Tools: Microsoft.Net version 05/08/10/12, Microsoft SQL Server version 7/2K/05/08/12 , Oracle version 10/11, MySql version 5.1, 5.5, PS2, Visual C#, R, VB.NET, ASP.NET, PHP, API, MVC, WebAPI , Add-In Visual Basic etc.,. I have also more than two years’ of strong experience in mobile-VAS (platform development).
 
Points of Interest: Technology and research & development especially focused on business functionalities and social business areas as well, few stuff including:
 
1.R&D on new techniques as required to increase business revenue.
2.Urban and rural sectors to improve people’s lifestyle, better medical facilities, education, social business etc., using innovative technical solutions.
3.Research and innovative product development.
4.Etc.
Follow on   Twitter   LinkedIn

Comments and Discussions

 
GeneralMy vote of 5 PinmemberAbdul Quader Mamun14-Aug-12 15:27 
GeneralMy vote of 5 PinmemberMd. Salah Uddin Salim19-Dec-11 1:09 
GeneralRe: My vote of 5 PinmemberAbdul Quader Mamun14-Aug-12 15:27 
Please read my newly posted article and Plz comments or vote.
A Framework for Software Application[^]

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140921.1 | Last Updated 28 May 2009
Article Copyright 2009 by Md. Marufuzzaman
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid