How do i use this code?? It can't function..
VB Code:
Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long
Private Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" (ByVal lpszName As String, ByVal bForce As Long) As Long
Const WN_SUCCESS = 0 ' The function was successful.
Const WN_NET_ERROR = 2 ' An error occurred on the network.
Const WN_BAD_PASSWORD = 6 ' The password was invalid.
Function AddConnection(MyShareName As String, MyPWD As String, UseLetter As String) As Integer
On Local Error GoTo AddConnection_Err
AddConnection = WNetAddConnection(MyShareName, MyPWD, UseLetter)
AddConnection_End:
Exit Function
AddConnection_Err:
AddConnection = Err
MsgBox Error$
Resume AddConnection_End
End Function
Function CancelConnection(DriveLetter As String, Force As Integer) As Integer
On Local Error GoTo CancelConnection_Err
CancelConnection = WNetCancelConnection(DriveLetter, Force)
CancelConnection_End:
Exit Function
CancelConnection_Err:
CancelConnection = Err
MsgBox Error$
Resume CancelConnection_End
End Function
Private Sub Form_Load()
'KPD-Team 1999
'URL: [url]http://www.allapi.net/[/url]
'to add a connection call by:
variable = AddConnection(, , )
'To cancel a connection type:
varible = CancelConnection()
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...
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
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:
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
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