Write Information to the Registry

The following FUNCTIONS can be used to write a string of information to a key in the Registry. A command similar to the one shown below will be used in the macro to call the function:

vResult:=RegistryWriteStringToLocalMachine("Software\MyJunk"; "MyItem"; "The Data")

You can check the vResult return variable to determine if the write was successful.

// ******************************************************************
// Copyright (c) 1999 J. Jeppson. All Rights Reserved.
// http://www.wpmacros.com
// Purpose: Write a string to the Registry's CurrentUser section
// Input: vKey: The name of the key to open (i.e., "Software\MySection")
//           vItem: The name of the item to get the value for
//           vValue:  the string value to store in the Registry
// Return: 0 if successful, 100 if key is invalid, 101 if key couldn't be opened
// *******************************************************************

FUNCTION RegistryWriteStringToCurrentUser (vKey; vItem; vValue)
HKey:=RegistryCreateKey(CurrentUser!; vKey)
vReturn:=RegistrySetValue(HKey; vItem; vValue; String!)
RegistryCloseKey(HKey)
Return(vReturn)
ENDFUNC

// ******************************************************************
// Copyright (c) 1999 J. Jeppson. All Rights Reserved.
// http://www.wpmacros.com
// Purpose: Write a string to the Registry's LocalMachine section
// Input: vKey: The name of the key to open (i.e., "Software\MySection")
//           vItem: The name of the item to get the value for
//           vValue:  the string value to store in the Registry
// Return: 0 if successful, 100 if key is invalid, 101 if key couldn't be opened
// *******************************************************************

FUNCTION RegistryWriteStringToLocalMachine (vKey; vItem; vValue)
HKey:=RegistryCreateKey(CurrentUser!; vKey)
vReturn:=RegistrySetValue(HKey; vItem; vValue; String!)
RegistryCloseKey(HKey)
Return(vReturn)
ENDFUNC

See also: Get Infomation from the Registry

 

Terms of Use:

You may include the code displayed here in your own macros with the following conditions:

The code must be included in its entirety, including copyright and header information.
You may use the code in macros used within your own organization, as part of your job, for your employer, or for your own personal use.
You may modify the code to meet your own needs.
If you modify any code in the routine, you must comment out the original line of code, and leave that original line intact, then type a new line of code with the change that you made. You must then add a comment  noting your change. 
You may not use the code in macros you create for hire, other than at your regular work for an employer, where the macrowill be used in-house.  For example, you may not use this routine in macros you create, modify, or convert for hire as a consultant for a company or individual that you are not a regular employee for. 
You may not sell or publish macros that use this routine in any form. 
You accept full responsibility for macros that you include this routine in.
J. Jeppson will not be obligated  to make the code work for you, or for your particular need or usage.
Under no circumstances will J. Jeppson be held liable for any damages or liabilities incurred while using  this code.

 

Copyright Notice: The information included in these pages is protected by US Copyright.  If you choose to use the information here, you do so entirely at your own risk. No representations are made regarding the fitness of this information for your particular purpose, or for your ability or inability to use the information. You are advised to make backups of all relevant files before implementing any suggestion  or technique.
© Copyright 1999 by J. Jeppson.