Hacker News new | ask | show | jobs
by ronjouch 3517 days ago
So annoying, yes. I since uninstalled GeForce Experience and replaced update notifications (the only feature I was using) with this ugly batch script. Careful, it's ugly! Botched stackoverflow-oriented batch brogramming! But it works for me! Feel free to reuse and improve :)

    @ECHO OFF
    setLocal EnableDelayedExpansion

    rem nvup.bat, a quick & dirty driver downloader since GeForce Experience requires a login.
    rem In a folder with write permissions, drop the script and its two dependencies:
    rem  - jq: https://stedolan.github.io/jq/
    rem  - curl: https://curl.haxx.se/
    rem For automation, just create a Scheduled Task that runs when you want it (I like on Resume).
    rem Reuse / modify / redistribute at will.

    rem http://stackoverflow.com/questions/19131029/how-to-get-date-in-bat-file
    for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
    set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
    set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
    set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%"
    set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"
    echo lastCheck: "%fullstamp%" > lastCheck.log

    rem to get the update feed for your device/OS combo, go to http://www.geforce.com/drivers
    rem , pick your device/os, pop the "Network" tab of your devtools, start the driver search,
    rem and copy the url
    curl --silent -o rawNv.json "http://www.geforce.com/proxy?..."

    for /f "delims=" %%i in ('jq ".IDS[0].downloadInfo.DownloadURL" rawNv.json') do set lastUrl=%%i

    set /p installedUrl=< installedUrl.txt

    if %installedUrl%==%lastUrl% (
      echo same version, quitting
      exit /B
    ) else (
      echo new version, updating
      echo %lastUrl% > installedUrl.txt
      pushd C:\Users\YOURUSERNAME\Downloads
      %~dp0\curl -O %lastUrl%
      popd
      rem http://stackoverflow.com/questions/774175/show-a-popup-message-box-from-a-windows-batch-file
      mshta "javascript:alert('New driver');close()"
    )
4 comments

Here's a less ugly PowerShell version of your script that doesn't have any external dependencies and compares the version of the currently installed driver with the latest (non-beta) driver on NVIDIA's website.

  $URI = 'http://www.geforce.com/proxy?proxy_url=http%3A%2F%2Fgfwsl.geforce.com%2Fservices_toolkit%2Fservices%2Fcom%2Fnvidia%2Fservices%2FAjaxDriverService.php%3Ffunc%3DDriverManualLookup%26psid%3D101%26pfid%3D815%26osID%3D57%26languageCode%3D1078%26beta%3D0%26isWHQL%3D1%26dltype%3D-1%26sort1%3D0%26numberOfResults%3D10'
  $Download = (Invoke-WebRequest $URI | ConvertFrom-Json | Select -ExpandProperty IDS)[0].downloadInfo.DownloadURL
  
  # Installed driver version (21.21.13.7570) > NVIDIA driver version (375.70)
  [Version]$Driver = (Get-WmiObject Win32_PnPSignedDriver | Select DeviceName, DriverVersion, Manufacturer | Where { $_.Manufacturer -eq "NVIDIA" -and $_.DeviceName -like "*GeForce GTX*" }).DriverVersion
  [Version]$CurrentDriver = ("{0}{1}" -f $Driver.Build,$Driver.Revision).Substring(1).Insert(3,'.')
  
  # Latest driver on NVIDIA's website
  [Version]$LatestDriver = ([System.Uri]$Download).Segments[-2].Trim('/')
  
  If ($CurrentDriver -lt $LatestDriver) {
      Write-Output "New driver available"
      Start-BitsTransfer -Source $Download -Destination "$env:USERPROFILE\Downloads"
      (New-Object -ComObject WScript.Shell).Popup("New NVIDIA driver downloaded",0,"Update")
  } Else {
      Write-Output "Same version. Nothing to download"
  }
Improvements welcome. :)
Thanks. I hesitated reaching for PowerShell because, although it looks solid, I'm not familiar with it. Even at work, I was automating part of a Windows build last week, and used batch :-/

So I have a few questions to you or knowledgeable PS-passersby:

1. Any recommendations to get started with PowerShell? Good documentation, tooling, linters, useful packages?

2. Are there remaining cases where it's impossible or unreasonable to use PowerShell rather than Batch or VBScript?

3. PS runs on Win≄XP, right? How does the language evolve / is it versioned? If so, which version should I target?

1. Start with the ISE, comes with windows. If you can't find it "C:\Windows\System32\WindowsPowerShell\v1.0\powershell_ise.exe" Otherwise VSCode with a plugin is nice but you miss some intellisense magic the ise can do.

1a. with powershell as an administrator run `Update-Help` That's all the help for the commands installed and up to date from online. Get-help <command> and don't forget to use wildcards `get-help get-*` will show every single get command you can run. Get-Verb will show what you should expect things to be called. `Get-module -listAvailable` worth looking at too. Tab complete is your friend.

1b. This and the advenced one are great although quite slow; https://mva.microsoft.com/en-us/training-courses/getting-sta...

2. No? Maybe stuff that's already fine or where working out the signing policy is a hassle.

3. Powershell is wrapped into the "Windows Management Framework" you can install. WMF 5 has PS 5, can install down to Windows 7. 7 shipped with PS 2.0 where you could write cmdlets in powershell itself, before that you had to use C++ and visual studio. PS3.0 is the minimum it's really pleasant to use but 2.0 support isn't crazy.

1. Try this: https://web.archive.org/web/20120103141402/http://powershell...

2. Not really. Worst case, you can batch & co.

3. Probably v2.

Off-Topic: While looking through your script I noticed the `jq' dependency. I went to install it and in the docs it mentioned this thing called chocolatey [0], which is like homebrew for windows, and seems pretty amazing :)

Thank you for sharing your work with us!

[0] https://chocolatey.org/

Be aware that even if you manually installed the driver in the first place and have never had GFE installed, Windows Update will helpfully install GFE for you if you let it update the driver.
Sadly, that doesn't allow use of shadowplay.

There are some older versions of nvidea experience floating around that still work with shadowplay without the login.

If you're on Windows 10, the built in games recorder is pretty fantastic, I prefer it over Shadowplay. Of course, a lot of people trying to avoid telemetry are probably still avoiding Windows 10.
Use OBS instead.
Shadow play has that record last X minutes feature that OBS doesn't I think
OBS does, OBS studio doesn't.

It's replay buffer where you start the replay buffer and it will keep the last n seconds of footage in a buffer. You set a keybind to save that buffer to file.

https://obsproject.com/forum/resources/obs-classic-how-to-us...