Solved

Cutting Network connections

Posted on 1998-07-16
31
279 Views
Last Modified: 2013-11-20
I want to shut down windows automatically at a certain time and therefore need to know how to cut all network connections so that this stupid question: "There are x computers connected to you" does not appear when I shutdown. You can do this with netwatch but I need to program it. So can anyone tell me the command ?
0
Comment
Question by:MarcoHelmers
  • 15
  • 15
31 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1319262
Try using the NetSessionDel and NetSessionEnum functions.

0
 

Author Comment

by:MarcoHelmers
ID: 1319263
Are you sure that NetSessionDel is the right fuction for my problem ? As I want to disconnect all others computers from mine I simply called NetSessionDel(NULL,NULL,NULL); and he returned an unidenfied error (none of the listed). Is that the correct function to disconnect other computers from my computer like it is done with netwatch (disconnect user) even if there are no files open. If it is, where is my mistake ?
0
 

Author Comment

by:MarcoHelmers
ID: 1319264
Sorry ... but I need an answer so I am going to reopen the question to other experts.
0
 

Author Comment

by:MarcoHelmers
ID: 1319265
Perhaps you misunderstood my problem ... I don´t know exactly. I have a Win95 system and shared directories. Now other computers are able to copy files fom these directories by using their networkhood. And when I try to shutdown I get this warning whether or whether not there are files currently open.
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319266
I think you can use WNetOpenEnum to start, WNetEnumResource to continue the enumeration of resources on the network and enumeration of currently connected resources. Then use WNetCancelConnection to disconnect each of them. WNetCloseEnum to stop the enumeration. Hope it is helpful.

0
 
LVL 23

Expert Comment

by:chensu
ID: 1319267
I think WNetCancelConnection function trestan suggested is to disconnect the shares that you access from other computers, meaning that your computer is the client. It is the equivalent of the Disconnect Network Drive... menu item. In fact, your case is that your computer is the server, which exposes the shares to other computers. So, I think NetSessionDel is the right one although I have never tried it before. The other related functions are NetShareDel and NetShareSetInfo. But NetShareDel will disable the share.

0
 
LVL 23

Expert Comment

by:chensu
ID: 1319268
Here is a relevant article.

See Who's Connected to Your Computer
http://www.frogpond.org/~markg/article/ne.html
0
 

Author Comment

by:MarcoHelmers
ID: 1319269
Ok, according to your information about "sessions" I think NetSessionDel might be the right function. But why does it not work ? Give me a hint why I alway get an error when trying to disconnect every computer (user) f´rom my computer by NetSessionDel(NULL,NULL,NULL);
I also tried NetSessionDel(NULL,"name",NULL);
but that did not work either. What is wrong ? I only want to disconnect every other user from my computer.
Please help me !
0
 
LVL 23

Expert Comment

by:chensu
ID: 1319270
Are you running your application on Windows NT or 95?

If NT, only members of the Administrators or Account Operators local group can successfully execute NetSessionDel.

0
 

Author Comment

by:MarcoHelmers
ID: 1319271
I am running my application on Win95.
I have now found out that if I do not specify the second parameter (client) I get an "invalid parameters" error otherwise an unknown error !
NetSessionDel(NULL,"name",NULL); -> unknown error
NetSessionDel(NULL,NULL,"x"/NULL); -> invalid parameters

0
 
LVL 23

Expert Comment

by:chensu
ID: 1319272
Try "\\\\name" instead of "name".
0
 
LVL 23

Expert Comment

by:chensu
ID: 1319273
And, what's the unknow error value?
0
 

Author Comment

by:MarcoHelmers
ID: 1319274
Using "\\\\name" instead of "name" did not help.
The Error is none of the 4 predefined. The ErrorCode number is:
2461.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1319275
The error code is defined in lmerr.h.

#define NERR_BASE       2100

#define NERR_NoSuchSession      (NERR_BASE+361) /* The session identification does not specify a valid session. */

Make sure the name is correct.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1319276
You may use NetSessionEnum to enumerate all the sessions.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:MarcoHelmers
ID: 1319277
servername = NULL (my own computer)
clientname = "\\\\name" (client compuer that IS! connected)(it is not a wrong name !)
username = NULL (all users on that computer)

So what do you think I should change ?
0
 
LVL 23

Expert Comment

by:chensu
ID: 1319278
I would suggest you try NetSessionEnum. I have no other ideas. Sorry.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1319279
I mean the name might not look like what you expect.
0
 

Author Comment

by:MarcoHelmers
ID: 1319280
hmm ... alright ... I´m going to try it.
0
 

Author Comment

by:MarcoHelmers
ID: 1319281
That does not work (I do not get NetSessionEnum work properly).
My Compiler (VC5.0) says that a dll is missing despite i linked svrapi.dll. When I link netapi32.dll as well my Compiler does not return an error but when i run the program I get an error that the function NetSessionEnum has not been found.
Could you be so kind and send me a working example of NetSessionDel and NetSessionEnum (The one you send me does not work either).
A working NetSessionDel sample would be great ... couldn´t you try to get one (by testing it on your computer).
Please help me !
0
 

