• Detect Network or Drive Accesibility (97pro upwards)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Detect Network or Drive Accesibility (97pro upwards)

    Author
    Topic
    #358867

    I’m absolutely certain that this has come up before but my complete inability to operate a search engine has resulted in a null score.

    How do I work out in vba whether my laptop is dialled up or not?

    I have a data manipulation sub in excel that chunders data around for a bit and then prints the resultant files; which is fine at work but if I’m running from home I don’t want the print bit to work. I think I could use on error resume next but I’ve got the same problem with other stuff, so wouldn’t mind treating the cause as opposed to the symptoms.

    Obviously, I could have two cover subs

    a) Sub RunFromHome
    Sub RunFromWork

    which then pass printer status to the main routine but a) I’m lazy and I’m curious

    I’ve tried the following

    Option Explicit
    Declare Function GetSystemMetrics Lib “user32.dll” (ByVal nIndex As Long) As Long
    Sub GetNetworkInfo()
    Const SM_NETWORK = 63
    Dim CheckNetWork As Long ‘ Check if network is presented.
    ‘ Display whether the system has a network connection installed.
    CheckNetWork = GetSystemMetrics(SM_NETWORK)
    If (CheckNetWork And &H1) = &H1 Then ‘ check only the information bit
    MsgBox “A network is configured to be used by Windows.”
    Else
    MsgBox “No network is currently configured.”
    End If
    End Sub

    but when I’m at home I get the first msgbox – but I think the key here is the word “configured” ?

    I am, as ever, as confused as a confused thing. Any help would result in a virtual beer as long as I can find the link!

    Brooke

    Viewing 0 reply threads
    Author
    Replies
    • #536440

      There is another set of functions that might fit better. See HOWTO: List Local Network Connections with WNetEnumResources (Q177697). I have not tried it myself, and I think there are some wrappers for these functions in a Getz & Gilbert book, but I forget which one. Hope this helps.

      • #536596

        Well, I have a workaround, though it’s not as elegant as I’d like.

        the code is as follows:

        Private Declare Function GetLogicalDrives Lib "KERNEL32" () As Long
        Private Sub ShowDrives()
            'KPD-Team 1999
            'URL: http://www.allapi.net/
            'E-Mail: KPDTeam@Allapi.net
            Dim LDs As Long, Cnt As Long, sDrives As String
            'get the available drives
            LDs = GetLogicalDrives
            sDrives = "Available drives:"
            For Cnt = 0 To 25
                If (LDs And 2 ^ Cnt)  0 Then
                    sDrives = sDrives + " " + Chr$(65 + Cnt)
                End If
            Next Cnt
            MsgBox sDrives
        End Sub
        

        I have to admit I’m not 100% sure whats going on here but it works after a fashion – though NT servers still show up at home due to my login scripts but I don’t have to test for those drives, do I?

        Brooke

    Viewing 0 reply threads
    Reply To: Reply #536596 in Detect Network or Drive Accesibility (97pro upwards)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel