Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Is it a Registry DataItem or Subkey?
Does Key Exist? Using RegQueryValue Function & ErrorMode(@off)

Keywords: regqueryvalue dataitem key subkey 

Question:

I want a program to query the registry for a key, and if it finds the key it should just display the value in the message. If the key doesn't exist it should create a new one, add the value, then display that value.

The function creates a new key and value OK if the key does not exist, however the RegQueryValue of rkey then returns an error. Why?

Answer:

There may be various things going on. Is what you want to query a key or a dataitem? If it is a key, it will be displayed in the LEFT panel in Regedit; if it is a dataitem, it will be displayed in the RIGHT panel in Regedit.

Assuming "current_tag" is a key, here's how to use RegQueryValue:

ErrorMode(@off) ; See warnings
LastError()
ctag = RegQueryValue(@REGCURRENT, "software\peoplesoft\PSVerTag\CURRENT_TAG")
err=LastError()
ErrorMode(@cancel)
if err==0   ; it exists
    Message("Current_tag default value is",ctag)
else
  rkey = RegCreateKey(@REGCURRENT, "software\peoplesoft\PSVerTag\CURRENT_TAG")
RegSetValue(rkey, "","New User")
       RegCloseKey(rkey)
MESSAGE("Current_tag","New User")
endif
Assuming "current_tag" is a dataitem, here's how to use RegQueryValue:
ErrorMode(@off) ; See warnings
LastError()
ctag = RegQueryValue(@REGCURRENT, "software\peoplesoft\PSVerTag[CURRENT_TAG]")
err=LastError()
ErrorMode(@cancel)
if err==0   ; it exists
    Message("Current_tag default value is",ctag)
else
  rkey = RegCreateKey(@REGCURRENT, "software\peoplesoft\PSVerTag")
RegSetValue(rkey, "[CURRENT_TAG]","New User")
       RegCloseKey(rkey)
MESSAGE("Current_tag","New User")
endif

Article ID:   W13716
Filename:   DataItem or Subkey - Does Key Exist and RegQueryValue.txt