/*!
* \brief getOthermShare tells if there is another mShare opened in this machine.
* \return
*/
bool getOthermShare()
{
bool mshare_detectado = false;
// Get the list of process identifiers
DWORD aProcesses[1024], cbNeeded, cProcesses;
//Tenta 10 vezes capturar os processos; se nao conseguir, fecha (rever isso aqui!)
for (int aaa = 0; aaa < 10; aaa++)
{
if (EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
break;
else if (aaa == 9)
{
QMessageBox::warning(NULL,
QMessageBox::tr("Error"),
QMessageBox::tr("A fatal error ocurred. Please close down your application and try again.\nIf the problem persists, enter in contact with " "the support team."));
return false;
}
}
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
// Discover the name and process identifier for each process.
for (unsigned int i = 0; i < cProcesses; i++ )
{
if( aProcesses[i] != 0 )
{
TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
// Get a handle to the process.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_ALL_ACCESS | READ_CONTROL |
PROCESS_VM_READ,
FALSE, aProcesses[i] );
// Get the process name.
if (NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName)/sizeof(TCHAR) );
}
#ifdef Q_OS_WIN
#ifdef UNICODE
if (QString::fromUtf16((ushort
*)szProcessName
).
section(".",
0,
0) == "mShare") {
if (!mshare_detectado)
mshare_detectado = true;
else
{
CloseHandle( hProcess );
return true;
}
}
#endif
#endif
// Release the handle to the process.
CloseHandle( hProcess );
}
}
}
return false;
}
/*!
* \brief getOthermShare tells if there is another mShare opened in this machine.
* \return
*/
bool getOthermShare()
{
bool mshare_detectado = false;
// Get the list of process identifiers
DWORD aProcesses[1024], cbNeeded, cProcesses;
//Tenta 10 vezes capturar os processos; se nao conseguir, fecha (rever isso aqui!)
for (int aaa = 0; aaa < 10; aaa++)
{
if (EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
break;
else if (aaa == 9)
{
QMessageBox::warning(NULL,QMessageBox::tr("Error"),QMessageBox::tr("A fatal error ocurred. Please close down your application and try again.\nIf the problem persists, enter in contact with "
"the support team."));
return false;
}
}
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
// Discover the name and process identifier for each process.
for (unsigned int i = 0; i < cProcesses; i++ )
{
if( aProcesses[i] != 0 )
{
TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
// Get a handle to the process.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_ALL_ACCESS | READ_CONTROL |
PROCESS_VM_READ,
FALSE, aProcesses[i] );
// Get the process name.
if (NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName)/sizeof(TCHAR) );
}
#ifdef Q_OS_WIN
#ifdef UNICODE
if (QString::fromUtf16((ushort*)szProcessName).section(".",0,0) == "mShare")
{
if (!mshare_detectado)
mshare_detectado = true;
else
{
CloseHandle( hProcess );
return true;
}
}
#endif
#endif
// Release the handle to the process.
CloseHandle( hProcess );
}
}
}
return false;
}
To copy to clipboard, switch view to plain text mode
Bookmarks