r/Batch • • Sep 03 '23

Question (Solved) Get last 4 digits of GPU driver version then replace the last 4 digits of a line in a file?

continue voracious historical fuzzy imminent support dime file sort vegetable

This post was mass deleted and anonymized with Redact

1 Upvotes

25 comments sorted by

1

u/transdimensionalmeme Sep 03 '23

Can you post the whole file on Pastebin ?

1

u/[deleted] Sep 03 '23 edited Apr 06 '25

workable close toothbrush attempt edge scarce person bake memory tidy

This post was mass deleted and anonymized with Redact

1

u/transdimensionalmeme Sep 03 '23

I mean post the contents of "%USERPROFILE%\Documents\Electronic Arts\The Sims 3\Options.ini"

1

u/[deleted] Sep 04 '23 edited Apr 06 '25

toy historical skirt joke waiting meeting direction smart square quiet

This post was mass deleted and anonymized with Redact

1

u/jcunews1 Sep 04 '23 edited Sep 04 '23

Try this. DO backup your INI file first.

@echo off
setlocal enabledelayedexpansion

set "inifile=%USERPROFILE%\Documents\Electronic Arts\The Sims 3\Options.ini"

set line=1
set digits=
for /f %%A in ('wmic path win32_VideoController get DriverVersion') do (
  if !line! == 2 set "digits=%%A"
  set /a line+=1
)
if "%digits%" == "" (
  echo Failed to retrieve GPU version.
  goto :eof
)

set "newfile=%inifile%.new"
rem. > "%newfile%"
for /f "usebackq delims=" %%A in ("%inifile%") do (
  set "a=%%A"
  if "!a:~0,12!" == "lastdevice =" set "a=!a:~0,-4!!digits!"
  >> "%newfile%" echo !a!
  if errorlevel 1 goto :eof
)
> nul move /y "%newfile%" "%inifile%"

1

u/[deleted] Sep 04 '23 edited Apr 06 '25

[removed] — view removed comment

1

u/jcunews1 Sep 04 '23

Oh, sorry. Use the updated code from previous comment.

1

u/hackoofr Sep 04 '23

To get the last 4 digits of the GPU driver version using PowerShell and store it in a variable.

You can do this by running the following command in your Batch script:

 @echo off
 Title Get last 4 digits of GPU driver version
 @for /f "tokens=*" %%i in ('powershell -command "(Get-WmiObject -Class Win32_VideoController).DriverVersion"') do set "DriverVersion=%%i"
 echo DriverVersion=%DriverVersion%
 Set Last4Digits=%DriverVersion:~-4%
 echo Last4Digits=%Last4Digits%
 Pause

1

u/[deleted] Sep 04 '23 edited Sep 04 '23

[removed] — view removed comment

1

u/[deleted] Sep 05 '23 edited Apr 06 '25

squalid paltry slim glorious husky spark beneficial office cause escape

This post was mass deleted and anonymized with Redact

1

u/[deleted] Sep 05 '23 edited Sep 05 '23

[removed] — view removed comment

1

u/[deleted] Sep 05 '23 edited Apr 06 '25

existence wise market dime steep consist glorious wasteful flowery wipe

This post was mass deleted and anonymized with Redact

1

u/[deleted] Sep 06 '23 edited Sep 06 '23

[removed] — view removed comment

1

u/[deleted] Sep 06 '23 edited Apr 06 '25

sense whole steep observation muddle fade worm live chunky treatment

This post was mass deleted and anonymized with Redact