i need a script for a flash drive that auto-executes and prints out ipv4, pc name, name…
- User
i need a script for a flash drive that auto-executes and prints out ipv4, pc name, name of user,os version
- Assistant
Creating a script that automatically executes from a flash drive (USB) when plugged into a computer is generally restricted by modern operating systems due to security reasons. AutoRun/AutoPlay features are disabled or heavily limited on most current Windows versions to prevent malware spread.
However, I can provide you with a PowerShell script that, when manually run, will print out the IPv4 address, PC name, username, and OS version. You can place this script on your flash drive and run it manually.
PowerShell Script: Get System Info
# Get IPv4 address $ipv4 = (Get-NetIPAddress -AddressFamily IPv4 -InterfaceAlias "Ethernet","Wi-Fi" -ErrorAction SilentlyContinue | Where-Object { $_.IPAddress -notlike "169.*" -and $_.IPAddress -ne "127.0.0.1" } | Select-Object -First 1 -ExpandProperty IPAddress) # Get PC name $pcName = $env:COMPUTERNAME # Get current user name $userName = $env:USERNAME # Get OS version $osVersion = (Get-CimInstance Win32_OperatingSystem).Caption + " " + (Get-CimInstance Win32_OperatingSystem).Version # Print the information Write-Output "IPv4 Address: $ipv4" Write-Output "PC Name: $pcName" Write-Output "User Name: $userName" Write-Output "OS Version: $osVersion"
How to use:
- Save the above script as
Get-SystemInfo.ps1on your flash drive. - Insert the flash drive into the target PC.
- Open PowerShell (preferably as Administrator).
- Navigate to the flash drive, e.g.,
E:\ - Run the script:
.\Get-SystemInfo.ps1
Notes:
- Auto-execution is not recommended and mostly blocked for security reasons.
- If you want to run it automatically, you would need to instruct the user to run the script manually.
- You can create a batch file to launch the PowerShell script for easier execution:
@echo off powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0Get-SystemInfo.ps1" pauseSave this as
RunInfo.baton the flash drive. Double-clicking this batch file will run the PowerShell script.
If you want help with a script for a different OS or more advanced automation, just ask!
- Save the above script as
- User
there is mostly win 7, iirc there is no powershell
- Assistant
You're right! Windows 7 does have PowerShell, but it might not be installed or enabled by default on some systems, especially older or minimal installs. Also, the default PowerShell version on Windows 7 is quite old (v2.0), and some cmdlets like
Get-NetIPAddressare not available.For Windows 7, a batch script combined with some built-in commands and
ipconfigcan work well.
Batch script to get IPv4, PC name, username, and OS version on Windows 7
Save this as
GetSystemInfo.baton your flash drive:@echo off setlocal enabledelayedexpansion :: Get IPv4 address (exclude loopback and IPv6) for /f "tokens=2 delims=:" %%a in ('ipconfig ^| findstr /R /C:"IPv4 Address"') do ( set ip=%%a ) :: Trim leading spaces from IP set ip=%ip:~1% :: Get PC name set pcname=%COMPUTERNAME% :: Get username set username=%USERNAME% :: Get OS version for /f "tokens=4-5 delims=[.] " %%a in ('ver') do ( set osver=Windows %%a.%%b ) echo IPv4 Address: %ip% echo PC Name: %pcname% echo User Name: %username% echo OS Version: %osver% pause
How to use:
- Save the above as
GetSystemInfo.baton your flash drive. - Insert the flash drive into the Windows 7 PC.
- Open Command Prompt.
- Navigate to the flash drive, e.g.,
E:\ - Run the batch file:
GetSystemInfo.bat
Explanation:
ipconfigoutput is parsed to find the IPv4 address line.%COMPUTERNAME%and%USERNAME%are environment variables.vercommand outputs Windows version, parsed to get a simple version string.
Important:
- This script assumes the PC has a single active IPv4 address.
- If multiple network adapters exist, it will pick the first IPv4 address found.
- Auto-run from USB is disabled by default on Windows 7 for security reasons, so manual execution is required.
If you want, I can help you create a more advanced script or a small executable that runs this automatically after user confirmation. Just let me know!
- Save the above as
- User
maybe make the script create a folder like: inv., where it stores text files with this info, and names files after pc name
- Assistant
Sure! Here's an updated batch script for Windows 7 that:
- Creates a folder named
inv.on the flash drive (where the script runs). - Saves the info into a text file named after the PC name (e.g.,
PCNAME.txt). - Appends a timestamp to the file name to avoid overwriting previous files.
- Prints the info to the console as well.
Updated
GetSystemInfo.bat@echo off setlocal enabledelayedexpansion :: Get IPv4 address (exclude loopback and IPv6) set ip= for /f "tokens=2 delims=:" %%a in ('ipconfig ^| findstr /R /C:"IPv4 Address"') do ( set ip=%%a goto :gotIP ) :gotIP :: Trim leading spaces from IP set ip=%ip:~1% :: Get PC name set pcname=%COMPUTERNAME% :: Get username set username=%USERNAME% :: Get OS version for /f "tokens=4-5 delims=[.] " %%a in ('ver') do ( set osver=Windows %%a.%%b ) :: Create folder "inv." if it doesn't exist if not exist inv. ( mkdir inv. ) :: Get timestamp for filename (YYYYMMDD_HHMMSS) for /f "tokens=1-4 delims=/:. " %%a in ("%date% %time%") do ( set datetime=%%c%%a%%b_%%d%%e%%f ) :: Compose filename set filename=inv\%pcname%_%datetime%.txt :: Write info to file ( echo IPv4 Address: %ip% echo PC Name: %pcname% echo User Name: %username% echo OS Version: %osver% ) > "%filename%" :: Also print info to console type "%filename%" echo. echo Info saved to %filename% pause
How to use:
- Save this as
GetSystemInfo.baton your flash drive. - Insert the flash drive into the Windows 7 PC.
- Open Command Prompt.
- Navigate to the flash drive (e.g.,
E:\). - Run the batch file:
GetSystemInfo.bat
What it does:
- Creates a folder
inv.on the flash drive root. - Saves the info in a text file named like
PCNAME_YYYYMMDD_HHMMSS.txt. - Prints the info on screen.
- Pauses so you can see the output.
If you want me to help you make it more robust or add other info, just ask!
- Creates a folder named
- User
maybe for fail-safe, print out every ipv4 that computer has
- Assistant
Got it! Here's an improved version of the batch script that:
- Prints all IPv4 addresses found on the computer (not just the first one).
- Saves all info into a timestamped text file inside the
inv.folder. - Prints the info to the console as well.
Updated
GetSystemInfo.bat(prints all IPv4 addresses)@echo off setlocal enabledelayedexpansion :: Initialize variable to hold all IPv4 addresses set iplist= :: Loop through all IPv4 addresses (exclude loopback 127.0.0.1) for /f "tokens=2 delims=:" %%a in ('ipconfig ^| findstr /R /C:"IPv4 Address"') do ( set ip=%%a set ip=!ip:~1! if not "!ip!"=="127.0.0.1" ( if defined iplist ( set iplist=!iplist!, !ip! ) else ( set iplist=!ip! ) ) ) :: Get PC name set pcname=%COMPUTERNAME% :: Get username set username=%USERNAME% :: Get OS version for /f "tokens=4-5 delims=[.] " %%a in ('ver') do ( set osver=Windows %%a.%%b ) :: Create folder "inv." if it doesn't exist if not exist inv. ( mkdir inv. ) :: Get timestamp for filename (YYYYMMDD_HHMMSS) for /f "tokens=1-4 delims=/:. " %%a in ("%date% %time%") do ( set datetime=%%c%%a%%b_%%d%%e%%f ) :: Compose filename set filename=inv\%pcname%_%datetime%.txt :: Write info to file ( echo IPv4 Addresses: %iplist% echo PC Name: %pcname% echo User Name: %username% echo OS Version: %osver% ) > "%filename%" :: Also print info to console type "%filename%" echo. echo Info saved to %filename% pause
What changed?
- The script now collects all IPv4 addresses (except
127.0.0.1) and joins them with commas. - The output line is now
IPv4 Addresses: <all IPs>. - Everything else remains the same.
Usage:
Same as before — save, run from Command Prompt, and it will create the
inv.folder and save the info.
If you want me to help with anything else, just say!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.