Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 353
  • Last Modified:

Cutting Network connections

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
MarcoHelmers
Asked:
MarcoHelmers
  • 15
  • 15
1 Solution
 
chensuCommented:
Try using the NetSessionDel and NetSessionEnum functions.

0
 
MarcoHelmersAuthor Commented:
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
 
MarcoHelmersAuthor Commented:
Sorry ... but I need an answer so I am going to reopen the question to other experts.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
MarcoHelmersAuthor Commented:
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
 
trestanCommented:
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
 
chensuCommented:
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
 
chensuCommented:
Here is a relevant article.

See Who's Connected to Your Computer
http://www.frogpond.org/~markg/article/ne.html
0
 
MarcoHelmersAuthor Commented:
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
 
chensuCommented:
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
 
MarcoHelmersAuthor Commented:
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
 
chensuCommented:
Try "\\\\name" instead of "name".
0
 
chensuCommented:
And, what's the unknow error value?
0
 
MarcoHelmersAuthor Commented:
Using "\\\\name" instead of "name" did not help.
The Error is none of the 4 predefined. The ErrorCode number is:
2461.
0
 
chensuCommented:
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
 
chensuCommented:
You may use NetSessionEnum to enumerate all the sessions.
0
 
MarcoHelmersAuthor Commented:
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
 
chensuCommented:
I would suggest you try NetSessionEnum. I have no other ideas. Sorry.
0
 
chensuCommented:
I mean the name might not look like what you expect.
0
 
MarcoHelmersAuthor Commented:
hmm ... alright ... I´m going to try it.
0
 
MarcoHelmersAuthor Commented:
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
 
MarcoHelmersAuthor Commented:
Adjusted points to 65
0
 
MarcoHelmersAuthor Commented:
Does anyone have suggestions ?
0
 
MarcoHelmersAuthor Commented:
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
 
chensuCommented:
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
 
MarcoHelmersAuthor Commented:
Ok ... that was not the mistake. But why does it not work ?
I do not have any ideas any more :-(
0
 
MarcoHelmersAuthor Commented:
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
 
chensuCommented:
Apparently this part is not documented well. I don't know the reason of the error. Try using dynamic link.
0
 
chensuCommented:
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
 
chensuCommented:
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
 
MarcoHelmersAuthor Commented:
That helped ! Now everything works fine. Thanx.
Microsoft('s) (documentation) is **** !
Please log the question if you want to have the points.
0
 
chensuCommented:
I am happy that it works finally. Thank you.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 15
  • 15
Tackle projects and never again get stuck behind a technical roadblock.
Join Now