Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to create a key in the registry ?
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00720364
Message ID:
00720549
Views:
9
>>i use the registry classe in vfp to get informations. but this time i want to creat a key if it doesn't exist and set the value.
>>
>>this is what i want to do :
>>
>>oReg.SetRegKey("DisableTaskMgr",1,;
>>"Software\Microsoft\Windows\CurrentVersion\Policies\System",;
>>HKEY_CURRENT_USER)
>>
>>1 - how can i creat the system key if it doesn't exist ?
>>
>>2 - how to set the value 1 to "DisableTaskMgr" with a reg-dword type
>
>Hi Kouakou,
>Try this:
>
>#DEFINE REG_DWORD  4
>
>Local lo_Reg
>Local lc_Value, lc_Name, lc_Key
>Local ll_Error, ln_SubKey
>
>* Change the path with your vfp directory path
>lo_Reg = NewObject('Registry', 'D:\VFP7\FFC\Registry.VCX')
>
>lc_Key = 'Software\Microsoft\Windows\CurrentVersion\Policies\System'
>lc_Name = 'DisableTaskMgr'
>If !lo_Reg.IsKey(lc_Key, lo_Reg.nUserKey)
>   ll_Error = (RegCreateKey(lo_Reg.nUserKey, lc_Key, @ln_SubKey) != 0)
>endif
>
>If !ll_Error and (lo_Reg.OpenKey(lc_Key, lo_Reg.nUserKey) == 0)
>   lc_Value = Num2DWord(1)
>   RegSetValueEx(lo_Reg.nCurrentKey, lc_Name, 0, REG_DWORD, lc_Value, 4)
>   lo_Reg.Closekey()
>endif
>
>lo_Reg = Null
>Release lo_Reg
>
>
>Function Num2DWord(tn_Num)
>Local c0, c1, c2, c3
>   c3 = chr(int(tn_Num / 16777216))  && 256^3
>   tn_Num = mod(tn_Num, 16777216)
>
>   c2 = chr(int(tn_Num / 65536))     && 256^2
>   tn_Num = mod(tn_Num, 65536)
>
>   c1 = chr(int(tn_Num / 256))
>   c0 = chr(mod(tn_Num, 256))
>
>   Return c0 + c1 + c2 + c3
>EndFunc
>
>
>HTH

Herman,

You can simplify this a bit by calling the class's OpenKey method and supplying a third parameter (logical) of .T. This will create the key if it doesn't exist.
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform