Somehow can I get the MAC address? - nsis

I'd like to write the MAC address in a txt file.
I have tried this:
FileOpen $4 "$PROGRAMFILES64\OpenVPN\config\auth.txt" w
###;here filewrite and the MAC address
FileWrite $4 "client"
FileClose $4
Could someone help a bit?

There is the IpConfig plugin that can help you with GetNetworkAdapterMACAddress but you need to know the adapter from which you want the MAC. The get MAC address from IP example could help you.

Related

How to request plain HTTP from a website using Inetc

Haya, at the moment im trying to solve a problem in my code regarding a SendRequest error since i believe the website im using (https://www.gnu.org/licenses/gpl-3.0.txt) is not being validated as having a correct certificate by inetc or something close to this - i read here (https://stackoverflow.com/a/26893754/11718125) that to fix this i could use plain http.
how could i go about doing this?
The answer you linked to is old, INetC now supports a /WEAKSECURITY switch.
To use plain HTTP, just change the https: part in the URL to http:. This does not work everywhere, some servers might force a redirect to HTTPS.
This works for me:
Section
InitPluginsDir
inetc::get /WEAKSECURITY /SILENT "https://www.gnu.org/licenses/gpl-3.0.txt" "$PluginsDir\License.txt" /END
ClearErrors
FileOpen $1 "$PluginsDir\License.txt" r
IfErrors 0 +2
Abort "No file?"
loop:
FileRead $1 $2
IfErrors +3
DetailPrint $2
Goto loop
FileClose $1
SectionEnd

How to check the space in the drive by taking the path from the Destination Folder When installing the software using NSIS

How to check the space in the drive by taking the path from the Destination Folder When installing the software.
I am able to check the space of the specific drive (for eg, "C") using the below code snippet.
But I want to take the drive or path from the Destination folder dynamically and check the space of the drive whether there is enough space or not.
!define sysGetDiskFreeSpaceEx 'kernel32::GetDiskFreeSpaceExA(t, *l, *l, *l) i'
function CheckSpaceFunc
IntCmp $2 0 ignorequota
; obey quota
System::Call '${sysGetDiskFreeSpaceEx}(r1,.r2,,.)'
goto converttokb
; ignore quota
ignorequota:
System::Call '${sysGetDiskFreeSpaceEx}(r1,.,,.r2)'
converttokb:
; convert the large integer byte values into managable kb
System::Int64Op $2 / 1024
Pop $2
; check space
System::Int64Op $2 > $0
Pop $2
functionend
Section "TestApp"
SectionIn RO
StrCpy $0 40000 ; kb u need
StrCpy $1 'c:' ; check drive c: for space
Call CheckSpaceFunc
IntCmp $2 1 okay
MessageBox MB_OK "Error: Not enough disk space"
okay:
SectionEnd
Could anyone please help me
The built-in directory page (Page Directory or !insertmacro MUI_PAGE_DIRECTORY) will perform the free space check for you and takes care of all the details.
It might be tempting to just do StrCpy $1 $InstDir 3 to get the drive letter and perform the check yourself but this can give you the wrong result because NTFS supports mounting other volumes as a folder.
GetDiskFreeSpaceEx does support directory paths but I believe the path has to exist so if you want to use $InstDir before $InstDir has been created then you must chop off subfolders until GetDiskFreeSpaceEx succeeds (or you only have a invalid drive letter left of the path).
Your !define should also be changed from GetDiskFreeSpaceExA to GetDiskFreeSpaceEx because it uses the t string type. This will make it Unicode compatible.

NSIS AccessControl::GrantOnFile permission failing

I am trying to create and set a directory with NSIS and the accessControl plugin like the following:
CreateDirectory "$APPDATA\${productName}"
; create fileResources directory
CreateDirectory "$APPDATA\${productName}\fileResources"
AccessControl::GrantOnFile "$APPDATA\${productName}\fileResources" "Everyone" "FullAccess"
Pop $0 ; get "Marker" or error msg
StrCmp $0 "Marker" Continue
MessageBox MB_OK|MB_ICONSTOP "Error setting access control for $APPDATA\${productName}\fileResources: $0"
Pop $0 ; pop "Marker"
Continue:
Pop $0
I am receiving the following on $0 what is that response?
I want to make a folder readable and writable by the installed program
I'm guessing that you are building a Unicode installer using NSIS v3 and that you put the wrong plugin in the plugins subdirectory, that is why the result looks chinese.
To install a plugin correctly you need to put the ANSI .dll in NSIS\Plugins\x86-ansi and the Unicode .dll in NSIS\Plugins\x86-unicode.

get hard disk drive name in which windows OS installed using NSIS

I need to get hard disk drive letter like C: or D: or any in which the OS is installed on any windows.
Kindly help me get out of this.
Section
StrCpy $0 $sysdir 3
DetailPrint $0
SectionEnd
$SYSDIR is the Windows system directory (usually C:\Windows\System or C:\WinNT\System32, but that's detected at runtime).
StrCpy has the syntax StrCpy user_var(destination) str(source) [maxlen] [start_offset] where maxlen and start_offset are optional.
So the code above, copies the first three letters from $SYSDIR into the $0 variable.

How to get system drive volume serial number

I am building a setup which requires to retrieve the disk volume of the drive on which the Operating system is installed. I have tried the following code:
Function ShowDiskVolumeSerialNumber
!define GetVolumeInformation "Kernel32::GetVolumeInformation(t,t,i,*i,*i,*i,t,i) i"
System::Call '${GetVolumeInformation ("$0",,${NSIS_MAX_STRLEN},.r0,,,,${NSIS_MAX_STRLEN})'
IntFmt $0 "%08X" $0
MessageBox MB_OK $0
FunctionEnd
I call the above function by specifying the desired drive:
StrCpy $0 "C:\"
Call ShowDiskVolumeSerialNumber
The above gives the volume no of c:\ drive. However if my OS is installed on d:\ or e:\ it will not work. I want a function which will automatically detect the drive on which the OS is installed and retrieve its volume no.
Secondly, the volume number retrieved is without a hyphen (e.g. 349620C1). I need the volume serial number retrieved as 3496-20C1.
Could someone please give a complete NSIS function when will do both the things i.e:
Automatically detect the drive on which the OS is installed and retrieve its serial no with a hyphen in between.
To get the OS drive, StrCpy $0 $windir 3 is probably enough (You did not specify if you wanted the boot volume or the system volume, on most systems they are the same so $windir is a good starting point)
To edit the serial number:
StrCpy $0 $serial 4
StrCpy $serial $serial "" 4
StrCpy $serial "$0-$serial"

Resources