0

I'd like to create a new .reg file and add it to the registry, as suggested in this article.

REGEDIT4
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\IniFileMapping\Autorun.inf]
@="@SYS:DoesNotExist"

It's pretty simple. But I want to script it. I thought I could just use REG ADD, but I'm not sure how to incorporate the @="@SYS:DoesNotExist" part at the end.

1

Create your batch file - e.g. fix.bat - with the following content:

echo REGEDIT4 > fix.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\IniFileMapping\Autorun.inf] >> fix.reg
echo @="@SYS:DoesNotExist" >> fix.reg

Run the batch and it'll create your file with the desired content. You can manually merge the .reg file or you could go one step further and use the batch file to merge the fix.reg file created with the script into Windows Registry:

echo REGEDIT4 > fix.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\IniFileMapping\Autorun.inf] >> fix.reg
echo @="@SYS:DoesNotExist" >> fix.reg
regedit.exe /S fix.reg
  • I appreciate it, but yuck. Is that necessary? Can't I just REG ADD it, or something like that? – tjt263 Nov 29 '18 at 14:29
  • @tjt263 This answer provides a solution based on the way your question is worded. That is, it creates a .reg file and imports that file. – Worthwelle Nov 29 '18 at 16:31
  • what else ya got – tjt263 Nov 29 '18 at 17:19
  • I think LotPings' answer will give you the all-in-one script you seek :) – Kinnectus Nov 29 '18 at 17:37
1

If you once import that key and look it up with REG QUERY,
you'll see that the first @ refers to the default key of type REG_SZ with content @SYS:DoesNotExist.

So to create the key directly with REG ADD use the following batch which as admin rights are required automatically elevates itself (with UAC dropping in):

:: Q:\Test\2018\11\29\SU_1379397.cmd
@echo off & setlocal EnableExtensions DisableDelayedExpansion
:: if not already running as admin, elevate and run batch again
net file 1>nul 2>&1 || (
  powershell -ExecutionPolicy unrestricted -Command ^
  "Start-Process -Verb RunAs -FilePath '%comspec%' -ArgumentList '/c %~f0 %*'"
  goto :eof
)
:: Put code here that needs elevation
@Echo off
Set "Key=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\IniFileMapping\Autorun.inf"
Set "Dat=@SYS:DoesNotExist"
REG ADD "%Key%" /ve /t REG_SZ /d "%Dat%" /f
TIMEOUT /T 10

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.