Jump to content

Dell Battery Replacement Script Help Required

Recommended Posts

I don't know if you have seen the news today about Dell recalling millions of laptop batteries. Article can be found here:


I have been tasked with writing a script that will determine if the PC/Laptop is Windows XP as I think WMI is only installed on WinXP and above, (might be wrong)

If it is WinXP, it will then launch a vbs script that will collect information such as:

I need to put a check for checking if machine is a laptop or desktop, if laptop continue running script, if desktop quit. (any assistance with this appreciated)



OS Caption

OS Version

Laptop Manufacturer

Laptop Model

Battery Manufacturer

Battery Name

Battery Device ID

All of this information is outputted to a file called %computername%.txt and thn a copy of this file is made to %Temp%

I am having a problem where if the vbscript is run once and the %computername%.txt file doesn't already exisit, I get a permission denied error. (It creates the .txt file, but doesn't enter any information). However if I then run the vbscript again with the .txt file already created, it works fine. Can someone tll me what I am doing wrong cos it is really bugging me.

It hasn't been decided how this script is going to b launched yet, but I am 99% certain it will be kicked off by Kix login scripts. Is there a way for th batch file that Kix launches to determine whether or not machine is laptop or desktop? I think there is a WMI command line engine, but can't remember exactly.

Once we have collected all these %computername%.txt files accross the council, we then would like to import all of these files into 1 csv file. From this file we will then try and determine exactly what customrs need to be contacted to arrange replacement battries. I can't beleive there isn't a solution for this from Dell. I know they have a webpage, but that relies on the person having access to the internet. I was hoping that a WMI script could find out the serial number of the battery, but it appears not to drill down that far.


Link to comment
Share on other sites

The problem we have got is that there are over 5000 users and we don't know exactly who has and where th laptops are located.

I know you can't get the battery serial number through WMI, but you can gather information that will allow you to cut down the amount of machines that may need replacement. Thats the idea of this script.

I would much rather go round 200 users to see if they need a replacement, rather than 5000+. It should save a lot of time running this script, I really just want to know, why I have to run it twice to get the text file to populate.

Link to comment
Share on other sites

Hi Kev, I've had a quick glance at the script code (quick as I'm a little ill today and don't want to do any head work ;)). From what I can see the problem is when your checking for the file to exist.

' Check that the strFile Fileexists
If objFSO.FileExists(strDirectory & strFile) Then
Set objFile = objFSO.GetFile(strDirectory & strFile)
Set objFile = objFSO.CreateTextFile(strDirectory & strFile, True)
End If

Your checking for the file to exist... if it exists it connects to the file, if it doesnt exist it creates the file... and that's it. It doesnt connect to it once its created the file.

I could be wrong though :| like i said I'm not at 100% today :)

Link to comment
Share on other sites

Thanks for the feedback. Especially if you aren't feeling 100%.

I have just finished off restructuring the .vbs file. I have followed the same structure that GSM used in the oeminfo.ini post. All credit goes to GSM. You the Man!! :thumbup

I am not 100% sure what in the attached file has fixed the error with it not writing the information to file the 1st time round, so if anyone can explain to me for future reference that would be good.

I just need to add a check in the vbs file that determines whether it is a laptop or not. If System=Laptop then continue else end script. I will repost when I have worked this out.

Change attachment to .vbs


Link to comment
Share on other sites

This may help you figure out what type of computer it is.

strComputer = "."
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colChassis = objWMI.ExecQuery("Select * from Win32_SystemEnclosure")
For Each objChassis in colChassis
For Each objItem in objChassis.ChassisTypes
If objItem = 3 Then
Wscript.Echo "Desktop"
End If
If objItem = 9 Then
Wscript.Echo "Laptop"
End If

Here is a Link for more information

Link to comment
Share on other sites

  • 2 weeks later...

It doesn't return the full serial number, but does get enough digits to match against the recall listing that Dell have published. I have tried it on known good and bad batteries that I have and it works fine for me.

As an extra, here is a list of the objects and some example outputs from the WMI PortableBattery class. The Name object has the 5 digits that need to be matched, else you could just match the manufacturer against Sony and then escalate up your support process as required. PS this was a good battery!



CapacityMultiplier: 10

Caption: Portable Battery

Chemistry: 2



CreationClassName: Win32_PortableBattery

Description: Portable Battery

DesignCapacity: 52170

DesignVoltage: 11100

DeviceID: Portable Battery 0








Location: Sys. Battery Bay


Manufacturer: Panasonic

MaxBatteryError: 2


Name: DELL 4M010 4




SmartBatteryVersion: 1.0



SystemCreationClassName: Win32_ComputerSystem

SystemName: PC2141



Link to comment
Share on other sites

Thats similar to how we are doing it at work. I will post my final code tomorrow as I have been off work.

Basically we obtain the information and write details of the laptop where the battery may need replacing and output this to a text file on a network share. We then a simple batch file to merge out that information into 1 csv file, where we can then search for make of battery first and then the model number if WMI gets this info. We found that there was a few laptops, i think the Latitude X300 where WMI didn't return anything regarding model number.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.

  • Create New...