Yorumları: 90
Konuları: 17
Kayıt Tarihi: 09-09-2017
Aktif Kullandığınız Delphi Sürümü:
Rep Puanı: 123 Başlangıç
06-06-2019, Saat: 16:52
(Son Düzenleme: 07-06-2019, Saat: 19:30, Düzenleyen: theSinan.)
s.a Bütün Müslümanların Bayramı mübarek olsun
Rabbim Bütün müslüman alemine nice hayırlı Bayramlar nasip etsin
Windows Uygulamasında Başka Bir Uygulamanın Çalışıp Çalışmadığını
Aşağıdaki Fonksiyon ile Kontrol Edebiliyorum
ancak Windows Service Uygulaması içinden çalıştırdığımda Uygulamanın ProgressId sini alamıyorum
servisin interactive Özelliğini True yaptım yine sonuç aynı neden olabilir acaba
Yardımlarınız için allah razı olsun
DWORD __fastcall ThreadUygulamaKontrol::UYGULAMA_DURUM_KONTROL(String UYGULAMA_ADI)
{
try
{
DWORD ProcessID;
HWND hwnd = FindWindow(0,UYGULAMA_ADI.w_str());
GetWindowThreadProcessId(hwnd,&ProcessID);
if(hwnd)
{
return ProcessID;
}
else
return 0;
}
catch(Exception *HATA)
{
//Form1->HATA->RAPORLA("Uygulama Id Arama Hatası : "+HATA->Message,1);
}
}
Yorumları: 90
Konuları: 17
Kayıt Tarihi: 09-09-2017
Aktif Kullandığınız Delphi Sürümü:
Rep Puanı: 123 Başlangıç
S.a Servis Uygulamaları 0 Oturumda Çalıştığından
Normal Uygulamada Kullandığım Fonksiyon Windows servis Uygulamasında işe yaramamıştı
WMI işe Sorunumu Çözdüm fonksiyon aşağıdadır
sorgulamak istediğiniz exenin adını fonksiyona parametre olarak göndermek yetiyor
çalışan programlar listesinde var ise yine exe adını geri döndürüyor yok ise boş geliyor
İnternette bir çok kişi bu sorunla karşılaşmış ancak basit çözüm bulunamamış
inşallah faydası olur
#include <windows.h>
#include <vector>
#include <string>
#pragma comment( lib, "Version.lib" )
using namespace std;
#include <wbemcli.h>
#include <comdef.h>
//---------------------------------------------------------------------------
#define CRED_MAX_USERNAME_LENGTH 513
#define CRED_MAX_CREDENTIAL_BLOB_SIZE 512
#define CREDUI_MAX_USERNAME_LENGTH CRED_MAX_USERNAME_LENGTH
#define CREDUI_MAX_PASSWORD_LENGTH (CRED_MAX_CREDENTIAL_BLOB_SIZE / 2)
#pragma argsused
//---------------------------------------------------------------------------
#pragma package(smart_init)
UnicodeString TGergerServis::GorevListesiSorgula(String Program_Ad)
{
//--------------------------------------------------------------------------------------
UnicodeString strGeriDonus="";
wchar_t pszName[CREDUI_MAX_USERNAME_LENGTH+1] = L"user";
wchar_t pszPwd[CREDUI_MAX_PASSWORD_LENGTH+1] = L"password";
BSTR strNetworkResource;
//To use a WMI remote connection set localconn to false and configure the values of the pszName, pszPwd and the name of the remote machine in strNetworkResource
bool localconn = true;
strNetworkResource = localconn ? L"\\\\.\\root\\CIMV2" : L"\\\\remote--machine\\root\\CIMV2";
COAUTHIDENTITY *userAcct = NULL ;
COAUTHIDENTITY authIdent;
// Initialize COM. ------------------------------------------
HRESULT hres;
hres = CoInitializeEx(0, COINIT_MULTITHREADED);
// Set general COM security levels --------------------------
if (localconn)
hres = CoInitializeSecurity(
NULL,
-1, // COM authentication
NULL, // Authentication services
NULL, // Reserved
RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication
RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
NULL, // Authentication info
EOAC_NONE, // Additional capabilities
NULL // Reserved
);
else
hres = CoInitializeSecurity(
NULL,
-1, // COM authentication
NULL, // Authentication services
NULL, // Reserved
RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication
RPC_C_IMP_LEVEL_IDENTIFY, // Default Impersonation
NULL, // Authentication info
EOAC_NONE, // Additional capabilities
NULL // Reserved
);
// Obtain the initial locator to WMI -------------------------
IWbemLocator *pLoc = NULL;
hres = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc);
// Connect to WMI through the IWbemLocator::ConnectServer method
IWbemServices *pSvc = NULL;
if (localconn)
hres = pLoc->ConnectServer(
strNetworkResource, // Object path of WMI namespace
NULL, // User name. NULL = current user
NULL, // User password. NULL = current
0, // Locale. NULL indicates current
NULL, // Security flags.
0, // Authority (e.g. Kerberos)
0, // Context object
&pSvc // pointer to IWbemServices proxy
);
else
hres = pLoc->ConnectServer(
strNetworkResource, // Object path of WMI namespace
pszName, // User name
pszPwd, // User password
NULL, // Locale
NULL, // Security flags
NULL, // Authority
NULL, // Context object
&pSvc // IWbemServices proxy
);
// Set security levels on the proxy -------------------------
if (localconn)
hres = CoSetProxyBlanket(
pSvc, // Indicates the proxy to set
RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx
RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx
NULL, // Server principal name
RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx
RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
NULL, // client identity
EOAC_NONE // proxy capabilities
);
else
{
// Create COAUTHIDENTITY that can be used for setting security on proxy
memset(&authIdent, 0, sizeof(COAUTHIDENTITY));
authIdent.PasswordLength = wcslen (pszPwd);
authIdent.Password = (USHORT*)pszPwd;
authIdent.User = (USHORT*)pszName;
authIdent.UserLength = wcslen(pszName);
authIdent.Domain = 0;
authIdent.DomainLength = 0;
authIdent.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
userAcct = &authIdent;
hres = CoSetProxyBlanket(
pSvc, // Indicates the proxy to set
RPC_C_AUTHN_DEFAULT, // RPC_C_AUTHN_xxx
RPC_C_AUTHZ_DEFAULT, // RPC_C_AUTHZ_xxx
COLE_DEFAULT_PRINCIPAL, // Server principal name
RPC_C_AUTHN_LEVEL_PKT_PRIVACY, // RPC_C_AUTHN_LEVEL_xxx
RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
userAcct, // client identity
EOAC_NONE // proxy capabilities
);
}
// HARDDISK BİLGİLERİLERİNİ ALIYORUZ
IEnumWbemClassObject* pEnumerator = NULL;
// Get the data from the WQL sentence
IWbemClassObject *pclsObj = NULL;
ULONG uReturn = 0;
String Sorgu = "SELECT * FROM Win32_Process Where Name='"+Program_Ad+"' ";
//Zamanlanmış Görev Listesi
hres = pSvc->ExecQuery( L"WQL", Sorgu.w_str(),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);
//IWbemClassObject *pclsObj = NULL;
//ULONG uReturn = 0;
//String strHarddiskTipi="";
while (pEnumerator)
{
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
if(0 == uReturn || FAILED(hr))
break;
VARIANT vtProp;
hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);// String
if (!FAILED(hr))
{
if ( vtProp.vt!=VT_NULL && vtProp.vt!=VT_EMPTY && vtProp.vt != VT_ARRAY )
strGeriDonus = vtProp.bstrVal ;
}
VariantClear(&vtProp);
pclsObj->Release();
pclsObj=NULL;
}
pSvc->Release();
pLoc->Release();
pEnumerator->Release();
if (pclsObj!=NULL)
pclsObj->Release();
return strGeriDonus;
//-------------------------------------------------------------------------------------
}
Yorumları: 235
Konuları: 28
Kayıt Tarihi: 05-05-2017
Aktif Kullandığınız Delphi Sürümü:
Rep Puanı: 1.177 Programcı
function TSend_Service.DoFindTask(exeFileName: string): Boolean;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
Result := False;
while Integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =
UpperCase(ExeFileName))) then
begin
Result := True;
end;
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;
function WTSQueryUserToken(SessionId: ULONG; var phToken: THandle): BOOL; stdcall; external 'Wtsapi32.dll';
procedure TSend_Service.RunApp(dosya :string);
var
SessionID: DWORD;
UserToken: THandle;
CmdLine: PChar;
si: _STARTUPINFOW;
pi: _PROCESS_INFORMATION;
begin
SessionId := WtsGetActiveConsoleSessionID;
if SessionID = $FFFFFFFF then Exit;
if WTSQueryUserToken(SessionID, UserToken) then
begin
CmdLine := PWideChar(ExtractFileDir(ParamStr(0))+ '\' + dosya);
//UniqueString(CmdLine);
ZeroMemory(@si, SizeOf(si));
si.cb := SizeOf(si);
SI.lpDesktop := PChar('winsta0\Default');
SI.dwFlags := STARTF_USESHOWWINDOW;
SI.wShowWindow := SW_SHOWNORMAL;
ZeroMemory(@pi, SizeOf(pi));
try
CreateProcessAsUser(UserToken, nil, PChar(CmdLine), nil, nil, False,
0, nil, nil, si, pi);
except on E: Exception do
// Log exception ...
end;
CloseHandle(UserToken);
end
else
begin
// Log GetLastError ...
end;
end;
RunApp('Belge_Basim.exe ' + refno + ' ' + belgetipi);
|