U
Hallo Tantor,
tut mir leid, wenn ich jetzt erst antworte, aber ich bin die ganze Woche nicht dazu gekommen ins Forum hineinzuschauen. Ich hab Dir mal einen Ausschnitt aus einem Code gepostet, den ich selbst für ein Setup-Programm benutze, um den Standard Path zu erweitern. Ich denke das es das ist, was Du suchst.
Die entscheidene Funktion heißt AddPath.
/*****************************************************************/
LPVOID WINAPI AllocPtr (DWORD Size)
{
LPVOID ret;
ret = malloc(Size);
if (ret) memset(ret, 0, Size);
return (ret);
}
/*****************************************************************/
VOID WINAPI Free_Ptr (LPVOID Ptr)
{
LPPVOID PPV;
PPV = (LPPVOID) Ptr;
Ptr = NULL;
if (PPV)
{
Ptr = *PPV; *PPV = NULL;
}
if (Ptr eq NULL) return;
free (Ptr);
}
/*-------------------------------------------------------------------------*/
HANDLE WINAPI OpenRegKey (HANDLE hKey, LPSTR Path, WORD New)
{
HANDLE ret;
DWORD dw;
WORD n;
LONG hl,Acc;
ret = 0;
//SetLastError(0);
if (New)
{
Acc = KEY_ALL_ACCESS;
RegCreateKeyEx (hKey, Path, 0, "", 0, Acc, NULL, &ret, &dw);
}else{
// Acc = KEY_READ;
Acc = KEY_ALL_ACCESS;
RegOpenKeyEx (hKey, Path, 0, Acc, &ret);
}
//DispLastError (hWndMain);
if (New > 1 and dw eq REG_OPENED_EXISTING_KEY)
{
RegDeleteKey (hKey, Path);
RegCreateKeyEx (hKey, Path, 0, "", 0, Acc, NULL, &ret, &dw);
}
Exit:
return (ret);
}
/*-------------------------------------------------------------------------*/
WORD WINAPI GetRegVal (HANDLE hKey, LPSTR Entry, LPVOID Val, DWORD Size)
{
char HStr[70];
WORD len,ret;
LONG hl;
DWORD hd,hd2;
ret = 0; // Error
memset (Val, 0, Size);
hl = RegQueryValueEx (hKey, Entry, NULL, NULL, (LPBYTE) Val, &Size);
if (hl) goto Exit;
ret = Size;
Exit:
return (ret);
}
/*-------------------------------------------------------------------------*/
LONG WINAPI SetRegKey (HANDLE Hd, LPSTR Entry, LPVOID Value, WORD Fmt)
{
WORD len;
LONG hl;
LPSTR LP;
HANDLE hKey;
hKey = (HANDLE) Hd;
Switch (Fmt)
case REG_SZ:
case REG_EXPAND_SZ: len = strlen((LPSTR)Value) + 1;
break;
case REG_DWORD: len = 4;
break;
default: len = 0;
}switch
hl = RegSetValueEx (hKey, Entry, 0, Fmt, Value, len);
return (hl);
}
/*-------------------------------------------------------------------------*/
VOID WINAPI CloseRegKey (HANDLE hKey)
{
RegCloseKey (hKey);
}
/***********************************************************************/
VOID WINAPI DispLastError (HWND hWnd, LPSTR Msg)
{
char HStr[90];
char Work[256];
LPBYTE LP,Cap,P;
int Err,hi;
Err = GetLastError(); HStr[0] = 0;
hi = FORMAT_MESSAGE_FROM_SYSTEM; LP = Work;
Cap = HStr; if (Msg) strcpy (Cap, Msg);
P = Cap + strlen(Cap);
wsprintf (P, " (%d)", Err);
FormatMessage (hi, NULL, Err, 0, LP, 255, NULL);
MessageBox (hWnd, LP, Cap, MB_ICONINFORMATION);
}
//-------------------------------------------------------------------------
VOID WINAPI AddPath (HWND hWnd, LPSTR Path)
{
HANDLE hKey;
short ret,len;
LONG Err;
char c;
DWORD hdw;
LPSTR LP,PV;
WORD hw,CFlag,Plen;
ret = 0;
LP = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";
hKey = OpenRegKey (HKEY_LOCAL_MACHINE, LP, 0);
if (hKey)
{
Plen = GetRegVal (hKey, "Path", NULL, 0);
if (Plen eq 0) DispLastError(hWnd, "Get Path");
hdw = Plen + 150; PV = AllocPtr (hdw);
GetRegVal (hKey, "Path", PV, hdw);
}else{
DispLastError(hWnd, LP); Plen = 0;
}
// wenn Pfad noch nicht vorhanden
// dann einfuegen
if (strstr(PV, Path) eq NULL)
{
hw = strlen(Path);
if (*PV)
{
memmove (PV+hw+1, PV, Plen);
}
memcpy (PV, Path, hw); *(PV+hw) = ';';
Err = SetRegKey (hKey, "Path", PV, REG_EXPAND_SZ);
Free_Ptr (&PV);
}
CloseRegKey (hKey);
}