InstallShield高级应用----判断是否是本机
//判断是否是本机,以本机的IP和计算机名称比较
//szServerName - 判断的服务名称
//若是,则返回TRUE,否则返回FALSE
function BOOL CheckISLocalServer(szServerName)
WSAData structWSAData;
WSAData POINTER pWSAData;
//
IPName LocalIPName;
IPName POINTER pLocalIPName;
//
IPAddrList structIPAddrList;
IPAddrList POINTER pIPAddrList;
IPAddPtr structIPAddPtr;
IPAddPtr POINTER pIPAddPtr;
POINTER pIN_Addr_Struct;
HostEnt structHostEnt;
HostEnt POINTER pHostEnt;
SHORT nlen;
NUMBER nIPNetAddr;
NUMBER nVersion;
STRING szMsg;
STRING szDefault;
STRING szURL;
STRING szPath;
NUMBER nRC;
NUMBER nRC2;
STRING szHostName;
STRING szMYIPAddr;
POINTER pWinSockReturn;
STRING szInitHostName;
begin
szInitHostName = szServerName;
StrToUpper(szInitHostName,szInitHostName);
StrReplace(szInitHostName,"\\SQLEXPRESS","",0);
pWSAData = &structWSAData;
nRC = UseDLL ("wsock32.dll");
pWSAData -> wHighVersion = 1;
pWSAData -> wVersion = 1;
nVersion = 0x02000002; // can be 0x01000001 for Windows NT but Windows 95 requires the version 2 settings
pWinSockReturn = WSAStartup(nVersion, pWSAData);
pWinSockReturn = gethostname(szHostName,100);
pHostEnt = gethostbyname(szHostName);
nlen = pHostEnt -> h_length; // debug check (should be 4)
pIPAddPtr = pHostEnt -> ph_addr_list;
pIPAddPtr = *pIPAddPtr;
nIPNetAddr = *pIPAddPtr;
// nIPNetAddr = pIPAddPtr -> nIPAddr;
pLocalIPName = inet_ntoa( nIPNetAddr );
szMYIPAddr = pLocalIPName -> szIPAddr;
WSACleanup();
UnUseDLL("wsock32.dll");
if(szInitHostName=szMYIPAddr || szInitHostName = szHostName) then
return TRUE;
else
return FALSE;
endif;
end;
//szServerName - 判断的服务名称
//若是,则返回TRUE,否则返回FALSE
function BOOL CheckISLocalServer(szServerName)
WSAData structWSAData;
WSAData POINTER pWSAData;
//
IPName LocalIPName;
IPName POINTER pLocalIPName;
//
IPAddrList structIPAddrList;
IPAddrList POINTER pIPAddrList;
IPAddPtr structIPAddPtr;
IPAddPtr POINTER pIPAddPtr;
POINTER pIN_Addr_Struct;
HostEnt structHostEnt;
HostEnt POINTER pHostEnt;
SHORT nlen;
NUMBER nIPNetAddr;
NUMBER nVersion;
STRING szMsg;
STRING szDefault;
STRING szURL;
STRING szPath;
NUMBER nRC;
NUMBER nRC2;
STRING szHostName;
STRING szMYIPAddr;
POINTER pWinSockReturn;
STRING szInitHostName;
begin
szInitHostName = szServerName;
StrToUpper(szInitHostName,szInitHostName);
StrReplace(szInitHostName,"\\SQLEXPRESS","",0);
pWSAData = &structWSAData;
nRC = UseDLL ("wsock32.dll");
pWSAData -> wHighVersion = 1;
pWSAData -> wVersion = 1;
nVersion = 0x02000002; // can be 0x01000001 for Windows NT but Windows 95 requires the version 2 settings
pWinSockReturn = WSAStartup(nVersion, pWSAData);
pWinSockReturn = gethostname(szHostName,100);
pHostEnt = gethostbyname(szHostName);
nlen = pHostEnt -> h_length; // debug check (should be 4)
pIPAddPtr = pHostEnt -> ph_addr_list;
pIPAddPtr = *pIPAddPtr;
nIPNetAddr = *pIPAddPtr;
// nIPNetAddr = pIPAddPtr -> nIPAddr;
pLocalIPName = inet_ntoa( nIPNetAddr );
szMYIPAddr = pLocalIPName -> szIPAddr;
WSACleanup();
UnUseDLL("wsock32.dll");
if(szInitHostName=szMYIPAddr || szInitHostName = szHostName) then
return TRUE;
else
return FALSE;
endif;
end;
作者:chhuic
出处:http://chhuic.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。