Matan L
Matan L

Reputation: 1027

Best way to get a unique id for a machine - NSIS

I wish to create a unique id for a machine using NSIS ,

I did some research accross the web and found out a great solution written in c#

http://www.codeproject.com/Articles/28678/Generating-Unique-Key-Finger-Print-for-a-Computer

Is there some known library/plugin/code that gives me a similar / close result ?

If not, what would be the best way to implement this type of solution?

Upvotes: 0

Views: 1702

Answers (2)

Seki
Seki

Reputation: 11465

There is an example of generating a GUID with NSIS on the wiki (actually 3 successive methods) that does not need external dependancy other than a system dll.

In short, it does not use the system management like the code you mentioned, but directly call the CoCreateGuid() function from ole32.

System accessor: it can automatically pop the stack into the variable you give it, or keep it on the stack

Function CreateGUID
  System::Call 'ole32::CoCreateGuid(g .s)'
FunctionEnd

Helper macro:

!define CreateGUID `!insertmacro _CreateGUID`
!macro _CreateGUID _RetVar
    Call CreateGUID
    !if ${_RetVar} != s
        Pop ${_RetVar}
    !endif
!macroend

Examples:

;${CreateGUID} $0 ; $0 contains GUID (poped from the stack by the macro)

;${CreateGUID} s ; the value is kept on the stack, we pop it ourselves
;Pop $0 ;contains GUID

Upvotes: 2

Daniel N
Daniel N

Reputation: 417

A simple solution would be to compile that code, embed the exe into your installer, and run the exe when your installer is running.

Upvotes: 0

Related Questions