473,397 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

WNetCancelConnection2 - How to Force Disconnect?

Have tried varying declares for the api call, i need to close a
connection even if resources are open (damn perfcounters)
It suggests that you can use a true (dim as a bool in the api
declare), this doesn't work, it always tells me the
getlasterrormessage of
'This network connection has files open or requests pending.'

I've tried using 1,-1 (after dimming as a long) as values, but they
still fail also

TIA

Cheers

Mack

GtErrorMessage(WNet.WNetCancelConnection2("\\192.1 68.1.2",0, 0))

Class WNet
<StructLayout(LayoutKind.Sequential)> _
Public Class NETRESOURCE
Public dwScope As Integer
Public dwType As Integer
Public dwDisplayType As Integer
Public dwUsage As Integer
Public lpLocalName As String
Public lpRemoteName As String
Public lpComment As String
Public lpProvider As String
End Class

Public Declare Ansi Function WNetAddConnection2 Lib "mpr.dll"
Alias "WNetAddConnection2A" (ByVal lpNetResource As NETRESOURCE, ByVal
lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As
Integer) As Integer
Public Declare Ansi Function WNetCancelConnection2 Lib "mpr.dll"
Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags
As Long, ByVal fForce As Long) As Integer

End Class
Nov 19 '05 #1
4 11601
Mack,

A correct declare should look like this

Public Declare Auto Function WNetCancelConnection2 Lib "mpr.dll"
(ByVal lpName As String, ByVal dwFlags As Integer, ByVal fForce As
Boolean) As Integer

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #2
I've tried that also, using true/false in the code, but it doesn't
make the slightest bit off difference, what exact value is the API
expecting? is it -1 ? does .net handle it's true/false equivalents
different to the API ?
On Tue, 26 Aug 2003 23:16:01 +0200, Mattias Sjögren
<ma********************@mvps.org> wrote:
Mack,

A correct declare should look like this

Public Declare Auto Function WNetCancelConnection2 Lib "mpr.dll"
(ByVal lpName As String, ByVal dwFlags As Integer, ByVal fForce As
Boolean) As Integer

Mattias


Nov 20 '05 #3
I've tried that also, using true/false in the code, but it doesn't
make the slightest bit off difference
In that case I don't think the problem is in your VB.NET code, but
perhaps some quirk with the API. Have you gotten it to work in some
other programming language? Have you tried it on multiple versions of
Windows?

what exact value is the API expecting? is it -1 ?
The value of Win32's TRUE is 1, but functions typically just check for
a non-zero value.

does .net handle it's true/false equivalents different to the API ?


Yes

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #4
If i use the declaration as
Public Declare Auto Function WNetCancelConnection2 Lib "mpr.dll"
(ByVal lpName As String, ByVal dwFlags As Integer, ByVal fForce As
Boolean) As Integer

then i get an error message
This network connection does not exist.

I guess this is due to the Ansi charset being used by the api?
if i use

Public Declare Ansi Function WNetCancelConnection2 Lib "mpr.dll"
(ByVal lpName As String, ByVal dwFlags As Integer, ByVal fForce As
Boolean) As Integer

then i get the error
This network connection has files open or requests pending.

If I try changing what i am disconnecting, then it does throw the
above error, so it would suggest that using the Auto in the declare is
incorrect, since it would not appear to understand the string being
passed.

I've tried changing the boolean to an integer and passing 1, but that
fails also.
Cheers

Mack
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tony Do | last post by:
I have the backup command BACKUP DATABASE NEST TO C:\\databases WITH 2 BUFFERS BUFFER 1024 $ How do I force all the user to disconnect? before running the above command
2
by: Toralf Kirsten | last post by:
Hi, we are using db2 8.1 on Linux. I'd like to close all open connection at a defined time point. Therfore I wrote a sql script including the command disconnect all or release all
5
by: wyhang | last post by:
Hi, I have a "list applications show detail" item below. DB2INST1 db2bp 524825 GAAF2D07.FB44.0E0F58094019 0003 1 8 0 Disconnect Pending 08/28/2005 21:24:11.012683 JXCRM...
2
by: http://www.visual-basic-data-mining.net/forum | last post by:
Say i have declare a module for connection and two buttons... one button has the method connect() and the other has the method disconnect().... how do i actually connect after i had disconnect...
1
by: Lee Harr | last post by:
Is there any way to forcibly disconnect all users from a database, or else force the drop of the database even though others are still connected? I have a report I run where I first drop the old...
3
by: AdrianDev | last post by:
Hi, I hope this is the right forum. From a console application running on a Windows 2003 server I have sucessfully added a connection using WNetAddConnection2 to a remote servers $IPC share....
0
by: AdrianDev | last post by:
Hi, I have sucessfully added a connection using WNetAddConnection2 to a remote servers $IPC share. But calling WNetCancelConnection2 using the share name fails error 2250: "The network...
41
by: Twayne | last post by:
Hi, How would I go about "forcing" a user from one page to another? I have a very simple random question/answer entrance requirement for an e-mail form. After 3 page views most people are...
9
by: Kelii | last post by:
Currently I have a button that allows the user to "Close Company" - at the moment it doesn't do anything :D I would like the button to "disconnect" the back end then show my Open Company form. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.