这是我IT生涯的第一篇博客文章
刚入手服务器,站点搭建需要对各种环境进行安装,自己整理下代码,把它记录下来,开始积累一点知识,方便以后回头观看,所以整理出来,虽然自己还是个菜鸟,但是我相信积跬步能至千里!
在高版本的IIS 10.0上安装PHPManager For IIS ,直接安装是不行的,需要把IIS在注册表中的版本号修改降级,才能安装。注意,安装完之后必须要还原版本号,否则后果很严重!
这面附上我的代码。
#include "stdafx.h" #include <windows.h> #include <iostream> using namespace std; bool ModifyIISVersion(); bool RestoreIISVersion(); bool ModifyReg(const wstring& keyname, const wstring& valuename, const DWORD data); int _tmain(int argc, _TCHAR* argv[]) { BOOL bRet = false; bRet = ModifyIISVersion(); bRet = RestoreIISVersion(); system("pause"); return 0; } bool ModifyIISVersion() { std::wstring iisW3svcRegKeyName = _T("System\\CurrentControlSet\\Services\\W3SVC\\Parameters"); std::wstring iisInetStpRegValueName = _T("SOFTWARE\\Microsoft\\InetStp"); std::wstring iisRegValueName_MajorVersion = _T("MajorVersion"); std::wstring iisRegValueName_MinorVersion = _T("MinorVersion"); bool bRet = false; if (ModifyReg(iisW3svcRegKeyName, iisRegValueName_MajorVersion, 0x00000009) == true && ModifyReg(iisW3svcRegKeyName, iisRegValueName_MinorVersion, 0x00000000) == true && ModifyReg(iisInetStpRegValueName, iisRegValueName_MajorVersion, 0x00000009) == true && ModifyReg(iisInetStpRegValueName, iisRegValueName_MinorVersion, 0x00000000) == true) { bRet = true; } return bRet; } bool RestoreIISVersion() { std::wstring iisW3svcRegKeyName = _T("System\\CurrentControlSet\\Services\\W3SVC\\Parameters"); std::wstring iisInetStpRegValueName = _T("SOFTWARE\\Microsoft\\InetStp"); std::wstring iisRegValueName_MajorVersion = _T("MajorVersion"); std::wstring iisRegValueName_MinorVersion = _T("MinorVersion"); bool bRet = false; if (ModifyReg(iisW3svcRegKeyName, iisRegValueName_MajorVersion, 0x0000000a) == true && ModifyReg(iisW3svcRegKeyName, iisRegValueName_MinorVersion, 0x00000000) == true && ModifyReg(iisInetStpRegValueName, iisRegValueName_MajorVersion, 0x0000000a) == true && ModifyReg(iisInetStpRegValueName, iisRegValueName_MinorVersion, 0x00000000) == true) { bRet = true; } return bRet; } bool ModifyReg(const wstring& keyname, const wstring& valuename, const DWORD data) { bool bRet = false; if (keyname.empty() || valuename.empty()) { return bRet; } HKEY hKey; DWORD dwRet; dwRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyname.c_str(), 0, KEY_WOW64_64KEY | KEY_ALL_ACCESS, &hKey); if (dwRet != ERROR_SUCCESS) { std::cout << "RegOpenKey Failded.\n" << endl; return bRet; } //DWORD data = 0x0000000a; dwRet = RegSetValueEx(hKey, valuename.c_str(), 0, REG_DWORD, (LPBYTE)&data, sizeof(data)); if (dwRet != ERROR_SUCCESS) { std::cout << "RegSetValueEx Failded.\n" << endl; return bRet; } bRet = true; return bRet; }