#ifndef GLOBAL_DECL
#include "global.h" // Global data types and variables
#endif
#include "winbase.h"
bool DialUp( config* settings )
{
if (settings -> use_modem)
GetDefDialUp( settings, false );
return true;
}
void HangUp( config* settings )
{
if (settings -> use_modem)
GetDefDialUp( settings, true );
}
void GetOS( config* settings )
{
/*
* This code is a modification of a code snippet copied from www.codeguru.com
* posted by Jeroen-Bart Engelen - j.engelen@planetinternet.nl
*
*/
OSVERSIONINFO version;
/* Find out which OS we are running on */
version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
/* If we get an error, make the OS "Unknown". */
if(!GetVersionEx(&version))
strcpy(settings -> OS, "Unknown");
else if (version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
strcpy(settings -> OS, "Win9x");
else if (version.dwPlatformId == VER_PLATFORM_WIN32_NT)
strcpy(settings -> OS, "WinNT");
}
void GetDefDialUp( config* settings, bool restore )
{
HKEY hKey = NULL;
DWORD nLen;
DWORD newvalue;
char data[500];
char defusrkey[70];
char profilekey[70];
char checkRAS[70];
bool valid_os = false;
CRegistry SysReg;
if (!strcmp(settings -> OS, "Win9x"))
{
// Set the registry key we want to look at.
strcpy(defusrkey, "remoteaccess");
strcpy(profilekey, "remoteaccess\\profile\\");
strcpy(checkRAS, "system\\currentcontrolset\\services\\remoteaccess\\networkprovider");
valid_os = true;
}
else if (!strcmp(settings -> OS, "WinNT"))
{
strcpy(defusrkey, "remoteaccess");
strcpy(profilekey, "remoteaccess\\profile\\");
strcpy(checkRAS,"system\\currentcontrolset\\services\\remoteaccess");
valid_os = true;
}
settings -> default_name[0] = NULL;
if (valid_os)
{
// Open the RAS registry key to check if RAS is installed
SysReg.Open( HKEY_LOCAL_MACHINE, checkRAS );
if (SysReg.GetLastError() == ERROR_SUCCESS)
// If we got an error then the registry key does not exist and
// we can conclude that the RAS has not been installed.
{
SysReg.Close();
SysReg.Open(HKEY_CURRENT_USER, defusrkey);
// Try and retrieve the default phone book connection name
if (SysReg.GetLastError() == ERROR_SUCCESS)
{
SysReg.Read((LPBYTE)data, (nLen=sizeof(data),&nLen), NULL, "default" );
if (SysReg.GetLastError() == ERROR_SUCCESS)
{
// Store the default connection name
strcpy(settings -> default_name, data);
strcat(profilekey, data);
SysReg.Close();
SysReg.Open(HKEY_CURRENT_USER, profilekey);
// Try and get phone book entry details for default connection
if (SysReg.GetLastError() == ERROR_SUCCESS)
{
// Change settings to turn on autodial and autodisconnect
if (!restore)
{
settings -> autoconnect = 2; // 2 = Error value
settings -> autodisconnect = 2; // 2 = Error value
settings -> exitdisconnect = 2; // 2 = Error value
// Attempt to read actual values and store them
SysReg.Read((LPBYTE)data, (nLen=sizeof(data),&nLen), NULL, "autoconnect" );
if (SysReg.GetLastError() == ERROR_SUCCESS)
settings -> autoconnect = (DWORD)data[0];
SysReg.Read((LPBYTE)data, (nLen=sizeof(data),&nLen), NULL, "enableautodisconnect" );
if (SysReg.GetLastError() == ERROR_SUCCESS)
settings -> autodisconnect = (DWORD)data[0];
SysReg.Read((LPBYTE)data, (nLen=sizeof(data),&nLen), NULL, "enableexitdisconnect" );
if (SysReg.GetLastError() == ERROR_SUCCESS)
settings -> exitdisconnect = (DWORD)data[0];
// Set new values
newvalue = 1;
nLen=sizeof(newvalue);
SysReg.Write("autoconnect", (CONST BYTE *)&newvalue, nLen, REG_DWORD);
SysReg.Write("enableautodisconnect", (CONST BYTE *)&newvalue, nLen, REG_DWORD);
SysReg.Write("enableexitdisconnect", (CONST BYTE *)&newvalue, nLen, REG_DWORD);
}
// Restore original autodial and autodisconnect settings
else
{
nLen=sizeof(newvalue);
if (settings -> autoconnect != 2) // 2 = Error value
SysReg.Write("autoconnect", (CONST BYTE *)&(settings -> autoconnect),
nLen, REG_DWORD);
if (settings -> autodisconnect != 2) // 2 = Error value
SysReg.Write("enableautodisconnect", (CONST BYTE *)&(settings -> autodisconnect),
nLen, REG_DWORD);
if (settings -> exitdisconnect != 2) // 2 = Error value
SysReg.Write("enableexitdisconnect", (CONST BYTE *)&(settings -> exitdisconnect),
nLen, REG_DWORD);
}
}
}
}
}
SysReg.Close();
}
}
syntax highlighted by Code2HTML, v. 0.8.11