Read and write to the registry
- Last UpdatedJul 24, 2024
- 1 minute read
In a script, you can use OLE to read from and write to the Windows registry by:
-
Creating an OLE object based on the Windows class Wscript.Shell.
-
Using the RegRead() and RegWrite() methods of the OLE object.
For example, these commands read the installed version of the InTouch HMI directly from the registry key and store the value in the rkey message tagname:
OLE_CreateObject(%WS,"Wscript.Shell");
rkey = %WS.RegRead("HKLM\SOFTWARE\Wonderware\InTouch\Installation\Version");
These commands write the value 1 to the registry key that determines if file extensions are hidden for the currently logged on user:
OLE_CreateObject(%WS,"Wscript.Shell");
%WS.RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt",1,"REG_DWORD");