Serial number grab using vba

elwood2083

New Member
Joined
Nov 7, 2014
Messages
2
<br>
Halito!<br>
<br>
I am attempting to find a code that will grab the serial number of the pc and insert into cell A1. I have found the below code and it works, but it requires you to enter the name of the computer you need serial from, then displays serial in message box. I just want it to grab the serial of the machine its run on and paste to cell A1<br>
<br>
This code does work by the way and is accurate (BY THE WAY, IM NEW AT THIS, IAM SURE YOU CAN TELL)<br>
<br>
On Error Resume Next<br>
<br>
Dim System<br>
<br>
If Wscript.Arguments.Count > 0 Then<br>
sSystem = Wscript.Arguments(0)<br>
<br>
End If<br>
<br>
ComputerName = InputBox("Enter the name of the computer you wish to query")<br>
<br>
winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//" & ComputerName & ""<br>
<br>
Set SNSet = GetObject(winmgmt1).InstancesOf("Win32_BIOS")<br>
<br>
For Each SN In SNSet<br>
<br>
MsgBox "The serial number for the specified computer is: " & SN.SerialNumber<br>
<br>
Next<br>
<br>
End Sub<br>
<br><br type="_moz">
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi and welcome to the MrExcel Message Board.

Try setting the computer name to a full stop.

e.g.
Code:
ComputerName="."
 
Upvote 0
I actually finally figured it out. Used the below code. Thanks Tho!


Range("A1").Select

On Error Resume Next
Dim System

ComputerName = Environ$("computername")
winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//" & ComputerName & ""
Set SNSet = GetObject(winmgmt1).InstancesOf("Win32_BIOS")
For Each SN In SNSet

Selection = SN.SerialNumber
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,650
Messages
6,126,017
Members
449,280
Latest member
Miahr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top