40 lines
1.2 KiB
Batchfile
40 lines
1.2 KiB
Batchfile
@echo off
|
|
setlocal enabledelayedexpansion
|
|
|
|
echo Retrieving laptop serial number...
|
|
|
|
:: Gebruik een aparte map in de root als uitvoerlocatie
|
|
set "output_dir=%~dp0..\output"
|
|
:: Maak de output map aan als deze niet bestaat
|
|
if not exist "!output_dir!" mkdir "!output_dir!"
|
|
echo Uitvoerlocatie: !output_dir!
|
|
|
|
:: Get the serial number using PowerShell instead of WMIC
|
|
for /f "delims=" %%a in ('powershell -command "(Get-WmiObject -Class Win32_BIOS).SerialNumber"') do (
|
|
set "serial=%%a"
|
|
)
|
|
|
|
:: Remove any spaces from the serial number
|
|
set "serial=!serial: =!"
|
|
|
|
:: Check if serial number was found
|
|
if "!serial!"=="" (
|
|
echo Error: Could not retrieve serial number.
|
|
exit /b 1
|
|
)
|
|
|
|
:: Get the hostname
|
|
set "hostname=%COMPUTERNAME%"
|
|
|
|
:: Create a text file with HOSTNAME_SERIAL as the filename
|
|
set "filename=!hostname!_!serial!.txt"
|
|
echo Serial Number: !serial! > "!output_dir!\!filename!"
|
|
echo Computer Name: !hostname! >> "!output_dir!\!filename!"
|
|
echo Date: %DATE% >> "!output_dir!\!filename!"
|
|
echo Time: %TIME% >> "!output_dir!\!filename!"
|
|
|
|
echo Serial number !serial! has been saved to !output_dir!\!filename!
|
|
echo.
|
|
echo Script completed successfully.
|
|
pause
|
|
endlocal |