如何确定我的NSIS功能是否有可用的互联网连接?
我看到了Intec插件,但我没有找到怎么做
感谢。
答案 0 :(得分:4)
你应该使用Dailer插件。
试试这个:
Dialer::GetConnectedState
Pop $1
如果有互联网连接,$ 1将是online
,它将是offline
答案 1 :(得分:0)
TESTAGIN:
ClearErrors
SetDetailsPrint both
DetailPrint "$(TEST_TEST)"
SetDetailsPrint none
inetc::head /silent "http://www.msn.com" "$SYSDIR\test.txt"
Pop $0 # return value = exit code, "OK" if OK
${If} $0 != OK
GOTO Done
${Else}
MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "$(TEST_INTERNET_CONNECTION)" IDRETRY TESTAGIN
#quit
${EndIf}
Done:
SetDetailsPrint both
DetailPrint "$(TEST_OK)"
SetDetailsPrint none
ClearErrors
答案 2 :(得分:0)
根据Windows Vista及更高版本上的NSIS documentation,建议使用INetworkListManager::GetConnectivity()
检查Internet是否已连接。
以下是使用推荐方法的函数:
!include "LogicLib.nsh"
Function IsInternetConnected
!define CLSID_NetworkListManager "{DCB00C01-570F-4A9B-8D69-199FDBA5723B}"
!define IID_INetworkListManager "{DCB00000-570F-4A9B-8D69-199FDBA5723B}"
!define CLSCTX_ALL 23
Push $R0
Push $R1
Push $R2
Push $R3
Push $R9
; Result - is internet connected.
StrCpy $R0 false
SetPluginUnload alwaysoff
System::Call "ole32::CoCreateInstance(g '${CLSID_NetworkListManager}', i 0, i ${CLSCTX_ALL}, g '${IID_INetworkListManager}', *i .R1) i .R9"
IntCmp $R9 0 0 end
; INetworkListManager->GetConnectivity(NLM_CONNECTIVITY*)
System::Call "$R1->13(*i .R2) i .R9"
IntCmp $R9 0 0 end
; IUnknown->Release()
System::Call "$R1->2() i"
; Internet IPv4: NLM_CONNECTIVITY_IPV4_INTERNET = 64.
IntOp $R3 $R2 & 64
${If} $R3 <> 0
StrCpy $R0 true
Goto end
${EndIf}
; Internet IPv6: NLM_CONNECTIVITY_IPV6_INTERNET = 1024.
IntOp $R3 $R2 & 1024
${If} $R3 <> 0
StrCpy $R0 true
Goto end
${EndIf}
end:
SetPluginUnload manual
Pop $R9
Pop $R3
Pop $R2
Pop $R1
Exch $R0
FunctionEnd
这是使用此功能的方法:
!include "LogicLib.nsh"
Section
Push $0
Call IsInternetConnected
Pop $0
${If} $0 == false
MessageBox MB_OK "Internet is not connected"
${Else}
MessageBox MB_OK "Internet is connected"
${EndIf}
Pop $0
SectionEnd
也许对某人有用。