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;

posted @ 2011-06-04 16:24  ☆会飞的鱼☆  阅读(481)  评论(2编辑  收藏  举报