Why does RegExistKey return an error.

Started by George Vagenas, February 25, 2014, 03:29:52 PM

Previous topic - Next topic

George Vagenas

This line is returning an error:
Code (winbatch) Select
   if regexistkey(@regcurrent, PrjKey) then cCnts = regqueryvalue(@regcurrent, '%PrjKey%[WorkSpace Count]')
      else cCnts = 0
.  I know that I can trap this error but the documentation indicates that it should just return a value of @FALSE if the key does not exist.

I've had this code as part of a menu call for a very long time, not 100% but I'm pretty sure it used to just return @FALSE.
Thanks

George

Deana

RegExistKey will return 0 if the key doesn't exist. What error are you getting? Is it possibly due to the use of variable substitution?

Add DebugTrace to your script and post the resulting trace file here. It will contain the info needed to help track down the issue.
Deana F.
Technical Support
Wilson WindowWare Inc.

George Vagenas

Not getting a log file, is the syntax wrong?
Code (winbatch) Select
debugtrace(1, 'PrjMngr.log') Or is it not created in the same folder as the script?

The question is moot at any rate I added this line to the script and it now works.
Code (winbatch) Select
   Hndl = regopenkey(@regcurrent, PrjKey)
  I had assumed that other parts of the script had opened the key but obviously not as this fixed the error.

Thanks

George

Deana

You didn't specify a file path in the DebugTrace statement. Therefore the 'PrjMngr.log' will created in the current working directory ( whatever that might be at that point in the script). I recommend using DirScript if you want it placed in the same directory as the script.

I cannot see how adding a RegOpenKey would have any effect on this statement. The handle returned is not used anywhere in the statement.

Code (winbatch) Select
if regexistkey(@regcurrent, PrjKey) then cCnts = regqueryvalue(@regcurrent, '%PrjKey%[WorkSpace Count]')
      else cCnts = 0


I would recommend that you continue debugging to address the possible issue.
Deana F.
Technical Support
Wilson WindowWare Inc.

td

Quote from: George Vagenas on February 25, 2014, 03:29:52 PM
I know that I can trap this error but the documentation indicates that it should just return a value of @FALSE if the key does not exist.

I've had this code as part of a menu call for a very long time, not 100% but I'm pretty sure it used to just return @FALSE.

If you use "WOW6432NODE" in any part of registry sub-key specification on a 64-bit system, almost all WinBatch registry functions will error.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

George Vagenas

Deana -
Thanks, you're right the "Hndl =" line had no effect.  Except for the debugtrace lines I restored the code to the original and wasn't getting any errors.  So I deleted the registry items in question and the error returned.
Code (winbatch) Select
Error: #1233: RegQueryValue: Function Failed
Script: if regexistkey(@regcurrent, PrjKey) then cCnts = regqueryvalue(@regcurrent, 'Software\GVProp\PrjMngr\Projects\Newzbin[WorkSpace Count]')
Assignment: ccnts
File: C:\0ser\WinBatch\Macros\Studio PrjMngr\PrjMngr.wbt
Procedure: writeprjfiles
Line No. 845


Sorry, I've been away from programming too long and I didn't pickup on the cause of the error.  The lines should read:
Code (winbatch) Select
   PrjKey = strcat('Software\GVProp\PrjMngr\Projects\', Prj, '[WorkSpace Count]') ; Hard coded key.
   ; Need a workspace count before messing with the project key.
   if regexistkey(@regcurrent, PrjKey) then cCnts = regqueryvalue(@regcurrent, PrjKey)
      else cCnts = 0

I tested for the parent as it were and assumed the child value existed, really dumb.
Thanks

George