Get the computer Serial Number

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Jbcom41
Posts: 3
Joined: 20 Jun 2021 02:36

Get the computer Serial Number

#1 Post by Jbcom41 » 20 Jun 2021 07:41

Hi Folks

This is my first time here, hello all :) - I have a batch login script that works really well, but I am trying to find out how to get the serialnumber of the PCs within my network using the wmic bios get serialnumber cmd but I am not sure how to implement this into my script, please see script below:

Code: Select all

set ip_address_string="IPv4 Address"
for /f "usebackq tokens=2 delims=:" %%f in (`ipconfig ^| findstr /c:%ip_address_string%`) do (
@(Echo Event,Date,Time,Device,User,IP & Echo Login,%DATE%,%TIME:~0,8%,%COMPUTERNAME%,%USERNAME%,%%f))1>%RANDOM%.csv
goto :eof  
My Script produces the following output: Event,Date,Time,Device,User,IP
Login,20/06/2021,11:27:44,LT6880,testuser, 192.168.0.86


If possible could I incorporate the wmic bios get serialnumber in my script so I could get the following output: Event,Date,Time,Device,User,IP,SN
Login,20/06/2021,11:27:44,LT6880,testuser, 192.168.0.86,Bsuggesting 4P4MW2


If anyone could point me in the correct direction that would be much appreciated. Also this is a login script by adding the wmic bios get serialnumber to the script will this slow down the login? - open for suggesting other than wmic bios get serialnumber cmd.

Many Thanks

John

aGerman
Expert
Posts: 4198
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Get the computer Serial Number

#2 Post by aGerman » 20 Jun 2021 08:44

This line will define a %SerialNumber% evironment variable:

Code: Select all

for /f "delims=" %%i in ('wmic bios get serialnumber /value') do for /f "delims=" %%j in ("%%i") do set "%%j"
Steffen

Jbcom41
Posts: 3
Joined: 20 Jun 2021 02:36

Re: Get the computer Serial Number

#3 Post by Jbcom41 » 20 Jun 2021 09:40

Thanks Steffen, that work a treat - do you know if the wmic bios get serialnumber will slow down users logging in and will this always display the Serial number of the PC, I mean will there be some manufacturers that do not abide by the wmic bios get serialnumber? thanks again Steffen much appreciated.

John

aGerman
Expert
Posts: 4198
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Get the computer Serial Number

#4 Post by aGerman » 20 Jun 2021 11:03

Well, "bios" is the WMIC alias for the "Win32_BIOS" class.
https://docs.microsoft.com/en-us/window ... win32-bios
Scroll down to the description of the SerialNumber member. If there was any limitation you would usually find it (something like "This property is not supported before Windows version ..."). I can't see anything like that though. However, I can't tell if there are any vendors out there who don't even provide a serial number.

On very old and slow machines I found that the WMIC command took a few hundred milliseoconds longer than other commands. On my (still comparatively slow) ~2 years old Win 10 laptop it's not relevant anymore. (Unless you query a class which takes ages to collect the data anyway.)

Steffen

Jbcom41
Posts: 3
Joined: 20 Jun 2021 02:36

Re: Get the computer Serial Number

#5 Post by Jbcom41 » 20 Jun 2021 15:02

Thanks steffen...

Post Reply