I recently ran into a problem while trying to write a DWORD registry value using the RegWrite method in a VBScript. When I tried to write the value “2705144907” I received the error message:

Microsoft VBScript runtime error: Overflow

The script syntax I was using is shown below.

set oShell = Wscript.CreateObject("Wscript.Shell")

oShell.RegWrite "HKCU\SOFTWARE\Test\HexValue", 2705144907, "REG_DWORD"


What causes this problem? The RegWrite method uses the Long type variable. The Long variable is an integer in the range of -2,147,483,648 to 2,147,483,647. Since the value I am trying to add in my script (2,705,144,907) is outside this range the script will fail with the Overflow error.

So how can you write a value that is outside this range? All you have to do is convert the value from decimal to hexadecimal and use hexadecimal value in the script.

Step 1. Convert your variable from decimal to hexadecimal

  1. Open Windows Calculator
  2. Click on View and select Programmer
  3. On the left panel ensure Dec is selected
  4. Enter your value
  5. Click on Hex in the left panel
  6. Make note of the value.

This value is your hexadecimal variable. In this example 2705144907 becomes A13D3C4B.

Step 2. Enter the hexadecimal value into your script.

Note: When entering a hexadecimal variable in a VBScript you must add the &H prefix. If you do not add the &H prefix you will receive a Type mismatch error. Therefore our final variable should be set to &HA13D3C4B.

The final working script:

set oShell = Wscript.CreateObject("Wscript.Shell")

oShell.RegWrite "HKCU\SOFTWARE\Test\HexValue", &HA13D3C4B, "REG_DWORD"