Create registry key using variable in batch file 2008r2

command-line-interfaceinternet explorerwindows-server-2008-r2

I would like to create a new registry key to add the current computer name to the internet explorer trusted sites in windows 2008r2 x64

My server is called "MyServerName"
in a batch file if I type echo %hostname% it return MyServerName
but in the registry command it doesnt work it create the key using "%hostname%" instead of "MyServerName"

Here is the command I tried :

reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\EscDomains\%hostname%" /v http /t REG_DWORD /d 00000002 /f

I would expect the key to be created to look more like this:

HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\EscDomains\MyServerName"

Any help would be appreciated, I tried digging to find info on how to do this but couldn't find anything that would solve my problem.

In case you wonder, we have an application that needs to run locally and use the server hostname to access a website and apparently for IE MyServerName is different from localhost even if localhost is already in the trusted site.

Best Answer

There is a system binary C:\windows\system32\hostname.exe, but Windows doesn't have an Environment Variable %HOSTNAME%

C:\> set | FIND /I "HOSTNAME"
<no results>

Perhaps you mean to use %COMPUTERNAME% instead?

C:\> set | FIND /I "COMPUTERNAME"
COMPUTERNAME=SRV1