|
-
Nov 18th, 2009, 12:27 AM
#1
Thread Starter
Addicted Member
Hard disk serial Key in user account
Hi. I have come across a problem to get Hard disk serial number. I’m googling it from past one week without much joy. I found many solutions. None of them were perfect. The most common problem, which I faced, is that the Hard disk serial number couldn’t be taken without admin permission in Vista. In Microsoft website the api is given which will return the Drive volume serial number. The problem is that once we format the hard disk the drive volume serial number will change. The other option is to use SCSI back door. But it is not available in Vista. The only option remaining is using S.M.A.R.T.. The Smart api doesn’t work properly in VB without admin permission. But it is possible in an exe created in VC++, where they read the hard disk code without admin permission. Is there any other method in VB where the Hard disk serial number and model number can be read?
-
Nov 18th, 2009, 07:54 AM
#2
Fanatic Member
Re: Hard disk serial Key in user account
Take a look at this its a "registration" system based on the users hard drive serial number, written by MartinLiss. You may find that there is something useful in there?
"Wisdom is only truly achieved, when you realise you dont know everything" ... I must be a genius because I always have to ask stupid questions...
Pointing an idiot like me in the right direction, is always appreciated by the idiot, explaining how to do what you have pointed the idiot to, is appreciated even more. I apologise to all experienced coders who will think I am an idiot, you are right, I am an idiot, but I am an idiot who is trying to learn
-
Nov 19th, 2009, 01:24 AM
#3
Thread Starter
Addicted Member
Re: Hard disk serial Key in user account
Thanks for the reply. But the details given there are similar to the Microsoft link provided above. The API returns a long value, which is the drive volume serial number rather than Hard disk manufacturers serial number. It changes from drive to drive and also after formatting the hard drive volume number will change. The manufacturers serial number doesn’t change even after we format the hard disk.
-
Nov 19th, 2009, 05:08 AM
#4
Fanatic Member
Re: Hard disk serial Key in user account
ah, Im sorry I couldnt help at all with that, have you seen THIS thread? post 14 specifically?
"Wisdom is only truly achieved, when you realise you dont know everything" ... I must be a genius because I always have to ask stupid questions...
Pointing an idiot like me in the right direction, is always appreciated by the idiot, explaining how to do what you have pointed the idiot to, is appreciated even more. I apologise to all experienced coders who will think I am an idiot, you are right, I am an idiot, but I am an idiot who is trying to learn
-
Nov 20th, 2009, 12:08 AM
#5
Thread Starter
Addicted Member
Re: Hard disk serial Key in user account
Thanks for the post. Yes, i did read it. The post 14 you told gives us the volume serial number of a drive which will change while formatting. The other posts also link to some codes but they will not work in Vista having UAC. it needs admin permission. which will not be available some times.
-
Nov 20th, 2009, 04:27 AM
#6
Fanatic Member
Re: Hard disk serial Key in user account
I will be honest I am not the best programmer, so please forgive me If I seem a little knowledgeless!
Does it work with UAC turned off?
If so I found THISthread, I dont know if it will be of any help. but after looking it up, apparently microsoft has set UAC up in such a way that it is very difficult for any 3rd party applications to disable the feature, or bypass it. However from what I have read, people have generated "injected dll's" (if that is the correct phrase) in which they can bypass UAC (I think thats moreso in .net) or turn UAC off.
Last edited by JayCR; Nov 20th, 2009 at 04:53 AM.
"Wisdom is only truly achieved, when you realise you dont know everything" ... I must be a genius because I always have to ask stupid questions...
Pointing an idiot like me in the right direction, is always appreciated by the idiot, explaining how to do what you have pointed the idiot to, is appreciated even more. I apologise to all experienced coders who will think I am an idiot, you are right, I am an idiot, but I am an idiot who is trying to learn
-
Nov 20th, 2009, 05:45 AM
#7
Re: Hard disk serial Key in user account
i tested this as standard user in vista
vb Code:
Set WMIObjectSet = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\CIMV2").ExecQuery("SELECT * FROM Win32_DiskDrive") For Each WMIObject In WMIObjectSet MsgBox "hard drive " & WMIObject.Index & ": serialnumber " & WMIObject.signature Next Set WMIObjectSet = Nothing
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 20th, 2009, 05:46 AM
#8
Thread Starter
Addicted Member
Re: Hard disk serial Key in user account
Actually the problem is not just in Vista. It comes in XP also if the user does not have admin previllages (user account-Limited user). The thing is that I have a source code of a C++ exe where they will take it without admin previllages. This website gives a Dll which will fetch the Hard disk serial number. But the problem is the license. I cant use it in the software as the license is not compatible with it. Even if i purchase it, I cant redistribute the dll with my software. So i thought if there might be another solution where DLL can be used and redistributed.
-
Nov 20th, 2009, 05:49 AM
#9
Thread Starter
Addicted Member
Re: Hard disk serial Key in user account
Thanks for the post westconn1. WMI has certain problems in Vista. I already tried the solution and failed. Read this PDF for more details.
-
Nov 20th, 2009, 06:02 AM
#10
Re: Hard disk serial Key in user account
i tested this on an almost new vista (home premium) installation with no problem for a standard user
and also on an older vista basic system
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 21st, 2009, 01:45 AM
#11
Thread Starter
Addicted Member
Re: Hard disk serial Key in user account
Unfortunately the very first vista (home basic) I tried it had failed. So when I googled I got that pdf. Thanks for the reply. Is there any other method to get it?
-
Nov 21st, 2009, 05:39 PM
#12
Re: Hard disk serial Key in user account
check this thread in codebank
http://www.vbforums.com/showthread.p...+serial+number
may need modification to run in vista
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 23rd, 2009, 02:04 AM
#13
Thread Starter
Addicted Member
Re: Hard disk serial Key in user account
It doesnt work in Vistal or in XP without admin permission. As it is concerned with registration i cant take the risk where the HD code is available for one user and not available for the other. I want to use this code for all my softwares which i will develop in future also.
The problem in the code is that the createfile api used requires admin permission. So if there is any other code to avoid create file and instead pass any other handle to the DeviceIoControl api it'll be very helpful. Thanks in advance.
-
Nov 23rd, 2009, 02:41 AM
#14
Re: Hard disk serial Key in user account
Haven't seen the options given but won't using GetVolumeInformation API do the trick?
Code:
Private Declare Function GetVolumeInformation Lib "kernel32.dll" Alias "GetVolumeInformationA" ( _
ByVal lpRootPathName As String, _
ByVal lpVolumeNameBuffer As String, _
ByVal nVolumeNameSize As Long, _
lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, _
lpFileSystemFlags As Long, _
ByVal lpFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long) As Long
Private Sub Command1_Click()
Dim volname As String ' receives volume name of C:
Dim sn As Long ' receives serial number of C:
Dim snstr As String ' display form of serial number
Dim maxcomplen As Long ' receives maximum component length
Dim sysflags As Long ' receives file system flags
Dim sysname As String ' receives the file system name
Dim retval As Long ' return value
' Initialize string buffers.
volname = Space(256)
sysname = Space(256)
' Get information about the C: drive's volume.
retval = GetVolumeInformation("C:\", volname, Len(volname), sn, maxcomplen, _
sysflags, sysname, Len(sysname))
' Remove the trailing nulls from the two strings.
volname = Left(volname, InStr(volname, vbNullChar) - 1)
sysname = Left(sysname, InStr(sysname, vbNullChar) - 1)
' Format the serial number properly.
snstr = Trim(Hex(sn))
snstr = String(8 - Len(snstr), "0") & snstr
snstr = Left(snstr, 4) & "-" & Right(snstr, 4)
' Display the volume name, serial number, and file system name.
Debug.Print "Volume Name: "; volname
Debug.Print "Serial Number: "; snstr
Debug.Print "File System: "; sysname
End Sub
-
Nov 23rd, 2009, 03:55 AM
#15
Thread Starter
Addicted Member
Re: Hard disk serial Key in user account
Sorry. Thats the drive volume serial number. The problem with that is that it will change if you format the hard disk. So i will have to genearate the key again and give it. The manufacturers Hard disk Serial number will not change.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|