The inevitable question: Get Computer ID

MSingh
3StarLounger
Posts: 366
Joined: 12 May 2010, 06:49

The inevitable question: Get Computer ID

Post by MSingh »

Hi,

How can i get the unique computer id?

My program makes extensive use of userforms, so a
user cannot utilise it without enabling macros.

I have searched but cannot seem to find code
to get compid. There are lots of cautionary
notes around this.

Thanking you
Mohamed

User avatar
HansV
Administrator
Posts: 78471
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: The inevitable question: Get Computer ID

Post by HansV »

What exactly do you mean by "unique computer ID" and what would you use it for - I don't see the connection to enabling macros.
Best wishes,
Hans

MSingh
3StarLounger
Posts: 366
Joined: 12 May 2010, 06:49

Re: The inevitable question: Get Computer ID

Post by MSingh »

Hi Hans,

Sorry for the late reply...

I attempting to safeguard .xlsm from piracy, workbook open event would verify computer id against the id obtained from the end-user before distribution (perhaps that's the incorrect term, maybe pc serial number) whichever is unique to each pc.
This unique number to be stored & compared each time .xlsm is opened, if it doesn't match, then give msg & close workbook.
Becoz workbook can only be used with userforms macros has to be enabled.

I should have described such in first post.

Thanks
Mohamed

User avatar
HansV
Administrator
Posts: 78471
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: The inevitable question: Get Computer ID

Post by HansV »

You can use the following code to get the computer's serial number:

Code: Select all

Function GetSerial() As String
  Dim strComputer As String
  Dim objWMIService As Object
  Dim colSMBIOS As Object
  Dim objSMBIOS As Object
  strComputer = "."
  Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
  Set colSMBIOS = objWMIService.ExecQuery _
    ("Select * from Win32_SystemEnclosure")
  For Each objSMBIOS In colSMBIOS
    GetSerial = objSMBIOS.SerialNumber
  Next objSMBIOS
End Function
The user can get the serial number from the service tag on the PC, or you could give them the .vbs file in the attached zip file; when opened from Windows Explorer it will display the serial number.
GetSerial.zip
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

MSingh
3StarLounger
Posts: 366
Joined: 12 May 2010, 06:49

Re: The inevitable question: Get Computer ID

Post by MSingh »

Thanks Hans,

Thats awesome. I only accessed the post now & see 35 downloads already.

You should start charging for this service!

Kindest regards
Mohamed

User avatar
HansV
Administrator
Posts: 78471
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: The inevitable question: Get Computer ID

Post by HansV »

MSingh wrote:You should start charging for this service!
Hi Mohamed,

The idea behind Eileen's Lounge is a free exchange of information, we're not trying to make money.
Best wishes,
Hans

kpark91
StarLounger
Posts: 61
Joined: 29 Jul 2010, 14:52

Re: The inevitable question: Get Computer ID

Post by kpark91 »

HansV wrote:
MSingh wrote:You should start charging for this service!
Hi Mohamed,

The idea behind Eileen's Lounge is a free exchange of information, we're not trying to make money.
That's the best part of it all lol, joking :P

I'm really amazed by your range of knowledge in computers O_o
I don't have one