How to turn off network connection under Windows95 & Windows98

zhaozj2021-02-08  237

How to turn off network connection under Windows95 & Windows98

Huang Fei <98/5/20>

I. Problem proposes:

Whenever you access "online neighbors" via Windows95 or Windows98, the system has established two

Network connection relationship between the machine, but after the end of the access, disconnect the network connection automatically,

So sometimes we close the Windows system, pop up a dialog box, ask if the network is turned off

Connect, after answering "YES", it really begins to turn off the computer.

When the programmer has a system closing the program, it is necessary to consider this situation, although SDK provides a shutdown API:

EXITWINDOWSEX () and exitwindows (), but I found in practical applications, when specifying force shutdown

There is a problem in a particular case. So, you must find a way to disconnect the network connection.

2. Programming interface:

The network programming interface provided by Windows 95 and Windows98 is in svrapi.dll, using it

We can list the current network connection status, control or delete network connection. Windows attachments

NetWatch.exe tool is achieved.

Maybe you will ask, NetApi's detailed description is very detailed in the SDK documentation of the development tool, no need to

This demonstration. However, after looking up a lot of information, I have to say: some part of NetApi in MSDN

Ming is wrong, at least incomplete and confirmed, can be said, depending on these documents, you can't

Now all functions! The following code is what you analyze, you will find the correct application.

How big is the documentation.

3.API declaration:

Turning off the network connection implementation method is two steps: enumerate all current network connection conditions;

Disconnect the enumerated network connection.

1. Enumerate all current network connection conditions:

This API is like this in accordance with the development of helping documents:

NET_API_STATUS NetSessionNum

LPWSTR ServerName,

LPWSTR UNCCLIENTNAME,

LPWSTR Username,

DWord Level,

LPBYTE * BUFPTR,

DWORD prefmaxlen,

LPDWORD EntriesRead,

LPDWORD TOTALENTRIES,

LPDWORD RESUME_HANDLE

);

However, the actual situation is that under Windows95 and Windows98 platforms,

This call does not connect to the upper library file at all. The real API declaration should be:

DWORD NetSessionNum (LPSTR,

DWORD,

LPBYTE,

DWORD,

LPDWORD,

LPDWORD)

Parameter 1: NULL means a network connection to this machine

Parameter 2: Unknown. In the enumeration is constant 0x32.

Parameter 3: Buffer pointer for storage information

Parameter 4: Buffer length

Parameter 5: Point to return to connect

Parameter 6: Pointing to a total connection number

It can be seen that the number of parameters is completely different, and the other parameters have also changed.

2. Disconnect the enumerated network connection in turn:

It is also fortunate that the API declaration that disconnects the network connection is correct:

NET_API_STATUS NetSessionDel

LPWSTR ServerName,

LPWSTR UNCCLIENTNAME,

LPWSTR Username;

However, it is important to note that the contents of the second and third parameters need

Be degenerate from the buffer obtained by the enumeration. Specific method see the program.

Source code:

The following is a subroutine that implements disconnecting the network, you can easily join them into your own project.

Go, don't have to waste time like me to study how to achieve the network enumeration.

Note: Since this program actually uses a function declaration in a svrapi.dll, I don't have it.

Use the original header file, you can define yourself.

///

// file: NetClose.h

// Version: 1.01

#define netbuff_size 0x208

#define netsessionenum_profile (DWORD (__stdcall *) (LPSTR, DWORD, LPBYTE, DWORD, LPDWORD, LPDWORD) #define netsessionDel_profile (DWORD (__stdcall *) (LPSTR, LPSTR, DWORD))

///

// file: NetClose.cpp

// Version: 1.01

///

// define: Bool NetCloseall (Void)

// Parameters: None

// Return: True Or False

//

// Author: mr.huang fei

// Time: 5/7/1998

// NOTE: Can Only Be Used on Windows95 & Windows98

// Remark: Close All NetWork Connections

///

Bool NetCloseall (Void)

{

BYTE BYBUFF [NetBuff_size];

DWORD dwnetRet = 0 ;;

DWORD I = 0;

DWORD DWENTRIES = 0;

DWORD DWTOTALENTRIES = 0;

LPSTR SZCLIENT = NULL;

DWORD dwusername = 0;

BOOL BRET = FALSE;

LPBYTE LPBYBUFF = (lpbyte) byBuff;

DWORD (__stdcall * hooknetsessionenum) (LPSTR, DWORD, LPBYTE, DWORD, LPDWORD, LPDWORD);

DWORD (__stdcall * hooknetsessiondel) (LPSTR, LPSTR, DWORD);

Hinstance hmod = loadingLibrary ("svrapi.dll");

IF (HMOD! = NULL)

{

// get the address of function

HooknetSessionNum = NetSessionNum_profile

GetProcaddress

(HMOD, Text ("NetSessionNum"));

HooknetSESSIONDEL = NetSessionDel_Profile

GetProcaddress

(HMOD, Text ("NetSessionDel"));

IF ((HooknetSESSIONDEL! = NULL) &&

(hooknetSessionNum! = null))

{

DwnetRet = hookseessionnum (NULL,

0x32, bybuff,

NetBuff_size, & DWENTRIES,

& dwtotalentries);

IF (dwnetRet == 0) {

Bret = True;

For (i = 0; i

{

SZClient = (LPSTR) ((DWORD *)

LPBYBUFF) [0]);

DwuserName = ((DWORD *) LPBYBUFF) [2];

DwnetRet = HooknetSessionDel (NULL,

Szclient, dwusername;

IF (dwnetret! = 0)

{

Bret = false;

Break;

}

LPBYBUFF = 26;

}

} // NetSessionNum (...)

Else

Bret = false;

} // getProcAddress (...)

Else

Bret = false;

Freelibrary (HMOD);

} // loadLibrary (...)

Return Bret;

}

5. Summary:

The above is a little experience in the development process, I hope to help everyone, if you have a place, please understand and

It is pointed out. In addition, it is well known that Microsoft's development document has a considerable part of it is undisclosed.

Public information sometimes causes us a big difficult, and it is desirable to have similar experience program developers.

Written your own experience and let the later people take some detours.

转载请注明原文地址:https://www.9cbs.com/read-1286.html

New Post(0)