if (nStatu == NERR_Success)
fprintf(stderr, "The specified session(s) has been successfully deleted\n");
else
fprintf(stderr, "A system error has occurred: %d\n", nStatu);
pTmpBuf++;
dwTotalCount++;
}
}
}
//
// Otherwise, indicate a system error.
//
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus);
//
// Free the allocated memory.
//
if (pBuf != NULL)
{
NetApiBufferFree(pBuf);
pBuf = NULL;
}
}
//
// Continue to call NetSessionEnum while
// there are more entries.
//
while (nStatus == ERROR_MORE_DATA); // end do
// Check again for an allocated buffer.
//
if (pBuf != NULL)
NetApiBufferFree(pBuf);
//
// Print the final count of sessions enumerated.
//
fprintf(stderr, "\nTotal of %d entries enumerated\n", dwTotalCount);
return 0;
}
golanshahar
May 31st, 2005, 08:04 AM
the fuction ::NetSessionDel(..) close the session between the server and the workstation.
in your code you called
Netsessiondel(NULL,pTmpBuf->sesi10_cname,NULL)
now that is wrong casue if provide NULL on the first paramter that mean u working on the local machine....i dont think this is what you want!
you should give the server name in the fisrt parameter
::Netsessiondel(L"my server name",pTmpBuf->sesi10_cname,NULL)
one more thing you must have an administartor rights for deleting a session
if i helped dont forget to rate :-)
Cheers
Himao
May 31st, 2005, 12:30 PM
Thanks for your help~Code Master!
I want to disconnect a client that connect to my PC ~
when I delete the sessions with username~
All the other clients that connects to my pc with the username also are deleted~
I have been headache for several days ~555555555
For example:
there are two sessions to my pc~
1>
client : robot
user: administrator
...
2>
client : robot2
user: administrator
....
and now I want to delete the first session(robot1)~Not all sessions.
My server name is "Himao".
so what I should do?
PS:
I am a chinese student in middle school~
I will try to perfect my bad English~~~
NoHero
May 31st, 2005, 01:06 PM
Doesn't...
NetSessionDel(S"\\\\.\\", S"\\\\robot", NULL);
... work? Try this without any other code... Because it would to be to strange if not...
Himao
May 31st, 2005, 01:18 PM
NetSessionDel(S"\\\\.\\", S"\\\\robot", NULL);
Thank you ~
return error 53~~~
Gloomy~~~~~~~~~
NoHero
May 31st, 2005, 01:28 PM
Error 53 means "Bad network path" So maybe one or both network path don't exist or are wrong.
Himao
May 31st, 2005, 01:35 PM
I use NetSessionEnum() to get the sessions~
The console shell display the sessions which I used~
So the session must be exist~~
Where is wrong????
I should finish the work today~
Gloomy again~~~~~~
NoHero
May 31st, 2005, 01:57 PM
I will test the code on my computers I will inform you on the results...
NoHero
May 31st, 2005, 02:21 PM
Well ... this code worked perfect for me until I added the code which adds \\ before the client name (the code I speak of is highlighted). So without the \\ before the username it won't work.
pTmpBuf++;
dwTotalCount++;
}
}
}
//
// Otherwise, indicate a system error.
//
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus);
//
// Free the allocated memory.
//
if (pBuf != NULL)
{
NetApiBufferFree(pBuf);
pBuf = NULL;
}
}
//
// Continue to call NetSessionEnum while
// there are more entries.
//
while (nStatus == ERROR_MORE_DATA); // end do
// Check again for an allocated buffer.
//
if (pBuf != NULL)
NetApiBufferFree(pBuf);
//
// Print the final count of sessions enumerated.
//
fprintf(stderr, "\nTotal of %d entries enumerated\n", dwTotalCount);
return 0;
}
If I pass only the username via the third parameter it also worked like a charm.
/"mike" is the name of my second PC I used for testing
Himao
May 31st, 2005, 02:24 PM
You are a "good" man~~
Thank you for your helping me~
I am online waitting for you result~~~~~~~~~~~~
I think it is the problem of parameter~
I test the function [netsessiondel] on control shell~
It deletes sessions successfully~
But now the new problem is How to translate the value "\\\\himao" to LPWSTR type~~~~~
NoHero
May 31st, 2005, 02:27 PM
I am online waitting for you result~~~~~~~~~~~~
Check my previous post
But now the new problem is How to translate the value "\\\\himao" to LPWSTR type~~~~~
The string literal? Well just put an L before it. Orif you have "himao" somewhere in a variable just use wsprintf().:
1> couldn't convert const wchar_t[1] to TCHAR [100]
2> wsprintfA : couldn't convert the seccond parameter const wchar_t[5] to LPCSTR
NoHero
May 31st, 2005, 02:51 PM
Have you changed the character set to use in your project properties section to Unicode? Or defined tha macro _UNICODE before including tchar header file?
Himao
May 31st, 2005, 02:54 PM
I have do nonthing about what you say~~~
How poorly I am when I use the knowledge~~~
NoHero
May 31st, 2005, 02:58 PM
The add
#define _UNICODE
Above the includes and add tchar to your includes...:
This is the MapRobotServerDlg.cpp
///////////////////////////////////////////////////////
#include "stdafx.h"
#include "MapSvr.h"
#include "MapSvrDlg.h"
#include ".\mapsvrdlg.h"
class CAboutDlg : public CDialog
{
....................
};
/////////////////////////////////////
I will use the function below
and what I shoul do?
NoHero
May 31st, 2005, 03:06 PM
This is the MapRobotServerDlg.cpp
///////////////////////////////////////////////////////
#include "stdafx.h"
#include "MapSvr.h"
#include "MapSvrDlg.h"
#include ".\mapsvrdlg.h"
#include <afxdtctl.h> // Internet Explorer 4 公共控件的 MFC 支持
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // Windows 公共控件的 MFC 支持
#include <afxsock.h>
#endif
////////////////////////////////////////////////////////
You are a good teacher to me~
and How small the world is~~
NoHero
May 31st, 2005, 03:11 PM
Please use code tags when posting code. And add the #define's of UNICODE, _UNICODE on top of the file and don't include tchar here. MFC does this for you.
Himao
May 31st, 2005, 03:22 PM
.............................................
NoHero
May 31st, 2005, 03:32 PM
The problem is.: I do not have any ADO installed. And it's now half past 10 pm here in Austria.
Sorry but I cannot help you anymore... I am too tired.
/may my angel be with you
Himao
May 31st, 2005, 03:39 PM
Thank you for all time for your help~~~~~~~~~~~
I will study hard in my future life~~~~~~~~~~~~~~~
Have a good night~~~~~~~~~~~~~~~~~~~~~~
It's 4:37 AM in China now~~~~~~~~~~~~~~~~~
Hoho~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Wellcome to China,Friend, NoHero~~~~~~~~~~~
Himao
May 31st, 2005, 03:43 PM
And Have a good night~~~~~~~
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.