Skip to main content
August 3, 2011
Answered

Querying hardware data

  • August 3, 2011
  • 4 replies
  • 1202 views

Hello,

Im wondering is there a tag or some special method available in Coldfusion to access certain data about servers, for example if I wanted to query a server on my network to retrive and output a list of logical drive letters is that possible?

I cant see anything that can do that in the CGI variables list.

Thanks for any help.

This topic has been closed for replies.
Correct answer LyndonPatton

Something like this?

<cfset drivesToCheck='c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z'>
<cfset drivesOnServer=''>
<cfloop from="1" to="#ListLen(drivesToCheck)#" index="i">
<cfdirectory action="LIST" filter="*" name="getDrives" directory="#ListGetAt(drivesToCheck,i)#:\">
<cfif getDrives.RecordCount>
  <cfset drivesOnServer=ListAppend(drivesOnServer,ListGetAt(drivesToCheck,i))>
</cfif>
</cfloop>

<cfoutput>
#drivesOnServer#
</cfoutput>

4 replies

August 11, 2011

Hi, Thank you all for advising me, using a mixture of all your

suggestions I came up with an acceptable solution. here is the code if anyone is intereted. Its the only way ive been able to dynamicaly work out the drives on a remote server then check the space statistis. I know its not the most elegant way, ive tried using the .NET object method which seems to return the best info without having to guess drives but for the life of me I couldnt get it to work. Im intrested in the WMI method but i`ll have a play around with that when I get more time.

<!---Get list of servers from active directory--->
<cfldap
  server = "dc01.domain.com"
  action = "query"
  name = "serverName"
  start = "dc=domain,dc=com"
  scope="subtree"
  filter="(objectclass=computer)"
  attributes = "cn"
  sort = "cn ASC"
  username="username"
  password="password">
 
<!--- Set drive letters to check--->
<cfset drivesToCheck = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z'>

<cfoutput query="serverName">
#cn#
</cfoutput>
<p>

<!---Loop through all the drive letters and match them to drives on the server--->
<cfloop list="#drivesToCheck#" index="i">

<cfoutput>
 
  <p>
  <!---The java object returns drive space data--->
  <cfset fileOb = createObject("java", "java.io.File").init("\\#ServerName.cn#.domain.com\#i#$")>
  <!---Test to see if its a physical hard drive by making sure its maximum size isnt '0' if the server has a CD in its drive unfortunately it will be displayed to--->
  <cfif fileOb.getTotalSpace() GT '0'>
   <p>
   #i#
   <p>
   freespace=#fileOb.getFreeSpace()#<br>
   usablespace=#fileOb.getUsableSpace()#<br>
   totalspace=#fileOb.getTotalSpace()#<br>
   <p>

   <!---Set the hard drive space statistics--->
   <cfset usablespace = #fileOb.getUsableSpace()#>

   <cfset totalspace = #fileOb.getTotalSpace()#>
  
   <cfset usedspace = #fileOb.getTotalSpace()# - #fileOb.getUsableSpace()#>
  
   <!---Display the results in form of a pie chart--->
   <cfchart format="flash"
     chartheight="400"
     chartwidth="400"
     showxgridlines="yes"
     showygridlines="yes" 
     scalefrom="0"
     scaleto="10"
     title="HD Space"
     show3d="yes" showlegend="yes">
    
      <cfchartseries type="pie">
     
       <cfchartdata item="Free Space" value="#usablespace#">
       <cfchartdata item="Used Space" value="#usedspace#">
  
      </cfchartseries>
   </cfchart>
 
   <p>
 
  </cfif>
</cfoutput>

</cfloop>

Thanks for your help people :-)

Owainnorth
Inspiring
August 4, 2011

Rather than guessing what drives a machine has, use createObject("java", "Java.IO.File") to get the info on a drive (iirc), or createObject("dotnet", "System.IO.DriveInfo").

Give them a Google, they should have everything you need. Bear in mind the ColdFusion user will need explicit permissions in order to access network drive info.

LyndonPattonCorrect answer
Inspiring
August 3, 2011

Something like this?

<cfset drivesToCheck='c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z'>
<cfset drivesOnServer=''>
<cfloop from="1" to="#ListLen(drivesToCheck)#" index="i">
<cfdirectory action="LIST" filter="*" name="getDrives" directory="#ListGetAt(drivesToCheck,i)#:\">
<cfif getDrives.RecordCount>
  <cfset drivesOnServer=ListAppend(drivesOnServer,ListGetAt(drivesToCheck,i))>
</cfif>
</cfloop>

<cfoutput>
#drivesOnServer#
</cfoutput>

August 8, 2011

Im just wondering, how you would get this code to point to a server across the network, I tried this..

<cfdirectory action="LIST" filter="*" name="getDrives" directory="\\myserver.domain.com\#ListGetAt(drivesToCheck,i)#:\">

I cant get it to work. My CF server has permission to all the required resources on the network.

Inspiring
August 8, 2011

In what way did it not work?

Participating Frequently
August 3, 2011

If the servers are Windows you may want to look into this link regarding WMI.