Page 1 of 1 1
Topic Options
#58752 - 2001-08-31 01:16 PM Problem with EXISTKEY Function
Anonymous
Unregistered


HI,

I have a problem with this function that return always the @ERROR=2 when i check a subkey registry whether it exists or not.

Here the script section:

;--------Start------------------------------

$scKeyFull = "HKEY_LOCAL_MACHINE\Software\BdG\AMO"

DIM $RegParameters[22]
DIM $RegParamValue[22]

$RegParameters[0] = "SoftwareDistribution"
$RegParameters[1] = "City"
$RegParameters[2] = "Building"
$RegParameters[3] = "Floor"
$RegParameters[4] = "Office"
$RegParameters[5] = "Block"
$RegParameters[6] = "Template"
$RegParameters[7] = "PCModel"
$RegParameters[8] = "AssetCode"
$RegParameters[9] = "Zone"
$RegParameters[10] = "NetServer"
$RegParameters[11] = "SerialNumber"
$RegParameters[12] = "ClonerID"
$RegParameters[13] = "FullName"
$RegParameters[14] = "CloningDate"
$RegParameters[15] = "MasterVersion"
$RegParameters[16] = "DiskVersion"
$RegParameters[17] = "SoftwareLevel"
$RegParameters[18] = "Department"
$RegParameters[19] = "MonitorNumber"
$RegParameters[20] = "MonitorModel"
$RegParameters[21] = "MonReqExecuted"

;*****************************************************************************************

; Inizializzo la Chiave SoftwareDistribution a 0

WRITEVALUE ($scKeyFull,$RegParameters[0],"0","REG_SZ")

;*****************************************************************************************
; Riempio l'array dei valori con i valori del registry se presenti, altrimenti a vuoto

$Index = 0
$SubKeyValue = ""
DO
? $scKeyFull + "\" + $RegParameters[$Index]
$SubKeyValue = $scKeyFull + "\" + $RegParameters[$Index]
? $SubKeyValue
? @ERROR
If EXISTKEY($SubKeyValue)=0
? @ERROR
$RegParamValue[$Index] = READVALUE ($scKeyFull, $RegParameters[$Index])
? $RegParamValue[$Index] ; se esiste
Else
@ERROR?
WRITEVALUE ($scKeyFull,$RegParameters[$Index],"","REG_SZ")
$RegParamValue[$Index] = READVALUE ($scKeyFull, $RegParameters[$Index])
? $RegParamValue[$Index] ; se non esiste
EndIf
$Index= $Index + 1
? $Index
UNTIL $Index < 22

;--------END----------------

If you run this script You ca see the value @Error that become 2: what it means?

Then i try a test only with an IF statement and it is the same. Here is the Example:

;--------start------------------
If EXISTKEY ($scKeyFull + "\" + $RegParameters[1]) <> 0
WRITEVALUE ($scKeyFull,$RegParameters[1],"Zurich","REG_SZ")
EndIf

;-------end-----------------

Top
#58753 - 2001-08-31 01:21 PM Re: Problem with EXISTKEY Function
Anonymous
Unregistered


HI,

I forgot to say that i'm using ver 3.61

Thanks

Stefix

Top
#58754 - 2001-09-01 08:54 AM Re: Problem with EXISTKEY Function
Jeroen Offline
Starting to like KiXtart

Registered: 2001-08-16
Posts: 180
Loc: Netherlands
Hi,

What happens if you test the following:

code:

$scKeyFull="HKEY_LOCAL_MACHINE\Software\BdG\AMO\SoftwareDistribution"
$y=ExistKey($scKeyFull)
If $y=0
? "Key exists, Error value is: " + $y
Sleep 2
Else
? "Key not found, Error value is: " + $y
Sleep 2
Endif

I think maybe the brackets could cause a problem? ([$index]) If the above works, try loosing the brackets like this:

code:

$scKeyFull="HKEY_LOCAL_MACHINE\Software\BdG\AMO"
$RegParameters0 = "SoftwareDistribution"
$RegParameters1 = "City"
$Index = 0
$SubKeyValue = ""

DO
$SubKeyValue = $scKeyFull + "\" + $RegParameters + $Index
If EXISTKEY($SubKeyValue)=0
$RegParamValue + $Index = READVALUE ($scKeyFull, $RegParameters + $Index)
Else


Etc etc... If this doesn't work, is it possible that that part of the registry is protected with rights?

Just some thoughts...

_________________________
Regards, Jeroen. There are two ways to write error-free programs. Only the third one works.

Top
#58755 - 2001-09-03 11:05 AM Re: Problem with EXISTKEY Function
Anonymous
Unregistered


Hi Jeroen,

I think i find the problem:
Function ExistKey requires a subkey parameter and the complete path to "HKEY_LOCAL_MACHINE\Software\BdG\AMO\SoftwareDistribution" is a String value and then the results was always <>0!

The workaround is the Readvalue function, like the example:

code
_________________________________
? "Sto Inizializzando la chiave: " + $scKeyFull + "\" + $RegParameters[$Index]
$RegParamValue[$Index] = READVALUE ($scKeyFull,$RegParameters[$Index])
If @ERROR <> 0 ;if the value doesn't exist
$Value = ""
______________________
ecc......

I try to read the key value and if i can't i create.

Thanks

bye
Stefix

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1607 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.052 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org