+ Reply to Thread
Results 1 to 6 of 6

Get hard drive serial number

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    927

    Get hard drive serial number

    Hello

    I want to get hard drive serial number

    I use this code, but its give me the serial number starting with big space, like this
    ( SPACE ) 33LDW6PVT
    PHOTO : https://drive.google.com/open?id=1hK...U60ywP0cgKrbSt
    I want it without the space like this
    33LDW6PVT

    what can i do?
    Dim s As String
    Dim itm As Object
    With GetObject("winmgmts:\\.\root\CIMV2")
    For Each itm In .ExecQuery("SELECT * FROM Win32_DiskDrive", , 48)
    s = itm.SerialNumber
    Next itm
    End With
    End Sub
    thanks
    Last edited by Undo; 07-28-2019 at 09:29 AM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,774

    Re: Get hard drive serial number

    Via VBA: https://docs.microsoft.com/en-us/off...trim-functions

    Via Excel: =TRIM(A1)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Get hard drive serial number

    Try
    s = itm.SerialNumber
    Debug.Print Trim(s)
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  4. #4
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    927

    Re: Get hard drive serial number

    thanks all solved

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this …


    An alternative :

    PHP Code: 
    Function FindDiskSerial$(DEV$)
        
    Dim oDisks As ObjectoDisk As Object
        Set oDisks 
    GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select * from Win32_LogicalDisk where DeviceID = '" DEV "'")
        For 
    Each oDisk In oDisks:  FindDiskSerial oDisk.VolumeSerialNumber:  Next
        Set oDisks 
    Nothing
    End 
    Function

    Sub DemoFindDiskSerial()
        
    Debug.Print FindDiskSerial("D:")
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Thumbs up


    Thanks for the rep' !

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Get Hard Drive Serial Number?
    By ern2ern in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-03-2019, 11:28 PM
  2. Serial Number of Drive
    By Jerry in Houston in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-13-2014, 01:32 PM
  3. extract serial number to Hard disc
    By thair in forum Excel General
    Replies: 5
    Last Post: 10-31-2012, 09:23 AM
  4. Macro to unhide sheets IF macro is enabled and hard drive serial # match list of HD#
    By nikolaikolev in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-24-2011, 01:50 PM
  5. Replies: 0
    Last Post: 07-12-2011, 11:30 AM
  6. Replies: 1
    Last Post: 02-29-2008, 02:14 PM
  7. [SOLVED] How do I obtain the drive serial number in EXCEL spreadsheet
    By Paul Ramirez in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-03-2005, 06:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1