Archive: get disk volume serial number


get disk volume serial number
  Hi,

Is there a built-in function to get disk volume serial number in NSIS? I know InstallShield has one.


Thanx!


Use the System plug-in to call Windows API.


Go with GetVolumeInformation


hi,
i found that quite old topic about getting volume serial number. that's what i'm also interested in. The problem is that starter of this thread didn't post a solution and i have no experiences with msdn. i analysed some similar examples and put something together that looked quite like it should (to me). but....
here it is(PS. again, i have never used msdn...forgive me my dumb mistakes!)

Function GetVolumeInformation

strcpy$3 c
System::Call '${GetVolumeInformation}(i *r3, *r2,i 20, *r4, *r5, *r6, *r7,i 20) i r4'
>dumpstate::debug
functionend
>
so some help is needed here. please edit this system::call line and explain why this should not be the way i wrote. huge tnx for any help.


define GetVolumeInformation 

>"Kernel32::GetVolumeInformation(t,t,i,i,i,i,t,i) i"

>System::Call '${GetVolumeInformation}("C:\\",,255,.r0,,,,255)'
The code returns the result to $0. Replace "C:\" with the volume you want to know (include the backslash "\").

tnx,
but it returns always 0 as serial number($0) no matter weather i choose c:\ or d:\ which are partitions of one HD or e:\ which is sepparate HD.
i expected that this serial number is at least 5 characters and sertainly not 0.


!define GetVolumeInformation 

>"Kernel32::GetVolumeInformation(t,*t,i,*i,*i,*i,t,i) i"

>System::Call '${GetVolumeInformation}("C:\\",,${NSIS_MAX_STRLEN},.r0,,,,${NSIS_MAX_STRLEN})'
Sometimes I get confused when putting "pointers". Now probably the code is right. The result is returned as a decimal integer.

Up
  Is anyone know this?


The code is in the post above yours!!

-Stu


hello,
Thank you for your information,



Name "test"
OutFile "test.exe"

!include MUI.nsh

Section
Call GetDiskVolumeSerialNumber
IntFmt $0 "%08X" $0
MessageBox MB_OK "$0"
SectionEnd

Function GetDiskVolumeSerialNumber
!define GetVolumeInformation "Kernel32::GetVolumeInformation(t,t,i,*i,*i,*i,t,i) i"
System::Call '${GetVolumeInformation}("$0",,${NSIS_MAX_STRLEN},.r0,,,,${NSIS_MAX_STRLEN})'
FunctionEnd


My code is not working,
Can you help me!
So Make an Example of Me,
thanks in advance!!!

hello!!


You changed the example code that was provided.

Which disk are you trying to get the serial number from?


no i have not changed the code, i have picked up the Function from here: http://nsis.sourceforge.net/Get_Disk...Serial_Number, and i want to get a permanent serial from the computer which is installing this program, and i want this in order for it to be clear that only one person is using this program. it is not important where this serial has come from, but only when he is installing the program, the serial would not change if the windows is changed. and please give us an example about how we can get this serial. i have asked my previous question, please read it again to understand it fully what i want to do.thank you very much, do not forget the example, by the way.
the question: http://forums.winamp.com/showthread....99#post2421499


You haven't set anything to $0 before calling GetDiskVolumeSerialNumber, that may be the problem.

Section
StrCpy $0 "C:\"
Call GetDiskVolumeSerialNumber
IntFmt $0 "%08X" $0
MessageBox MB_OK "$0"
SectionEnd

You'll find that section works now.

Hi all,

the code works fine for me so far.
My trouble is that I need the Volume Serial in decimal format.

Example of my drive c:
E079E09B (NSIS is reporting right)
in decimal: 3766083739 (I don't get this value from NSIS).

I tried:

Section
StrCpy $0 "C:\"
Call GetDiskVolumeSerialNumber
IntFmt $0 "%08X" $0
IntFmt $0 "%d" $0 <---------- tried this
MessageBox MB_OK "$0"
SectionEnd

I guess it's a noob question but I can't figure out how to it displayed in decimal. My code above results in 0 instead of 3766083739

Thanks in advance for your help!


use format %u instead of %d


StrCpy $0 0xE079E09B
IntFmt $1 "%u" $0
MessageBox MB_OK "$0 -> $1"


result:

---------------------------
Name Setup
---------------------------
0xE079E09B -> 3766083739
---------------------------
OK
---------------------------

Thanks a lot for your quick answer!


no prob... I do have to admit that %u was a total guess (unsigned int?)... I haven't the foggiest where there's a reference for IntFmt that actually lists all the Format strings.

Edit: A-ha.
wsprintf -> http://msdn.microsoft.com/en-us/library/ms647550.aspx

Might be nice to include that (either a link -or- the reference as it stands) in the help file -_-


Anyone know how this could be edited to display Volume Label instead of Volume Serial Number?


Nevermind, I got it.
In case anyone else is interested, here is the code:

Name "GetVolumeName"
OutFile "GetVolumeName.exe"
!include MUI.nsh

Section
StrCpy $1 "C:\"
Call GetDiskVolumeName
MessageBox MB_OK "$1 $0"
SectionEnd

Function GetDiskVolumeName
System::Alloc 1024
Pop $0
!define GetVolumeInformation "Kernel32::GetVolumeInformation(t,t,i,*i,*i,*i,t,i) i"
System::Call '${GetVolumeInformation}("$1",.r0,1024,,,,,1024)' ;
FunctionEnd