166 lines
4.2 KiB
C++
166 lines
4.2 KiB
C++
#include <remotepsapp/RemoteProcessInfo.hpp>
|
|
#include <remotepsapp/windowview.hpp>
|
|
#include <com/bstring.hpp>
|
|
#include <com/variant.hpp>
|
|
#include <com/vtime.hpp>
|
|
#include <com/SafeArray.hpp>
|
|
#include <remoteps/remoteps_i.c>
|
|
#include <remoteps/remoteps.h>
|
|
#include <common/purehdc.hpp>
|
|
#include <common/openfile.hpp>
|
|
#include <common/pathfnd.hpp>
|
|
#include <common/errormsg.hpp>
|
|
|
|
RemoteProcessInfo::RemoteProcessInfo(void)
|
|
: mpIRemoteProcess(0)
|
|
{
|
|
}
|
|
|
|
RemoteProcessInfo::~RemoteProcessInfo()
|
|
{
|
|
disconnect();
|
|
}
|
|
|
|
bool RemoteProcessInfo::connect(const String &serverName)
|
|
{
|
|
ServerInfo serverInfo(serverName);
|
|
MultiQuery multiQuery;
|
|
ComResult comResult;
|
|
ComObj comObj;
|
|
|
|
if(isOkay())return false;
|
|
mServerName=serverName;
|
|
multiQuery.size(1);
|
|
multiQuery[0].pIID=&IID_IRemoteProcess;
|
|
comResult=comObj.createInstance(CLSID_CoRemoteProcess,0,ClassContext(RemoteServer|LocalServer),serverInfo,multiQuery);
|
|
if(!comResult.success())
|
|
{
|
|
ErrorMessage::message(comResult.error());
|
|
return false;
|
|
}
|
|
if(!ComResult(multiQuery[0].hr).success())return false;
|
|
mpIRemoteProcess=(IRemoteProcess*)multiQuery[0].pItf;
|
|
return isOkay();
|
|
}
|
|
|
|
void RemoteProcessInfo::disconnect(void)
|
|
{
|
|
if(!isOkay())return;
|
|
mpIRemoteProcess->Release();
|
|
mpIRemoteProcess=0;
|
|
}
|
|
|
|
bool RemoteProcessInfo::getListItems(void)
|
|
{
|
|
if(!isOkay())return false;
|
|
return getListItems(mpIRemoteProcess);
|
|
}
|
|
|
|
bool RemoteProcessInfo::getDesktopWindow(WindowView &windowView)
|
|
{
|
|
if(!isOkay())return false;
|
|
return getDesktopWindow(mpIRemoteProcess,windowView);
|
|
}
|
|
|
|
bool RemoteProcessInfo::getListItems(IRemoteProcess *pIRemoteProcess)
|
|
{
|
|
Variant variant;
|
|
Variant processVariant;
|
|
String ansiString;
|
|
String strParent;
|
|
DWORD processID;
|
|
int processCount;
|
|
|
|
if(!pIRemoteProcess)return false;
|
|
processCount=0;
|
|
remove();
|
|
computerName(mServerName);
|
|
try{pIRemoteProcess->Snapshot(&variant.getVARIANT());}
|
|
catch(...){return false;}
|
|
variant.getData(VTInt4,(void*)&processCount);
|
|
variant.clear();
|
|
if(!processCount)return false;
|
|
pIRemoteProcess->GetProcessFirst(&variant.getVARIANT());
|
|
variant.getData(VTInt4,&processID);
|
|
variant.clear();
|
|
for(int index=0;index<processCount;index++)
|
|
{
|
|
pIRemoteProcess->GetModuleFirst(&variant.getVARIANT());
|
|
if(VTInt4==variant.getType())variant.clear();
|
|
else
|
|
{
|
|
BString string;
|
|
variant.getData(string);
|
|
ansiString=string.toString();
|
|
ansiString.upper();
|
|
strParent=ansiString;
|
|
insert(&ProcessItem());
|
|
ProcessItem &processItem=operator[](size()-1);
|
|
processItem.processName(ansiString);
|
|
processItem.processID(processID);
|
|
variant.clear();
|
|
while(true)
|
|
{
|
|
pIRemoteProcess->GetModuleNext(&variant.getVARIANT());
|
|
if(VTInt4==variant.getType())
|
|
{
|
|
variant.clear();
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
BString string;
|
|
variant.getData(string);
|
|
ansiString=string.toString();
|
|
ansiString.upper();
|
|
processItem.insert(&ansiString);
|
|
variant.clear();
|
|
}
|
|
}
|
|
}
|
|
pIRemoteProcess->GetProcessNext(&variant.getVARIANT());
|
|
variant.getData(VTInt4,&processID);
|
|
variant.clear();
|
|
}
|
|
return size()?true:false;
|
|
}
|
|
|
|
bool RemoteProcessInfo::getDesktopWindow(IRemoteProcess *pIRemoteProcess,WindowView &windowView)
|
|
{
|
|
String strFileName("image000.tmp");
|
|
String strPathFileName;
|
|
FileHandle outFile;
|
|
Variant variant;
|
|
SafeArray safeArray;
|
|
int upperBound;
|
|
BYTE *pData;
|
|
GlobalData<BYTE> imageBytes;
|
|
PathFind pathFind;
|
|
|
|
pathFind.getWindowsTempDirectory(strPathFileName);
|
|
strPathFileName+=strFileName;
|
|
pIRemoteProcess->GetDesktopWindow(&variant.getVARIANT());
|
|
if(VTArray!=variant.getType()){variant.clear();return false;}
|
|
if(!variant.getData(safeArray)){variant.clear();return false;}
|
|
upperBound=safeArray.getUpperBound();
|
|
safeArray.accessData((void**)&pData);
|
|
imageBytes.size(*((DWORD*)pData));
|
|
::memcpy(&imageBytes[0],pData+(sizeof(DWORD)),imageBytes.size());
|
|
outFile.open(strPathFileName,FileHandle::Write,FileHandle::ShareRead,FileHandle::Overwrite);
|
|
if(!outFile.isOkay())
|
|
{
|
|
safeArray.unaccessData();
|
|
safeArray.destroy();
|
|
variant.clear();
|
|
return false;
|
|
}
|
|
outFile.write(&imageBytes[0],imageBytes.size());
|
|
outFile.close();
|
|
windowView.createImage(strPathFileName);
|
|
::unlink(strPathFileName);
|
|
safeArray.unaccessData();
|
|
safeArray.destroy();
|
|
variant.clear();
|
|
return true;
|
|
}
|