The WriteReg
function creates or modifies a string or a numeric value in the Windows Registry. Not available in WinTask Lite. Use all registry functions with caution. If you are unfamiliar with the Windows Registry, it is recommended that you do not use these functions. Removing or modifying a registry entry can cause your system to become unstable.
Syntax
WriteReg(<path>,<type>,<value>)
or
ret=WriteReg(<path>,<type>,<value>)
Parameters
<path>
: entire tree before the value; it does not contain the value. For instance:
"HKEY_LOCAL_MACHINE\SOFTWARE\TaskWare\WinTask\1.0\Name"
If the path or value does not exist, they are created. If the value already exists, it is replaced by the new<value>
.<type>
: can be:- 1 string
- 2 string expand
- 3 binary
- 4 integer
- 7 string multiple
<value>
: must be a variable.
Return Value
ret
, numeric return code. When the registry change is successful, the function returns 0, otherwise use this return code for Error Handling.
Remarks
- If there is an inconsistency between the specified
<type>
and<value>
, a compilation error is generated. - Under Windows Vista, if you don’t have enough rights, writing in Registry is allowed only under
HKEY_CURRENT_USER
. If you execute aWriteReg
without admin rights, writing underHKEY_LOCAL_MACHINE
, Windows Vista writes a virtualized key which is in fact underHKEY_CURRENT_USER\Software\Classes\VirtualStore
.
Examples
WriteReg("HKEY_LOCAL_MACHINE\SOFTWARE\TaskWare\WinTask\1.0\Name",1,name$)
Example Code
#IgnoreErrors=1
path$="HKEY_LOCAL_MACHINE\Personal\Id\"
firstname$="Robert"
lastname$="DUPONT"
age=40
idnumber=300000000
binary_key$="01000ff00c0"
res=WriteReg(path$+"FirstName",1,firstname$)
res=WriteReg(path$+"Lastname",1,lastname$)
res=WriteReg(path$+"Age",4,age)
res=WriteReg(path$+"Id",4,idnumber)
res= WriteReg(path$+"Key",3,binary_key$)
msgbox("Return code : "+str$(res),64,"Write to Registry")