Problem:
The code pasted below is just on add-on to the cobreg demo available on MF WEB Netx sample page; the initial cobreg demo reads & updates registries on the "local" computer.
With the code pasted below, you'll be able to read registry on a remote computer.
cobreg:
Accessing the Windows registry with COBOL and writing or reading information from the registry
Resolution:
use the WIN32 API RegConnectRegistry as pasted below
==========================================================
RegConnectRegistry:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/regconnectregistry.asp
MSDN registry APIs
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/registry_functions.asp
==========================================================
...
working-storage section.
01 ComputerName pic x(100) value z"\\\\NameOfTheRemoteComputer".
01 result long.
...
*->> _____________________________________________________________
*> read registries on a remote PC
call winapi "RegConnectRegistryA"
using by reference ComputerName
by value HKEY-LOCAL-MACHINE
by reference Result
returning lretVal
end-call
if lretVal = ERROR-SUCCESS
display "Call to WIN32 API RegConnectRegistry OK"
else display "Call to WIN32 API RegConnectRegistry KO"
if lretval = 53
display "Microsoft bug: 194928 "
*> BUG: RegConnectRegistry on Windows NT Returns ERROR_BAD_NETPATH
*> http://support.microsoft.com/default.aspx?scid=kb;en-us;194928
end-if
end-if
call Winapi RegOpenKeyEx using
by value Result
by reference
z"SOFTWARE\\Micro Focus\\Net Express\\4.0\\cobol\\"
by value 0
by value KEY-ALL-ACCESS
by reference hKey
returning lRetVal
end-call
if lretVal = ERROR-SUCCESS
display "Call to WIN32 API RegOpenKeyEx OK"
else display "Call to WIN32 API RegOpenKeyEx KO"
end-if
move length of key-buffer to key-length
call winapi RegQueryValueEx using
by value hkey
by reference z"VersionYVA"
by value 0
by reference key-type
by reference key-buffer
by reference key-length
returning lRetVal
end-call
if lretval = ERROR-SUCCESS
if key-type = REG-SZ
display "A String has been returned"
end-if
display "Value = " key-buffer(1:key-length)
display "Key Size= " key-length
else display "Key not found on remote computer"
end-if
.
perform CloseKey
stop run.
...