[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Need VB script to check APC UPS status

Posted on 2008-06-18
18
Medium Priority
?
2,409 Views
Last Modified: 2013-12-20
He there all, i need a script (VB) to check APC UPS status. I have found some PHP scripts but i need it to be in VBscript.  I have found a wmi server called uninteruptablepowersuply but this doesn't return any values.

I already have a large script for checking systemspecs and want to ad this to it, so please no wscript.echo but StrHtmL. (HTML output)
0
Comment
Question by:Dutchict
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
  • 2
18 Comments
 
LVL 5

Expert Comment

by:Devario Johnson
ID: 21812936
Will a .pl work?  All you have to do is install it on the machine

http://www.deadcat.net/viewfile.php?fileid=65


if you send me the php version I can convert it to ASP for you

Post it here on EE
0
 

Author Comment

by:Dutchict
ID: 21812992
Hi, thanks for this script, it does what i want.. but i'd like it to be in my VB script so the output can go in thesame HTML.  Do you know about executing Perl in VB?  
0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21813694
The Win32_UninterruptiblePowerSupply class is dropped as of Windows Vista.  It also only works with serial UPS, not USB, so isn't that useful.  I am just checking for the USB equivalent.  I am 80% sure that there will be a pure VB solution for this.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 5

Expert Comment

by:Devario Johnson
ID: 21813739
JMSSupport

If you post the PHP version you found I may be able to convert it to ASP for you...
0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21816500
The attached script returns the battery status on my laptop.  It should theoretically work on a server with connected batteries too... but my test has failed (though I am not sure if the USB lead of the UPS is plugged into the server, which could explain it).

Could you try this on a server with UPS to see if it works for that?  If so, there are many more properties I can add to the output.
dim colBatteries, objBattery
strComputer="."
 
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\CIMV2")
 
Set colBatteries = objWMIService.ExecQuery _
    ("Select * from Win32_Battery")
 
strHTML=strHTML & vbCrLF & vbCrLf & "<br/><br/>Battery Information<br/>" & vbCrLf
	 
for each objBattery in colBatteries
	strHtml=strHTML & "Battery status: " & BatteryStatusInfo(objBattery.BatteryStatus) & vbCrLf & "<br/>"
	strHtml=strHTML & "Description: " & objBattery.Description & vbCrLf & "<br/>"
	strHtml=strHTML & "Estimated runtime (minutes): " & objBattery.EstimatedRunTime & vbCrLf & "<br/>"
	strHtml=strHTML & "Status: " & objBattery.Status  & vbCrLf & "<br/>"
	strHtml=strHTML & "Time To Full Charge (minutes): " & objBattery.TimeToFullCharge & vbCrLf & "<br/>"
	strHtml=strHTML & "Estimated Charge Remaining: " & objBattery.EstimatedChargeRemaining & vbCrLf & "<br/><br/>"
next
 
wscript.echo strHTML
	 
 
function BatteryStatusInfo(intBatteryStatus)
	dim strStatus
	select case intBatteryStatus
		case 1: strStatus="Battery is discharging"
		case 2: strStatus="System is on AC power"
		case 3: strStatus="Battery is fully charged"
		case 4: strStatus="Battery is low"
		case 5: strStatus="Battery is critical"
		case 6: strStatus="Battery is charging"
		case 7: strStatus="Battery is charging and high"
		case 8: strStatus="Battery is charging and low"
		case 9: strStatus="Battery is charging and critical"
		case 11: strStatus="Battery is partially charged"
		case else: strStatus="Unknown"
	end select
	BatteryStatusInfo=strStatus
		
end function

Open in new window

0
 

Author Comment

by:Dutchict
ID: 21819692
Thanks, i will test this today!
0
 

Author Comment

by:Dutchict
ID: 21916382
Hi there again! Just back from holiday and wedding and stuff :)

This script checks batteries, but not the UPS... i found this script in the CIMV2 base also.
Maybe someone has another solution?
0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21916397
The problem is that the other relevant WMI sections are deprecated.. and won't work on future versions of Windows.  I'll look into it again...
0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21916429
I can rewrite some code to use Win32_UninterruptiblePowerSupply - but this relies on the UPS service.  If the UPS service isn't available, it will fail.  Also, it is not supported in Vista or Windows 2008.  Is this an issue?
0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21916444
Oh, and apparently that only works with serial attached devices, not USB.
0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21916494
Out of interest... when you tested the script, how was the UPS connected?

According to what I've read, the above script should work for batteries connected by USB - including a UPS.  I will be at a site installing a USB UPS tomorrow, so I can check then, but I was just wondering what you tested on.
0
 

Author Comment

by:Dutchict
ID: 21916618
Hi there purplepomegranite,

The ups's are mostly serial  atached (bigger APC) and works with SMTP traps
I have tried to look for scripts but coudn't find any.

The most of our servers are win2003 / win2003 2/ win2000 etc
We will be adding 2008 servers soon, as customers are wanting the new technology

0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21917865
Ok, I'll write a script later that uses the above query, should work with serial attached UPS.
0
 

Author Comment

by:Dutchict
ID: 21923084
wow, if you where a girl and pretty you would get a big sloppy kiss! lol
anywayz, thanks in advance!
0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21924725
The script already posted does work with servers with a USB UPS attached.  Have just tried it against an APC UPS.

So we just need the other script for legacy devices.  Will post it in a while (probably this evening).
0
 
LVL 24

Accepted Solution

by:
purplepomegranite earned 2000 total points
ID: 21931524
The attached code should work with serial attached devices (so long as the UPS service is running).
dim colUPS, objUPS
strComputer="."
 
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\CIMV2")
 
Set colUPS = objWMIService.ExecQuery _
    ("Select * from Win32_UninterruptiblePowerSupply")
 
strHTML=strHTML & vbCrLF & vbCrLf & "<br/><br/>UPS Information<br/>" & vbCrLf
         
for each objUPS in colBatteries
        strHtml=strHTML & "Battery status: " & objUPS.Status & vbCrLf & "<br/>"
        strHtml=strHTML & "Description: " & objUPS.Description & vbCrLf & "<br/>"
        strHtml=strHTML & "Estimated runtime (minutes): " & objUPS.EstimatedRunTime & vbCrLf & "<br/>"
        strHtml=strHTML & "Status: " & objUPS.Status  & vbCrLf & "<br/>"
        strHtml=strHTML & "Estimated Charge Remaining: " & objUPS.EstimatedChargeRemaining & vbCrLf & "<br/><br/>"
next
 
wscript.echo strHTML

Open in new window

0
 

Author Comment

by:Dutchict
ID: 21931593
Hi purplepomegranite, thanks again! will test this today, here are the point..
0
 

Author Closing Comment

by:Dutchict
ID: 31468243
Thanks again! Hope you also like my scripts till now :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

656 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