/* getreg.c - Obtiene un valor del registry y lo pone en la salida estandard Copyright (C) 2000, Luis C. 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: getreg {CR|CU|LM} Key ValueName CR = CLASSES_ROOT CU = CURRENT_USER LM = LOCAL_MACHINE */ #include #include #include HKEY hKey; HKEY hSubKey; DWORD dwError; BYTE Data[1024]; DWORD cbData; DWORD dwDisposition; LPBYTE lpMsgBuf; void uso(void) { fprintf(stderr, "Uso:\ngetreg {CR|CU|LM} Key ValueName\n\n"); exit(1); } int main(int argc, char **argv) { if (argc != 4) 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 = sizeof(Data); dwError = RegQueryValueEx(hSubKey, argv[3], 0, NULL, Data, &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, "RegQueryValueEx() - %s\n", lpMsgBuf); return 1; } printf(Data); return 0; }