Sönke Petersen
2004-04-05 14:34:49 UTC
Für alle, die auch Kunden haben, die verzweifelt nach einer Exe im
Programmverzeichnis suchen, unten ein kleines VC++-Programm von mir, das
keine MFC, msvbvm60.dll, etc. benötigt. Es ruft einfach die Access-RT mit
der gewünschten DB auf und übergibt Parameter per /cmd an Access.
Vielen Grüße...an die alten Bekannten
Sönke
// Sorry, sieht ohne Tabulatoren etwas wirr aus...
#include "stdafx.h"
#include <shellapi.h>
#include <winreg.h>
#include <stdlib.h>
const char DBName[20] = "server.kyy"; //// Hier Namen der Datenbank
eintragen, die geöffnet werden soll (muss im selben Verzeichnis liegen!)
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow )
{
HKEY pKey;
int success = 0;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Shared
Tools\\MSACCESS80", 0, KEY_ALL_ACCESS, &pKey)
== ERROR_SUCCESS)
{
success = 1;
}
else if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Shared
Tools\\MSACCESS80RT", 0, KEY_ALL_ACCESS, &pKey)
== ERROR_SUCCESS)
{
success = 1;
}
if (success)
{
unsigned char value[256];
unsigned long* ValueType = 0;
unsigned long dw = 256;
RegQueryValueExA(pKey, "Path", 0, ValueType, value, &dw);
RegCloseKey(pKey);
char dir[255];
char file[500];
char* pfile;
GetModuleFileName(NULL, dir, 255);
for (int i = strlen(dir) - 1; i>0; i--)
{
if (dir[i] == 92)
{
dir[i] = 0;
i = 0;
}
else
dir[i] = 0;
}
strcpy(file, "/runtime /wrkgrp \"");
pfile = strcat(file, dir);
pfile = strcat(pfile, "\\system.mdw\" \"");
pfile = strcat(file, dir);
pfile = strcat(pfile, "\\");
pfile = strcat(pfile, DBName);
pfile = strcat(pfile, "\"");
if (strlen(lpCmdLine) > 0)
{
pfile = strcat(pfile, " /cmd ");
pfile = strcat(pfile, lpCmdLine);
}
if ((long)ShellExecuteA (0, "Open", reinterpret_cast<const char
*>(&value), pfile ,"C:\\", 1) <= 32)
MessageBox(0, "Access-Runtime-Umgebung nicht gefunden!", "Fehler", 0);
}
else
{
MessageBox(0, "Access-Runtime-Umgebung nicht gefunden!", "Fehler", 0);
}
return 0;
}
Programmverzeichnis suchen, unten ein kleines VC++-Programm von mir, das
keine MFC, msvbvm60.dll, etc. benötigt. Es ruft einfach die Access-RT mit
der gewünschten DB auf und übergibt Parameter per /cmd an Access.
Vielen Grüße...an die alten Bekannten
Sönke
// Sorry, sieht ohne Tabulatoren etwas wirr aus...
#include "stdafx.h"
#include <shellapi.h>
#include <winreg.h>
#include <stdlib.h>
const char DBName[20] = "server.kyy"; //// Hier Namen der Datenbank
eintragen, die geöffnet werden soll (muss im selben Verzeichnis liegen!)
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow )
{
HKEY pKey;
int success = 0;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Shared
Tools\\MSACCESS80", 0, KEY_ALL_ACCESS, &pKey)
== ERROR_SUCCESS)
{
success = 1;
}
else if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Shared
Tools\\MSACCESS80RT", 0, KEY_ALL_ACCESS, &pKey)
== ERROR_SUCCESS)
{
success = 1;
}
if (success)
{
unsigned char value[256];
unsigned long* ValueType = 0;
unsigned long dw = 256;
RegQueryValueExA(pKey, "Path", 0, ValueType, value, &dw);
RegCloseKey(pKey);
char dir[255];
char file[500];
char* pfile;
GetModuleFileName(NULL, dir, 255);
for (int i = strlen(dir) - 1; i>0; i--)
{
if (dir[i] == 92)
{
dir[i] = 0;
i = 0;
}
else
dir[i] = 0;
}
strcpy(file, "/runtime /wrkgrp \"");
pfile = strcat(file, dir);
pfile = strcat(pfile, "\\system.mdw\" \"");
pfile = strcat(file, dir);
pfile = strcat(pfile, "\\");
pfile = strcat(pfile, DBName);
pfile = strcat(pfile, "\"");
if (strlen(lpCmdLine) > 0)
{
pfile = strcat(pfile, " /cmd ");
pfile = strcat(pfile, lpCmdLine);
}
if ((long)ShellExecuteA (0, "Open", reinterpret_cast<const char
*>(&value), pfile ,"C:\\", 1) <= 32)
MessageBox(0, "Access-Runtime-Umgebung nicht gefunden!", "Fehler", 0);
}
else
{
MessageBox(0, "Access-Runtime-Umgebung nicht gefunden!", "Fehler", 0);
}
return 0;
}