WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Registry
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

RegDeleteKey failing from 64bit to 32-bit server

 Keywords: RegDeleteKey 2k 2000 32 64 bit 

Question:

I have an application which connects to a remote server and deletes a registry key using the RegDeleteKey function.

This has worked for a number of years now when run from a 32-bit Windows server to another 32-bit Windows server.

Recently, we've had some 64-bit Windows (2003) servers introduced, and when this same utility was run against them from a 32-bit server, it would not find the key on the remote 64-bit servers because it was looking in the default 64-bit hive... I updated the code to add the RegOpenFlags(1) at the top, which forces the 32-bit registry for all registry calls... this worked fine again.

Now, I am in the position where I need to run this utility from a 64-bit Windows (2003) server against other 32-bit servers, and now the utility fails to delete the key on the remote 32-bit server when run from a 64-bit server (still works fine when run from a 32-bit server). The new server is a Windows2003 Enterprise Server x64 SP1.

I tried updating all the previous RegOpenKey calls to use RegOpenKeyEX with the "FULL" parameter in case I was getting some funky permissions issues now, but this did not help.

When I enable Debug, I can see the following being logged:

RegDelRC = RegDeleteKey(OPConfigKey,StrCat(LCKey,"\Operations\Agent\Event Providers\Application Log")) (9563) VALUE INT => 0

WIL ERROR SUPPRESSED =>1229 (RegDeleteKey: Function Failed)

Immediately before this, I check the key exists and proceed only if it is there.

Note: I can manual delete that key remotely using RegEdit from the 64bit server.

I've tested the following:

  • simplified the code
  • used a much simpler/shorter registry key on the target machine that I want to delete
  • tried the resulting WBT file on several W2K3-SP1 (x64) servers in my environment against various Win2000-SP4 (x86) servers
  • tried all variations of RegOpenFlags() i.e. commented-out, set to 0, 1, 2

And to prove that permissions is not an issue, I tested:

RegCreateKey(OPConfigKey,StrCat(LCKey,"\TestNew"))
TimeDelay(5)
RegDeleteKey(OPConfigKey,StrCat(LCKey,"\TestNew"))
The delete of the newly created key threw the same 1229 error message again.

Incidently, I also tried replacing the RegDeleteKey() function with the lines:

RunCmdStr=StrCat('/c REG DELETE "',strComputerUNC,'\HKLM\',strKeyPath,'\Test\TestNew" /f')
Pause("RunCmdStr",RunCmdStr)
Run("CMD.EXE",RunCmdStr)
and this works... but means I have to rely on an external command (REG.EXE) to handle this registry deletion instead of native WinBatch functions which has always served me so well in the past.I'd really like to get this resolved in WinBatch... :-(

All tests have returned the same 1229 suppressed error from the RegDeleteKey() function. Any clues as to why registry deletes would be failing for me now? Any help greatly appreciated.

Answer:

First, thank you for reporting the problem and taking the time to try some of the suggestions. It was particularly helpful to eliminate the permissions/ownership possibility.

We have been able to trace the problem to a change made in the RegDeleteKey function that was necessitated by the advent of the 64-bit version of Windows. Basically, RegDeleteKey uses a newer version of a Windows registry API function when it is called from a script running on a 64-bit version of Windows XP/2003 or later. However, the new API function is not implemented on Windows 2000 so the Windows 2000 remote registry service doesn't know what to do with the request that results from calling the new API function.

This does not cause a problem when WinBatch is used directly on a Windows 2000 machine because WinBatch knows the system version and knows what that system supports. However, WinBatch does not know the version of the remote system nor what the remote system supports when it makes the above mentioned API call, and you have experienced the results.

For now your best solution is probably to continue using your command line workaround. There are a few other workarounds but I don't think they have many real advantage over your current one. Hopefully, this problem will be addressed in a future version of WinBatch.

Again thank you for your time and patience.


Article ID:   W18230
Filename:   RegDeleteKey failing from 64bit to 32-bit server .txt
File Created: 2012:05:31:08:51:26
Last Updated: 2012:05:31:08:51:26