3

如何确定我的 NSIS 功能上是否有可用的互联网连接?

我看到了 Intec 插件,但我没有找到如何做到这一点

谢谢。

4

3 回答 3

4

您应该为此使用 Dailer 插件。

试试这个:

Dialer::GetConnectedState
Pop $1

如果有互联网连接,1美元将online是,它会是offline

阅读更多: http: //nsis.sourceforge.net/Docs/Dialer/Dialer.txt

于 2013-08-14T21:49:40.237 回答
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
于 2013-09-12T01:10:23.547 回答
0

根据Windows Vista 及更高版本上的NSIS 文档,建议使用它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

可能对某人有用。

于 2020-02-03T14:04:43.253 回答