获取系统版本AND创建快捷方式
获取系统版本:
DWORD dwVersion = 0;
DWORD dwMajorVersion = 0;
DWORD dwMinorVersion = 0;
DWORD dwBuild = 0;
dwVersion = GetVersion(); // Get the Windows version.
dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); // low-order word contains the version number of the operating system
dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion))); //high-order byte specifies the minor version (revision) number, in hexadecimal notation
if (dwVersion < 0x80000000)
DWORD dwMajorVersion = 0;
DWORD dwMinorVersion = 0;
DWORD dwBuild = 0;
dwVersion = GetVersion(); // Get the Windows version.
dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); // low-order word contains the version number of the operating system
dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion))); //high-order byte specifies the minor version (revision) number, in hexadecimal notation
if (dwVersion < 0x80000000)
{
dwBuild = (DWORD)(HIWORD(dwVersion));
dwBuild = (DWORD)(HIWORD(dwVersion));
}
CString D_version;
D_version.Format("V=%d,D=%d,S=%d",dwMajorVersion, dwMinorVersion, dwBuild);
AfxMessageBox(D_version);
·········------------------------------------------
CString D_version;
D_version.Format("V=%d,D=%d,S=%d",dwMajorVersion, dwMinorVersion, dwBuild);
AfxMessageBox(D_version);
·········------------------------------------------
Operating system | Version number |
---|---|
Windows 7 | 6.1 |
Windows Server 2008 R2 | 6.1 |
Windows Server 2008 | 6.0 |
Windows Vista | 6.0 |
Windows Server 2003 R2 | 5.2 |
Windows Server 2003 | 5.2 |
Windows XP | 5.1 |
Windows 2000 | 5.0 |
------------------------------------------------------------------------------------------
创建快捷方式主要的:
// 取得开始菜单或桌面的PIDL
LPITEMIDLIST pidlBeginAt;
SHGetSpecialFolderLocation(HWND_DESKTOP,CSIDL_COMMON_PROGRAMS,&pidlBeginAt) ;
// 把PIDL转换为路径名
char szLinkPath[MAX_PATH];
SHGetPathFromIDList(pidlBeginAt,szLinkPath);
szLink = szLinkPath;
char szLinkPath[MAX_PATH];
SHGetPathFromIDList(pidlBeginAt,szLinkPath);
szLink = szLinkPath;
//CreateDirectory(szLink,NULL); //创建快捷方式目录
CreateLink(LPCSTR path, LPCSTR pszLink)
{
HRESULT hres;
IShellLink *psl;
CoInitialize (NULL);
{
HRESULT hres;
IShellLink *psl;
CoInitialize (NULL);
// Create an IShellLink object and get a pointer to the IShellLink
// interface (returned from CoCreateInstance).
hres = CoCreateInstance (CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (void **)&psl);
if (SUCCEEDED (hres))
{
IPersistFile *ppf;
// interface (returned from CoCreateInstance).
hres = CoCreateInstance (CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (void **)&psl);
if (SUCCEEDED (hres))
{
IPersistFile *ppf;
// Query IShellLink for the IPersistFile interface for
// saving the shortcut in persistent storage.
hres = psl->QueryInterface (IID_IPersistFile, (void **)&ppf);
if (SUCCEEDED (hres))
{
WORD wsz [MAX_PATH]; // buffer for Unicode string
// saving the shortcut in persistent storage.
hres = psl->QueryInterface (IID_IPersistFile, (void **)&ppf);
if (SUCCEEDED (hres))
{
WORD wsz [MAX_PATH]; // buffer for Unicode string
// Set the path to the shortcut target.
hres = psl->SetPath (path);
hres = psl->SetPath (path);
if (! SUCCEEDED (hres))
return false;
return false;
// Set the description of the shortcut.
CSting pszDesc;
//hres = psl->SetDescription (pszDesc);
//hres = psl->SetDescription (pszDesc);
if (! SUCCEEDED (hres))
return false;
return false;
// Ensure that the string consists of ANSI characters.
MultiByteToWideChar (CP_ACP, 0, pszLink, -1, wsz, MAX_PATH);
MultiByteToWideChar (CP_ACP, 0, pszLink, -1, wsz, MAX_PATH);
// Save the shortcut via the IPersistFile::Save member function.
hres = ppf->Save (wsz, TRUE);
hres = ppf->Save (wsz, TRUE);
if (! SUCCEEDED (hres))
return false;
return false;
// Release the pointer to IPersistFile.
ppf->Release ();
}
// Release the pointer to IShellLink.
psl->Release ();
}
CoUninitialize ();
return true;
}