RemoteC.cpp
资源名称:anywhere.zip [点击查看]
上传用户:zhenhuadz
上传日期:2007-01-07
资源大小:1511k
文件大小:20k
源码类别:
远程控制编程
开发平台:
Visual C++
- // RemoteC.cpp: implementation of the CRemoteC class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "AnyServer.h"
- #include "AnyServerDoc.h"
- #include "ChatLsnSock.h"
- #include "ChatSock.h"
- #include "RemoteC.h"
- #include "io.h"
- #include "direct.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CString m_szResolution="1024*768";
- IMPLEMENT_DYNCREATE(CRemoteC, CObject)
- BOOL KillProcess(CTaskListEntry* pEntry, BOOL fForce);
- CRemoteC::CRemoteC()
- {
- m_filelist.RemoveAll();
- }
- CRemoteC::~CRemoteC()
- {
- }
- extern CCriticalSection CriticalSection;
- extern CCriticalSection CriticalData;
- UINT SendFile(LPVOID pParam);
- UINT PutFile(LPVOID pParam);
- HANDLE hEvent;
- HANDLE hPutFile;
- extern BOOL beAssumed;
- extern char* data;
- void CRemoteC::Command(SCommand command,CString& DataBuf,int nLength)
- {
- if (command==GETINFO)
- {
- m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理GetInfo");
- CriticalSection.Lock();
- SYS_INFO* m_sys_info=GetSysInfo();
- DataBuf.Empty();
- DataBuf="GETINFO*"+m_sys_info->m_stComputerName+"*"+
- m_sys_info->m_stUserName+"*"+
- m_sys_info->m_stVendorInfo+"*"+
- m_sys_info->m_stIdentify+"*"+
- m_sys_info->m_stProcessorLevel+"*"+
- m_sys_info->m_stNumProcessors+"*"+
- m_sys_info->m_stPhysicalMemory+"*"+
- m_sys_info->m_stPhysicalMemAvailable+"*"+
- m_sys_info->m_stDriver+"*";
- CriticalSection.Unlock();
- }
- else if (command==VIEWSCR)
- {
- m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理ViewScr");
- CRect Rect;
- (CWnd::FromHandle(::GetDesktopWindow()))->GetWindowRect(&Rect);
- char *filename;
- hEvent=::CreateEvent(NULL,FALSE,FALSE,"ViewScr");
- filename=CopyScreenToBitmap(&Rect);
- CriticalSection.Lock();
- DataBuf="VIEWSCR*";
- CriticalSection.Unlock();
- strcat(filename,"x9113");
- AfxBeginThread(SendFile,filename,THREAD_PRIORITY_NORMAL);
- ::WaitForSingleObject(hEvent,INFINITE);
- }
- else if (command==ENDSERVE)
- {
- m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("客户端请求断开!");
- CriticalSection.Lock();
- DataBuf="ENDSERVE";
- CriticalSection.Unlock();
- if (((CAnyServerDoc*)(m_pView->GetDocument()))->m_pConnect!=NULL&&((CAnyServerDoc*)(m_pView->GetDocument()))->m_pConnect->m_hSocket!=INVALID_SOCKET)
- {
- ((CAnyServerDoc*)(m_pView->GetDocument()))->m_pConnect->Close();
- delete ((CAnyServerDoc*)(m_pView->GetDocument()))->m_pConnect;
- ((CAnyServerDoc*)(m_pView->GetDocument()))->m_pConnect=NULL;
- }
- m_pView->SendMessage(WM_VALID,(WPARAM)FALSE,0);
- m_pView->SendMessage(WM_USERNAME,(WPARAM)FALSE,0);
- m_pView->SendMessage(WM_IPADDR,0,(LPARAM)FALSE);
- beAssumed=FALSE;
- }
- else if (command==LOCKKEY)
- {
- m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理LockKey");
- CriticalSection.Lock();
- DataBuf="LOCKKEY*";
- CriticalSection.Unlock();
- ::SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,1,0,0);
- }
- else if (command==UNLOCK)
- {
- m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理Unlock");
- CriticalSection.Lock();
- DataBuf="UNLOCK**";
- CriticalSection.Unlock();
- ::SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,0,0,0);
- }
- else if (command==GETFILE)
- {
- m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理GetFile");
- char *filename=new char[MAX_PATH];
- CriticalSection.Lock();
- DataBuf="GETFILE*";
- CriticalSection.Unlock();
- hEvent=::CreateEvent(NULL,FALSE,FALSE,"GetFile");
- CriticalData.Lock();
- strcpy(filename,data);
- delete data;
- CriticalData.Unlock();
- strcat(filename,"x9110");
- AfxBeginThread(SendFile,filename,THREAD_PRIORITY_NORMAL);
- ::WaitForSingleObject(hEvent,INFINITE);
- }
- else if (command==PUTFILE)
- {
- m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理PutFile");
- char *filename=new char [MAX_PATH];
- CriticalSection.Lock();
- DataBuf="PUTFILE*";
- CriticalSection.Unlock();
- hPutFile=::CreateEvent(NULL,FALSE,FALSE,"PutFile");
- CriticalData.Lock();
- strcpy(filename,data);
- delete data;
- CriticalData.Unlock();
- strcat(filename,"x9111");
- AfxBeginThread(PutFile,filename,THREAD_PRIORITY_NORMAL);
- ::WaitForSingleObject(hPutFile,INFINITE);
- }
- else if (command==LISTFILE)
- {
- m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理ListFile");
- CriticalData.Lock();
- ::SetCurrentDirectory(data);
- delete data;
- CriticalData.Unlock();
- CFileFind FileFinder;
- CString tmpFileName;
- while (m_filelist.GetCount())
- m_filelist.RemoveHead();
- BOOL bWorking = FileFinder.FindFile("*.*");
- while (bWorking)
- {
- bWorking = FileFinder.FindNextFile();
- tmpFileName=FileFinder.GetFileName();
- if (FileFinder.GetFileName()!=".")
- {
- if (FileFinder.IsDirectory())
- tmpFileName+="*";
- else
- {
- CString temp;
- temp.Format("%ld",FileFinder.GetLength());
- tmpFileName+="?";
- tmpFileName+=temp;
- }
- m_filelist.AddTail(tmpFileName);
- }
- }
- DataBuf="LISTFILE";
- POSITION Pos=m_filelist.GetHeadPosition();
- CriticalSection.Lock();
- for (int i=1;i<=m_filelist.GetCount();i++)
- {
- DataBuf+=m_filelist.GetNext(Pos);
- DataBuf+="/";
- }
- CriticalSection.Unlock();
- }
- else if (command==SHUTDOWN)
- {
- m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理ShutDown");
- CriticalSection.Lock();
- DataBuf="SHUTDOWN";
- CriticalSection.Unlock();
- ShutDown();
- }
- else if (command==LOGOFF)
- {
- m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理LogOff");
- CriticalSection.Lock();
- DataBuf="LOGOFF**";
- CriticalSection.Unlock();
- LogOff();
- }
- else if (command==LISTPROC)
- {
- m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理ListProc");
- CString temp=ListProc(FALSE,"");
- CriticalSection.Lock();
- DataBuf="LISTPROC"+temp;
- CriticalSection.Unlock();
- }
- else if (command==KILLPROC)
- {
- m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理KillProc");
- CriticalSection.Lock();
- DataBuf="KILLPROC";
- CriticalSection.Unlock();
- CriticalData.Lock();
- CString temp=data;
- delete data;
- CriticalData.Unlock();
- ListProc(TRUE,temp);
- }
- else if (command==RESTART)
- {
- m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理Restart");
- CriticalSection.Lock();
- DataBuf="RESTART*";
- CriticalSection.Unlock();
- Restart();
- }
- else if (command==RUNFILE)
- {
- m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理RunFile");
- CriticalSection.Lock();
- DataBuf="RUNFILE*";
- CriticalSection.Unlock();
- CriticalData.Lock();
- ::ShellExecute(NULL,NULL,data,NULL,NULL,SW_SHOW);
- delete data;
- CriticalData.Unlock();
- }
- else if (command==DELFILE)
- {
- m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理DelFile");
- CriticalSection.Lock();
- DataBuf="DELFILE*";
- CriticalSection.Unlock();
- CriticalData.Lock();
- ::DeleteFile(data);
- delete data;
- CriticalData.Unlock();
- }
- else if (command==CONFIG)
- {
- m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理Config");
- int x=::GetSystemMetrics(SM_CXSCREEN);
- int y=::GetSystemMetrics(SM_CYSCREEN);
- char* tempx=new char [10];
- char* tempy=new char [10];
- itoa(x,tempx,10);
- itoa(y,tempy,10);
- CriticalSection.Lock();
- DataBuf+="CONFIG**";
- DataBuf+=tempx;
- DataBuf+="*";
- DataBuf+=tempy;
- CriticalSection.Unlock();
- delete tempx;
- delete tempy;
- CriticalData.Lock();
- CString szData=data;
- delete data;
- CriticalData.Unlock();
- CString szUser=szData.Left(8);
- CString szPassword=szData.Mid(8,8);
- m_szResolution=szData.Right(szData.GetLength()-16);
- AfxGetApp()->WriteProfileString("AnyServer",szUser,szPassword);
- }
- else if (command==FINDFILE)
- {
- m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理FindFile");
- CriticalSection.Lock();
- DataBuf="FINDFILE";
- char sTmp[4];
- memset(sTmp,0,4);
- strcpy(sTmp,"C:\");
- for (int drv='C';drv<='Z';drv++)
- {
- sTmp[0] = (char)drv;
- if (GetDriveType(sTmp) == DRIVE_FIXED)
- {
- _chdir(sTmp);
- Search_Directory(data,DataBuf);
- }
- }
- delete data;
- CriticalSection.Unlock();
- }
- }
- SYS_INFO* CRemoteC::GetSysInfo()
- {
- SYSTEM_INFO sysInfo;
- static SYS_INFO m_sys_info;
- char str [MAX_PATH];
- LONG result;
- HKEY hKey;
- TCHAR vendorData [64];
- DWORD dataSize;
- result = ::RegOpenKeyEx (HKEY_LOCAL_MACHINE,
- "Hardware\Description\System\CentralProcessor\0", 0, KEY_QUERY_VALUE, &hKey);
- // Check if the function has succeeded.
- if (result == ERROR_SUCCESS) {
- dataSize = sizeof (vendorData);
- result = ::RegQueryValueEx (hKey, _T("VendorIdentifier"), NULL, NULL,
- (LPBYTE)vendorData, &dataSize);
- m_sys_info.m_stVendorInfo.Format ("%s", vendorData);
- result =::RegQueryValueEx (hKey,_T("Identifier"),NULL,NULL,
- (LPBYTE)vendorData,&dataSize);
- m_sys_info.m_stIdentify.Format ("%s",vendorData);
- }
- // Make sure to close the reg key
- RegCloseKey (hKey);
- // Get the hardware information
- GetSystemInfo (&sysInfo);
- // check number of processors
- itoa (sysInfo.dwNumberOfProcessors , str, 10);
- m_sys_info.m_stNumProcessors = CString (str);
- // Check the architecture type and processor level
- // Windows 95 doesn't use processor level
- if (sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) {
- switch (sysInfo.wProcessorLevel) {
- case 3:
- m_sys_info.m_stProcessorLevel = _T ("Intel 80386");
- break;
- case 4:
- m_sys_info.m_stProcessorLevel = _T ("Intel 80486");
- break;
- case 5:
- m_sys_info.m_stProcessorLevel = _T ("Pentium");
- // Check if the MMX instruction set is availbale or not.
- if (IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE)) {
- m_sys_info.m_stProcessorLevel += _T (" MMX");
- }
- break;
- case 6:
- m_sys_info.m_stProcessorLevel = _T ("Pentium (II/Pro)");
- break;
- }
- }
- else if (sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_MIPS) {
- if (sysInfo.wProcessorLevel == 0004) {
- m_sys_info.m_stProcessorLevel = _T ("MIPS R4000");
- }
- else {
- m_sys_info.m_stProcessorLevel = _T ("Unknown");
- }
- }
- else if (sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_ALPHA) {
- itoa (sysInfo.wProcessorLevel , str, 10);
- }
- else if (sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_PPC) {
- switch (sysInfo.wProcessorLevel) {
- case 1:
- m_sys_info.m_stProcessorLevel = _T ("PPC 601");
- break;
- case 3:
- m_sys_info.m_stProcessorLevel = _T ("PPC 603");
- break;
- case 4:
- m_sys_info.m_stProcessorLevel = _T ("PPC 604");
- break;
- case 6:
- m_sys_info.m_stProcessorLevel = _T ("PPC 603+");
- break;
- case 9:
- m_sys_info.m_stProcessorLevel = _T ("PPC 604+");
- break;
- case 20:
- m_sys_info.m_stProcessorLevel = _T ("PPC 620");
- break;
- }
- }
- else if (sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_UNKNOWN) {
- }
- double var;
- MEMORYSTATUS memoryStatus;
- memset (&memoryStatus, sizeof (MEMORYSTATUS), 0);
- memoryStatus.dwLength = sizeof (MEMORYSTATUS);
- GlobalMemoryStatus (&memoryStatus);
- var = memoryStatus.dwTotalPhys / 1024;
- m_sys_info.m_stPhysicalMemory.Format ("%7.0f", var);
- m_sys_info.m_stPhysicalMemory += _T (" KB");
- m_sys_info.m_stPhysicalMemory.TrimLeft ();
- var = memoryStatus.dwAvailPhys / 1024;
- m_sys_info.m_stPhysicalMemAvailable.Format ("%7.0f", var);
- m_sys_info.m_stPhysicalMemAvailable += _T (" KB");
- m_sys_info.m_stPhysicalMemAvailable.TrimLeft ();
- LPTSTR nameBuf=new char[MAX_PATH];
- DWORD nSize=MAX_PATH;
- GetComputerName(nameBuf,&nSize);
- m_sys_info.m_stComputerName=nameBuf;
- GetUserName(nameBuf,&nSize);
- m_sys_info.m_stUserName=nameBuf;
- m_sys_info.m_stDriver.Empty();
- char sTmp[4];
- memset(sTmp,0,4);
- strcpy(sTmp,"C:\");
- for (int drv='C';drv<='Z';drv++)
- {
- sTmp[0] = (char)drv;
- if (GetDriveType(sTmp) == DRIVE_FIXED)
- {
- m_sys_info.m_stDriver+=sTmp;
- }
- }
- return (&m_sys_info);
- }
- LPTSTR CRemoteC::CopyScreenToBitmap(LPRECT lpRect)
- {
- HDC hScrDC, hMemDC; // 屏幕和内存设备描述表
- HBITMAP hBitmap,hOldBitmap; // 位图句柄
- int nX, nY, nX2, nY2; // 选定区域坐标
- int nWidth, nHeight; // 位图宽度和高度
- int xScrn, yScrn; // 屏幕分辨率
- // 确保选定区域不为空矩形
- if (IsRectEmpty(lpRect)) return NULL;
- //为屏幕创建设备描述表
- hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL);
- //为屏幕设备描述表创建兼容的内存设备描述表
- hMemDC = CreateCompatibleDC(hScrDC);
- // 获得选定区域坐标
- nX = lpRect->left;
- nY = lpRect->top;
- nX2 = lpRect->right;
- nY2 = lpRect->bottom;
- // 获得屏幕分辨率
- xScrn = GetDeviceCaps(hScrDC, HORZRES);
- yScrn = GetDeviceCaps(hScrDC, VERTRES);
- //确保选定区域是可见的
- if (nX < 0) nX = 0;
- if (nY < 0) nY = 0;
- if (nX2 > xScrn) nX2 = xScrn;
- if (nY2 > yScrn) nY2 = yScrn;
- nWidth = nX2 - nX;
- nHeight = nY2 - nY;
- // 创建一个与屏幕设备描述表兼容的位图
- int *temp=new int(m_szResolution.Find("*"));
- char *pWidth=new char[10];
- char *pHeight=new char[10];
- strcpy(pWidth,m_szResolution.Mid(0,*temp));
- strcpy(pHeight,m_szResolution.Mid(*temp+1));
- delete temp;
- int nDestResWidth=atoi(pWidth);
- int nDestResHeight=atoi(pHeight);
- delete pWidth;
- delete pHeight;
- hBitmap = CreateCompatibleBitmap(hScrDC, nDestResWidth, nDestResHeight);
- // 把新位图选到内存设备描述表中
- hOldBitmap=(HBITMAP)::SelectObject(hMemDC, hBitmap);
- // 把屏幕设备描述表拷贝到内存设备描述表中
- StretchBlt(hMemDC, 0, 0, nDestResWidth, nDestResHeight,hScrDC, nX, nY,nWidth,nHeight,SRCCOPY);
- //得到屏幕位图的句柄
- hBitmap =(HBITMAP) ::SelectObject(hMemDC, hOldBitmap);
- //清除
- DeleteDC(hScrDC);
- DeleteDC(hMemDC);
- char tmppath[MAX_PATH];
- char *tmpname=new char[MAX_PATH];
- GetTempPath(MAX_PATH,tmppath);
- GetTempFileName(tmppath,"AnyServer",0,tmpname);//获得一个唯一的临时文件名
- SaveBitmapToFile(hBitmap,tmpname);
- return tmpname;
- }
- int CRemoteC::SaveBitmapToFile(HBITMAP hBitmap, LPSTR lpFileName)
- {
- //我们也可以把屏幕内容以位图格式存到磁盘文件上.
- //lpFileName 为位图文件名
- HDC hDC; //设备描述表
- int iBits; //当前显示分辨率下每个像素所占字节数
- WORD wBitCount; //位图中每个像素所占字节数
- //定义调色板大小, 位图中像素字节大小,位图文件大小,写入文件字节数
- DWORD dwPaletteSize=0,
- dwBmBitsSize,
- dwDIBSize, dwWritten;
- BITMAP Bitmap; //位图属性结构
- BITMAPFILEHEADER bmfHdr; //位图文件头结构
- BITMAPINFOHEADER bi; //位图信息头结构
- LPBITMAPINFOHEADER lpbi; //指向位图信息头结构
- HANDLE fh, hDib, hPal,hOldPal=NULL;
- //定义文件,分配内存句柄,调色板句柄
- //计算位图文件每个像素所占字节数
- hDC = CreateDC("DISPLAY",NULL,NULL,NULL);
- iBits = GetDeviceCaps(hDC, BITSPIXEL)*GetDeviceCaps(hDC, PLANES);
- DeleteDC(hDC);
- if (iBits <= 1)
- wBitCount = 1;
- else if (iBits <= 4)
- wBitCount = 4;
- else if (iBits <= 8)
- wBitCount = 8;
- else if (iBits <= 32)
- wBitCount = 24;
- //计算调色板大小
- if (wBitCount <= 8)
- dwPaletteSize = (1 << wBitCount) *
- sizeof(RGBQUAD);
- //设置位图信息头结构
- GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&Bitmap);
- bi.biSize = sizeof(BITMAPINFOHEADER);
- bi.biWidth = Bitmap.bmWidth;
- bi.biHeight = Bitmap.bmHeight;
- bi.biPlanes = 1;
- bi.biBitCount = wBitCount;
- bi.biCompression = BI_RGB;
- bi.biSizeImage = 0;
- bi.biXPelsPerMeter = 0;
- bi.biYPelsPerMeter = 0;
- bi.biClrUsed = 0;
- bi.biClrImportant = 0;
- dwBmBitsSize = ((Bitmap.bmWidth*wBitCount+31)/32)* 4*Bitmap.bmHeight ;
- hDib = GlobalAlloc(GHND,dwBmBitsSize+dwPaletteSize+sizeof(BITMAPINFOHEADER));//为位图内容分配内存
- lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDib);
- *lpbi = bi;
- hPal=(HPALETTE)::GetStockObject(DEFAULT_PALETTE);// 处理调色板
- if (hPal)
- {
- hDC = GetDC(NULL);
- hOldPal = SelectPalette(hDC,(HPALETTE)hPal, FALSE);
- RealizePalette(hDC);
- }
- // 获取该调色板下新的像素值
- GetDIBits(hDC, hBitmap, 0, (UINT) Bitmap.bmHeight,
- (LPSTR)lpbi + sizeof(BITMAPINFOHEADER)
- +dwPaletteSize,
- (BITMAPINFO *)
- lpbi, DIB_RGB_COLORS);
- //恢复调色板
- if (hOldPal)
- {
- SelectPalette(hDC,(HPALETTE) hOldPal, TRUE);
- RealizePalette(hDC);
- ReleaseDC(NULL, hDC);
- }
- //创建位图文件
- fh = CreateFile(lpFileName, GENERIC_WRITE,0, NULL, CREATE_ALWAYS,
- FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN, NULL);
- if (fh == INVALID_HANDLE_VALUE)
- return FALSE;
- // 设置位图文件头
- bmfHdr.bfType = 0x4D42; // "BM"
- dwDIBSize = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)
- + dwPaletteSize + dwBmBitsSize;
- bmfHdr.bfSize = dwDIBSize;
- bmfHdr.bfReserved1 = 0;
- bmfHdr.bfReserved2 = 0;
- bmfHdr.bfOffBits = (DWORD)sizeof
- (BITMAPFILEHEADER)
- + (DWORD)sizeof(BITMAPINFOHEADER)
- + dwPaletteSize;
- // 写入位图文件头
- WriteFile(fh, (LPSTR)&bmfHdr, sizeof
- (BITMAPFILEHEADER), &dwWritten, NULL);
- // 写入位图文件其余内容
- WriteFile(fh, (LPSTR)lpbi, dwDIBSize,
- &dwWritten, NULL);
- //清除
- GlobalUnlock(hDib);
- GlobalFree(hDib);
- CloseHandle(fh);
- return TRUE;
- }
- void CRemoteC::ShutDown()
- {
- ::ExitWindowsEx(EWX_SHUTDOWN,0);
- }
- void CRemoteC::Restart()
- {
- ::ExitWindowsEx(EWX_REBOOT,0);
- }
- CCriticalSection CriticalBuf;
- void CRemoteC::Search_Directory(char *szFilename, CString &DataBuf)
- {
- long handle;
- struct _finddata_t filestruct;
- char path_search [MAX_PATH];
- handle=_findfirst("*",&filestruct);
- if ((handle==-1)) return;
- if(::GetFileAttributes(filestruct.name)&FILE_ATTRIBUTE_DIRECTORY)
- {
- if (filestruct.name[0]!='.')
- {
- _chdir(filestruct.name);
- Search_Directory(szFilename,DataBuf);
- _chdir("..");
- }
- }
- else
- {
- if (!stricmp(filestruct.name,szFilename))
- {
- _getcwd(path_search,MAX_PATH);
- if (path_search[strlen(path_search)-1]!='\') strcat(path_search,"\");
- strcat(path_search,filestruct.name);
- CriticalBuf.Lock();
- DataBuf+=path_search;
- DataBuf+="/";
- CriticalBuf.Unlock();
- }
- }
- while(!(_findnext(handle,&filestruct)))
- {
- if (::GetFileAttributes(filestruct.name)&FILE_ATTRIBUTE_DIRECTORY)
- {
- if (*filestruct.name!='.')
- {
- _chdir(filestruct.name);
- Search_Directory(szFilename,DataBuf);
- _chdir("..");
- }
- }
- else
- {
- if (!stricmp(filestruct.name,szFilename))
- {
- _getcwd(path_search,MAX_PATH);
- if (path_search[strlen(path_search)-1]!='\') strcat(path_search,"\");
- strcat(path_search,filestruct.name);
- CriticalBuf.Lock();
- DataBuf+=path_search;
- DataBuf+="/";
- CriticalBuf.Unlock();
- }
- }
- }
- _findclose(handle);
- }
- void CRemoteC::LogOff()
- {
- ::ExitWindowsEx(EWX_LOGOFF,0);
- }
- CString CRemoteC::ListProc(BOOL bKill, CString kill_proc)
- {
- LPGetTaskList GetTaskList; //定义函数指针
- LPEnableDebugPriv EnableDebugPriv;//也是一个指针
- OSVERSIONINFO verInfo;
- memset(&verInfo, 0, sizeof(verInfo));
- verInfo.dwOSVersionInfoSize = sizeof(verInfo);
- GetVersionEx(&verInfo);
- CString tmp;
- switch (verInfo.dwPlatformId)
- {
- case VER_PLATFORM_WIN32_NT:
- GetTaskList = GetTaskListNT;
- EnableDebugPriv = EnableDebugPrivNT;
- break;
- case VER_PLATFORM_WIN32_WINDOWS:
- GetTaskList = GetTaskList95;
- EnableDebugPriv = EnableDebugPriv95;
- break;
- default:
- tmp="FAILED**";
- return tmp;
- }
- EnableDebugPriv();
- // get the task list for the system
- ClearTaskList();
- CTaskList& refTaskList = gettasklist();
- DWORD numTasks = GetTaskList(refTaskList);
- // enumerate all windows and try to get the window
- // titles for each task
- GetWindowTitles(refTaskList);
- int n;
- for (n = 0; n < refTaskList.GetSize(); n++)
- {
- if ((bKill) && (kill_proc==refTaskList[n]->ProcessName))
- {
- BOOL bResult = KillProcess(refTaskList[n], TRUE);
- if (bResult)
- {
- }
- }
- else tmp=tmp+refTaskList[n]->ProcessName+"/";
- }
- return tmp;
- }
- CRemoteC::CRemoteC(CView*pView)
- {
- m_pView=pView;
- }
- void CRemoteC::ClearTaskList()
- {
- int n;
- for (n = 0; n < m_tasklist.GetSize(); n++)
- delete m_tasklist[n];
- m_tasklist.RemoveAll();
- }
- CTaskList& CRemoteC::gettasklist()
- {
- return m_tasklist;
- }