/* setreg.c - Guarda un valor en el registry Copyright(C) 2000, Luis Carlos Castro Skertchly This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Uso: setreg {CR|CU|LM} Key ValueName Value CR = CLASSES_ROOT CU = CURRENT_USER LM = LOCAL_MACHINE */ #include #include #include HKEY hKey; HKEY hSubKey; DWORD dwError; DWORD cbData; DWORD dwDisposition; LPBYTE lpMsgBuf; void uso(void) { fprintf(stderr, "Uso:\nsetreg {CR|CU|LM} Key ValueName Value\n\n"); exit(1); } int main(int argc, char **argv) { if (argc != 5) uso(); if (!strcmp(argv[1], "CR")) hKey = HKEY_CLASSES_ROOT; else if (!strcmp(argv[1], "CU")) hKey = HKEY_CURRENT_USER; else if (!strcmp(argv[1], "LM")) hKey = HKEY_LOCAL_MACHINE; else uso(); //fprintf(stderr, "Key = '%s'\nSubKey = '%s'\nValue = '%s'\n", argv[1], argv[2], argv[3]); if ((dwError = RegCreateKeyEx(hKey, argv[2], 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hSubKey, &dwDisposition)) != ERROR_SUCCESS) { FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, dwError, 0, (LPSTR) &lpMsgBuf, 0, NULL); fprintf(stderr, "RegCreateKeyEx() - %s\n", lpMsgBuf); return 1; } cbData = strlen(argv[4]); dwError = RegSetValueEx(hSubKey, argv[3], 0, REG_SZ, argv[4], cbData); if (dwError) { FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, dwError, 0, (LPSTR) &lpMsgBuf, 0, NULL); fprintf(stderr, "RegSetValueEx() - %s\n", lpMsgBuf); return 1; } return 0; }