Results 1 to 4 of 4

Thread: How do i use this code?? It can't function..

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Exclamation How do i use this code?? It can't function..

    VB Code:
    1. Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long
    2. Private Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" (ByVal lpszName As String, ByVal bForce As Long) As Long
    3. Const WN_SUCCESS = 0 ' The function was successful.
    4. Const WN_NET_ERROR = 2 ' An error occurred on the network.
    5. Const WN_BAD_PASSWORD = 6 ' The password was invalid.
    6. Function AddConnection(MyShareName As String, MyPWD As String, UseLetter As String) As Integer
    7.     On Local Error GoTo AddConnection_Err
    8.     AddConnection = WNetAddConnection(MyShareName, MyPWD, UseLetter)
    9. AddConnection_End:
    10.     Exit Function
    11. AddConnection_Err:
    12.     AddConnection = Err
    13.     MsgBox Error$
    14.     Resume AddConnection_End
    15. End Function
    16. Function CancelConnection(DriveLetter As String, Force As Integer) As Integer
    17.     On Local Error GoTo CancelConnection_Err
    18.     CancelConnection = WNetCancelConnection(DriveLetter, Force)
    19. CancelConnection_End:
    20.     Exit Function
    21. CancelConnection_Err:
    22.     CancelConnection = Err
    23.     MsgBox Error$
    24.     Resume CancelConnection_End
    25. End Function
    26. Private Sub Form_Load()
    27.     'KPD-Team 1999
    28.     'URL: [url]http://www.allapi.net/[/url]
    29.     'E-Mail: [email][email protected][/email]
    30.  
    31.     'to add a connection call by:
    32.     variable = AddConnection(, , )
    33.     'To cancel a connection type:
    34.     varible = CancelConnection()
    35. End Sub

    Hai i would like to ask how do i used this code?? I've got it from http://www.mentalis.org/apilist/WNet...nnection.shtml

    It suppose to disconnect or connect the internet connection of a computer. But i can't get it to function. Can someone help me with this?? Please help...

  2. #2

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Re: How do i use this code?? It can't function..

    The error msg is compile error argment not optional. Can someone explain to me why is this happening?

    Thanks alot in advanced

  3. #3
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: How do i use this code?? It can't function..

    because you forgot to give parameters in the form_load event, here:
    VB Code:
    1. variable = AddConnection(, , )
    see the AddConnection function, it needs 3 parameters:

    1) MyShareName - Points to a null-terminated string that specifies the network resource to connect to.

    2) MyPWD - Points to a null-terminated string that specifies the password to be used to make a connection. This parameter is usually the password associated with the current user.
    If this parameter is NULL, the default password is used. If the string is empty, no password is used.

    and 3) UseLetter - Points to a null-terminated string that specifies the name of a local device to be redirected, such as F: or LPT1. The case of the characters in the string is not important. If the string is NULL, a connection to the network resource is made without redirecting the local device.

    Hope it helps you.

    Harsh Gupta
    Show Appreciation. Rate Posts.

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Talking Re: How do i use this code?? It can't function..

    Dear Harsh Gupta

    I just try to use the CancelConnection function but it also can't function.

    Sorry i'm still new with VB so what should i put in the parameter for
    variable = AddConnection(, , )

    Can you give me an example?

    This is a WNetCancelConnection function which breaks an existing network connection.

    I'm trying to disconnect the internet connection of computer and connect it back. Please give me some advise. Thanks alot

Posting Permissions

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



Click Here to Expand Forum to Full Width