Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Making calls to the Reg_ functions with the open agent and recieve 'Unexpected NULL' error

Making calls to the Reg_ functions with the open agent and recieve 'Unexpected NULL' error

BACKGROUND:

When calling the Reg_() functions using the Silk Test Open agent you may receive an ' Unexpected NULL' error, like so:

[ ] *** Error: Unexpected NULL
[ ] Occurred in RegCreateKeyEx at Registry.inc(397)
[ ] Called from Reg_CreateKey at Registry.inc(109)

The reason for this is that the Reg_ functions cannot be called by the Open agent because the agent does not support the ‘Agent.GetOption (OPT_USE_ANSICALL)' calls in the function.


SOLUTION:

To resolve this issue there are currently several workarounds.

1. Switch to the Classic agent like so.

[ ] Connect("(local)", CLASSIC_AGENT) //connect to Classic agent
[ ] Reg_CreateValue (HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\RunOnce", "Test", "hello")
[ ] Connect("(local)", OPEN_AGENT)//Connect back to Open agent

2. Have SilkTest execute a .reg file to create the value.

a. Create a registry file ( silk.reg) like so

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce]
"Test"="Hello"

b. Create a batch file that executes a .reg file to complete the registry updates. In this example we create a file (silkreg.bat ) as seen below

regedit /s c:\silk.reg


c. Now in your script create a Sys_Execute call that the Open agent will call to create the registry value.

[-] testcase run() appstate none
   [ ] LIST OF STRING lsDirOut
   [ ] SYS_Execute("c:\silkreg.bat", lsDirOut)
   [ ]

This will ensure the a key called 'Test' is created with the value data 'Hello'

3. Open the registry.inc file and comment any references to the Agent GetOption/SetOption calls in the relevant functions as seen below. This will allow the Open Agent to make the calls successfully.


[-] LONG RegCreateKeyEx (LONG hKey, STRING lpSubKey, LONG Reserved, STRING lpClass, LONG dwOptions, LONG samDesired, LONG lpSecurityAttributes, out LONG phkResult, out LONG lpdwDisposition)
[ ] LONG retVal
   [-] // if (Agent.GetOption (OPT_USE_ANSICALL))
     [ ] // Agent.SetOption (OPT_USE_ANSICALL, FALSE)
     [ ] // retVal = RegCreateKeyExW (hKey, lpSubKey, Reserved, lpClass, dwOptions, samDesired,    lpSecurityAttributes, phkResult, lpdwDisposition)
     [ ] // Agent.SetOption (OPT_USE_ANSICALL, TRUE)
  [-] // else
     [ ] retVal = RegCreateKeyExW (hKey, lpSubKey, Reserved, lpClass, dwOptions, samDesired, lpSecurityAttributes, phkResult, lpdwDisposition)
[ ] return retVal

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 21:03
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.