Author Comment

by:MarcoHelmers
ID: 1319282
Adjusted points to 65
0
 

Author Comment

by:MarcoHelmers
ID: 1319283
Does anyone have suggestions ?
0
 

Author Comment

by:MarcoHelmers
ID: 1319284
What about the parameters ? In the help it says it has to be Unicode strings. Is this also true for Win95 and if so, how can I convert my ansi string to unicode ? Another basic question:
Does NetSessionDel really work on Win95 ? Somewhere I read that it was not compatitible with Win95.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1319285
The actual prototype of the function is
NET_API_STATUS NET_API_FUNCTION
NetSessionDel (
    IN  LPTSTR      servername OPTIONAL,
    IN  LPTSTR      UncClientName,
    IN  LPTSTR      username
    );

And, look at the KB article
Windows 95 Support for Net Function Calls
http://support.microsoft.com/support/kb/articles/q125/7/00.asp
0
 

Author Comment

by:MarcoHelmers
ID: 1319286
Ok ... that was not the mistake. But why does it not work ?
I do not have any ideas any more :-(
0
 

Author Comment

by:MarcoHelmers
ID: 1319287
And why can I not use NetShareGetInfo and NetSessionEnum because of a linker error (unresolved external symbol _NetShareGetInfo@16) despite I linked svrapi.lib ?
When I link netapi32.lib,too I do not get the linker error any more but in that case I get an error at runtime telling me that the function (NetShareGetInfo) could not be found.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1319288
Apparently this part is not documented well. I don't know the reason of the error. Try using dynamic link.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1319289
Maybe it is documented wrongly. Include <svrapi.h> instead, you won't get the error. And the function prototype is different in the svrapi.h. I have no idea what happened.

/* 2.2  NetShareGetInfo
 *
 * Purpose: Read complete information about a single outstanding share.
 *
 * API_FUNCTION
 * NetShareGetInfo( servername, netname, level, buf, buflen, totalavail )
 * char FAR *          servername;     asciz remote server name or NULL if local
 * char FAR *          netname;        asciz network name of share being queried
 * short               level;          level of info requested (50 for Win95 peer servers)
 * char FAR *          buf;            for returned entry
 * unsigned short      buflen;         size of buffer
 * unsigned short FAR *totalavail;     total size needed for buffer
 *
 * Buffer contents on response:
 *     Level 50 contains a "struct share_info_50".
 *
 * Returns 0 if successful.  Possible error returns:
 *  ERROR_INVALID_LEVEL
 *  ERROR_INVALID_PARAMETER
 *  ERROR_BAD_NETPATH
 *  NERR_NetNotStarted
 *  NERR_ServerNotStarted
 *  NERR_NetNameNotFound
 *  NERR_MoreData
 *  NERR_BufTooSmall
 */
extern API_FUNCTION
  NetShareGetInfo ( const char FAR *     pszServer,
                    const char FAR *     pszNetName,
                    short                sLevel,
                    char FAR *           pbBuffer,
                    unsigned short       cbBuffer,
                    unsigned short FAR * pcbTotalAvail );

/***      NetSessionDel (Admin only)
 *
 *
 *      API_FUNCTION NetSessionDel( servername, clientname, reserved )
 *
 *      ENTRY
 *
 *       servername;     asciz remote srv name, NULL if local
 *      clientname;     asciz remote computer name (returned by NetSessionEnum)
 *                                     of session being deleted
 *                  In the case of a Win95 NWSERVER, the clientname should be the
 *                  ascii connection number
 *      reserved;       session key returned by NetSessionEnum
 *
 *       EXIT
 *
 *      0 = success
 *      NERR_NetNotStarted
 *  ERROR_BAD_NETPATH
 *      NERR_ServerNotStarted
 *      ERROR_INVALID_LEVEL
 *      NERR_RemoteErr
 *      NERR_RemoteOnly
 *       ERROR_ACCESS_DENIED
 *      NERR_BufTooSmall
 *      NERR_ClientNameNotFound
 *
 ***/
extern API_FUNCTION
  NetSessionDel ( const char FAR * pszServer,
                  const char FAR * pszClientName,
                  short            sReserved );

0
 
LVL 23

Expert Comment

by:chensu
ID: 1319290
According to the KB article "Windows 95 Support for Net Function Calls" I mentioned above,

"If you are only targeting Windows 95 and wish to use SVRAPI.DLL, SVRAPI.H and SVRAPI.LIB are included in the Windows 95 DDK. NOTE: The formal parameter lists for the Net function calls may be slightly different between the header files for Windows NT and Windows 95."

It seems that the documentation we read is for Windows NT.
0
 

Author Comment

by:MarcoHelmers
ID: 1319291
That helped ! Now everything works fine. Thanx.
Microsoft('s) (documentation) is **** !
Please log the question if you want to have the points.
0
 
LVL 23

Accepted Solution

by:
chensu earned 70 total points
ID: 1319292
I am happy that it works finally. Thank you.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now