Skip to main content

Past Blast

Featured Products

Windows Mobile Developer Controls
Windows Mobile Developer Controls
Stay in touch using the DEVBUSS RSS feeds.
 

News

Windows Mobile Developer Controls
Windows Mobile Developer Controls

Access PC information from your Pocket PC

Written by Pete Vickers  [author's bio]  [read 57956 times]
Edited by Derek

Download the code

Page 1  Page 2  Page 3 

Building on my last article (Remote Data Access using the Winsock Control), and taking into account some of the comments in the discussion forum, I decided to investigate using the Winsock control to move XML around, as Chris Tacke suggested.

Although I have loads of TCP/IP experience, XML is a fairly new animal to me (old dog - new tricks!), so I used the article by Jim Poe on DEVBUZZ entitled 'Getting Started with XML in eVB', as well as 'WinCE database application for MS SQL Server 7 using eVB and XML' by Shakil Siraj.

There are probably better ways to handle the XML on the Pocket PC, and I would be pleased if anyone points out the error of my ways in the way I handle the XML. If someone with a good knowledge of accessing XML from eVB wants to give us a few more pointers, I am sure we would all be grateful, as information appears to be fairly thin on the ground.

The project is based on the RDA article, and involves getting PC info from the server, formatting the XML, passing it to the client, and formatting it. Once again, we will be using the Winsock control.

The Server

The server is based on the RDA server from my last article, and all the comments about the winsock control still apply. The server will accept a connection, and accept a 'function', and act upon it accordingly.

The only functions in this case will be 'INFO' and 'CLOS'. The server is listening on port 9898.

When it receives an 'INFO' request, it will gather the following information from the PC.
1) PC name and User name
2) Memory usage statistics
3) Processor Type
4) Operating environment
5) Disc statistics

This will be generated as XML, and then saved to a file. The reasons for saving to a file are:-
1) Calling the load method causes an "Access Denied" error on the Pocket PC
2) We can illustrate how to download a file from the PC to the Pocket PC using Winsock.

The code on the server repeats itself, and makes use of the API, so we will only illustrate 1 piece of info here, i.e. the disc space module.

When we first get the 'INFO' function, we create the XML 'header'

Private Sub Create_XML_Start()
 Set objXMLDoc = CreateObject _
    ("MSXML2.DOMDocument")
 Set objXMLRoot = objXMLDoc.createElement _
    ("PcData")
 objXMLDoc.documentElement = objXMLRoot
 Set objXMLTopic = objXMLDoc.createElement _
   ("PcInfo")
 objXMLDoc.documentElement.appendChild _
   objXMLTopic
End Sub

For the disc space, we do the following:-

Private Sub Disc_Space()
 Dim sDrive As String
 sDrive = Get_All_Drives()
 sDrives = Split(sDrive, ",")
 Dim ict As Integer
 iDrives = UBound(sDrives) - 1
 Dim bSpace As Boolean
 For ict = 0 To iDrives
  Set objXMLTopic = _
   objXMLDoc.createElement("DiscSpace")
   objXMLDoc.documentElement.appendChild _
   objXMLTopic
  dBytesAvailable = 0
  dBytesTotal = 0
  bSpace = Get_Free_Disc_Space _
  (sDrives(ict), dBytesAvailable, dBytesTotal)
  Set objXMLNodes = objXMLDoc.createElement _
   ("DriveLetter")
  objXMLNodes.Text = sDrives(ict)
  objXMLTopic.appendChild objXMLNodes
  Set objXMLNodes = objXMLDoc.createElement _
   ("BytesTotal")
  objXMLNodes.Text = _
   Format(dBytesTotal, "###,###,###,##0")
  objXMLTopic.appendChild objXMLNodes
  Set objXMLNodes = objXMLDoc.createElement _
   ("BytesAvailable")
  objXMLNodes.Text = _
   Format(dBytesAvailable, "###,###,###,##0")
  objXMLTopic.appendChild objXMLNodes
Next
End Sub

For each drive we create elements consisting of the drive letter, total space and the bytes available.

This type of function is followed to get the other data we need, e.g.

uname = Get_User_Name
Set objXMLNodes = objXMLDoc.createElement _
   ("UserName")
objXMLNodes.Text = uname
objXMLTopic.appendChild objXMLNodes

When we have finished, we save the file, and then read it back in to send to the Pocket PC.

Private Sub Write_The_File()
  Dim ifile As Integer
  objXMLDoc.Save "c:\temp\pcinfo.xml"
  ifile = FreeFile
  Open "c:\temp\pcinfo.xml" For Input As ifile
  Sbuff = "INFOOK"
  tcpServer.SendData Sbuff
  While Not EOF(ifile)
    Line Input #ifile, Sbuff
    tcpServer.SendData Sbuff
  Wend
  Close ifile
  Sbuff = "~"
  tcpServer.SendData Sbuff
End Sub

Next Page