Easily connect to an RDP shadow session. https://sagino-alchemia.org
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Generate_csv.bat 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. :: Output filename
  4. set "output_file=allowed_pcs.csv"
  5. echo [INFO] Extracting session information...
  6. :: 1. Get the Computer Name
  7. set "pc_name=%COMPUTERNAME%"
  8. :: 2. Get the current Username and Session ID
  9. :: Using 'query user' for more stable output parsing compared to qwinsta
  10. set "found=false"
  11. for /f "skip=1 tokens=1,2,3" %%i in ('query user %USERNAME%') do (
  12. :: %%i = Username, %%j = SessionName or ID, %%k = ID or State
  13. :: Check if the 2nd column is a number (Session ID)
  14. echo %%j | findstr /r "^[0-9][0-9]*$" >nul
  15. if not errorlevel 1 (
  16. set "user_name=%%i"
  17. set "session_id=%%j"
  18. ) else (
  19. :: If 2nd column is SessionName (e.g., console), ID is in the 3rd column
  20. set "user_name=%%i"
  21. set "session_id=%%k"
  22. )
  23. :: Remove the ">" prefix from the username if present
  24. set "user_name=!user_name:>=!"
  25. set "found=true"
  26. )
  27. if "%found%"=="false" (
  28. echo [ERROR] Could not identify active session.
  29. pause
  30. exit /b
  31. )
  32. :: 3. Prompt user for a description
  33. set /p desc="Enter a description for this PC (e.g. Sales-Desktop): "
  34. :: 4. Output to CSV in append mode
  35. :: Wrapping in parentheses to prevent accidental file redirection issues
  36. (echo %pc_name%,%user_name%,%session_id%,%desc%)>> "%output_file%"
  37. echo.
  38. echo [SUCCESS] Information added to %output_file%
  39. echo Data: %pc_name%,%user_name%,%session_id%,%desc%
  40. echo.
  41. pause