• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2446
  • Last Modified:

Need VB script to check APC UPS status

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
Dutchict
Asked:
Dutchict
  • 9
  • 7
  • 2
1 Solution
 
Devario JohnsonSoftware EngineerCommented:
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
 
DutchictAuthor Commented:
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
 
purplepomegraniteCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Devario JohnsonSoftware EngineerCommented:
JMSSupport

If you post the PHP version you found I may be able to convert it to ASP for you...
0
 
purplepomegraniteCommented:
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
 
DutchictAuthor Commented:
Thanks, i will test this today!
0
 
DutchictAuthor Commented:
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
 
purplepomegraniteCommented:
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
 
purplepomegraniteCommented:
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
 
purplepomegraniteCommented:
Oh, and apparently that only works with serial attached devices, not USB.
0
 
purplepomegraniteCommented:
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
 
DutchictAuthor Commented:
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
 
purplepomegraniteCommented:
Ok, I'll write a script later that uses the above query, should work with serial attached UPS.
0
 
DutchictAuthor Commented:
wow, if you where a girl and pretty you would get a big sloppy kiss! lol
anywayz, thanks in advance!
0
 
purplepomegraniteCommented:
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
 
purplepomegraniteCommented:
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
 
DutchictAuthor Commented:
Hi purplepomegranite, thanks again! will test this today, here are the point..
0
 
DutchictAuthor Commented:
Thanks again! Hope you also like my scripts till now :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 9
  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now