Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Dec 2000
    Location
    Reading/Swindon, Berkshire, United Kingdom
    Posts
    664
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Detect Network or Drive Accesibility (97pro upwards)

    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
    [img]/forums/images/smilies/cool.gif[/img] Sub RunFromWork

    which then pass printer status to the main routine but a) I'm lazy and [img]/forums/images/smilies/cool.gif[/img] 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

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Detect Network or Drive Accesibility (97pro upwards)

    There is another set of functions that might fit better. See <A target="_blank" HREF=http://support.microsoft.com/support/kb/articles/Q177/6/97.ASP>HOWTO: List Local Network Connections with WNetEnumResources (Q177697)</A>. 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.

  3. #3
    5 Star Lounger
    Join Date
    Dec 2000
    Location
    Reading/Swindon, Berkshire, United Kingdom
    Posts
    664
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Detect Network or Drive Accesibility (97pro upwards)

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

    the code is as follows:
    <pre>Private Declare Function GetLogicalDrives Lib "KERNEL32" () As Long
    Private Sub ShowDrives()
    'KPD-Team 1999
    'URL: <A target="_blank" HREF=http://www.allapi.net/>http://www.allapi.net/</A>
    '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
    </pre>


    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •