windows-nt/Source/XPSP1/NT/shell/ext/hnw/nconn32/defconn.cpp

89 lines
2.8 KiB
C++
Raw Normal View History

2020-09-26 03:20:57 -05:00
//
// DefConn.cpp
//
#include "stdafx.h"
#include "Registry.h"
#include "DefConn.h"
#include "nconnwrap.h"
static const TCHAR c_szInternetSettings[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
static const TCHAR c_szProfile[] = "RemoteAccess\\Profile\\";
static const TCHAR c_szEnableAutodial[] = "EnableAutodial";
static const TCHAR c_szNoNetAutodial[] = "NoNetAutodial";
static const TCHAR c_szRemoteAccess[] = "RemoteAccess";
static const TCHAR c_szInternetProfile[] = "InternetProfile";
static const TCHAR c_szAutoConnect[] = "AutoConnect";
/////////////////////////////////////////////////////////////////////////////
// EnableAutodial
void WINAPI EnableAutodial(BOOL bAutodial, LPCSTR szConnection)
{
if (bAutodial)
{
// Ensure that "1" is written
bAutodial = 1;
}
CRegistry regInternetHKCU(HKEY_CURRENT_USER, c_szInternetSettings, KEY_SET_VALUE);
CRegistry regInternetHKLM(HKEY_LOCAL_MACHINE, c_szInternetSettings, KEY_SET_VALUE);
regInternetHKCU.SetDwordValue(c_szEnableAutodial, bAutodial);
regInternetHKCU.SetDwordValue(c_szNoNetAutodial, bAutodial);
regInternetHKLM.SetBinaryValue(c_szEnableAutodial, (LPBYTE)&bAutodial, sizeof(bAutodial));
if (szConnection != NULL)
{
TCHAR szTemp[MAX_PATH];
lstrcpy(szTemp, c_szProfile);
lstrcat(szTemp, szConnection);
CRegistry regProfile(HKEY_CURRENT_USER, szTemp, KEY_SET_VALUE);
regProfile.SetDwordValue(c_szAutoConnect, bAutodial);
}
}
/////////////////////////////////////////////////////////////////////////////
// BOOL IsAutodialEnabled()
BOOL WINAPI IsAutodialEnabled()
{
CRegistry regInternetHKCU;
return regInternetHKCU.OpenKey(HKEY_CURRENT_USER, c_szInternetSettings, KEY_QUERY_VALUE) &&
regInternetHKCU.QueryDwordValue(c_szEnableAutodial) != 0;
}
/////////////////////////////////////////////////////////////////////////////
// SetDefaultDialupConnection
//
// Empty (or NULL) string indicates no default connection, or shared connection (if ICS client).
void WINAPI SetDefaultDialupConnection(LPCTSTR pszConnectionName)
{
CRegistry regRAS(HKEY_CURRENT_USER, c_szRemoteAccess, KEY_SET_VALUE);
if (pszConnectionName != NULL && *pszConnectionName != '\0')
{
regRAS.SetStringValue(c_szInternetProfile, pszConnectionName);
// Don't automatically autodial anymore
// EnableAutodial(TRUE);
}
else
{
regRAS.DeleteValue(c_szInternetProfile);
EnableAutodial(FALSE);
}
}
/////////////////////////////////////////////////////////////////////////////
// GetDefaultDialupConnection
//
// Empty string returned indicates no default connection, or shared connection (if ICS client).
void WINAPI GetDefaultDialupConnection(LPTSTR pszConnectionName, int cchMax)
{
pszConnectionName[0] = '\0';
CRegistry regRAS(HKEY_CURRENT_USER, c_szRemoteAccess, KEY_QUERY_VALUE);
regRAS.QueryStringValue(c_szInternetProfile, pszConnectionName, cchMax);
}