|
-
July 10th, 2004, 04:42 AM
#1
Regarding Project Type
Hi,
Suppose i have one VC++ 6.0 Project .It may be Service or dll or exe or Control etc....
How to know weather it is service or dll............
Manually we have see or any kind of settings are there...
i.e Suppose if it is SDI..there will be SDIdoc Template like...
Other than this type any kind of settings are there..
If so please help me..
With Regards..
-
July 12th, 2004, 03:35 PM
#2
Hi voonnalk,
These IsService() is something I use to _try_ and determine if I am a service. Its a Yes biased deterministic algorithm - it always returns an answer, and when it returns Yes, it is always correct (since SECURITY_NT_AUTHORITY is a service). It could be the case that it is being run as a service under a different account. In that case, the algorithm will incorrectly return No.
Jeff
Code:
INT IsService() {
INT nResult = RUNNING_UNKNOWN;
SID_IDENTIFIER_AUTHORITY siaAuthority = SECURITY_NT_AUTHORITY;
PSID psidLocalSystem = NULL;
TCHAR* pTextualName = NULL;
BOOL bResult = FALSE;
HANDLE hToken = NULL;
TOKEN_USER* ptUser = NULL;
__try {
bResult = AllocateAndInitializeSid( &siaAuthority, 1, SECURITY_LOCAL_SYSTEM_RID,
0, 0, 0, 0, 0, 0, 0, &psidLocalSystem );
if( FALSE == bResult ) { __leave; }
if( FALSE == IsValidSid( psidLocalSystem ) ) { __leave; }
bResult = OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY | TOKEN_QUERY_SOURCE, &hToken );
if( FALSE == bResult ) { __leave; }
ptUser = (TOKEN_USER*)AllocateTokenInformation( hToken, TokenUser );
if( FALSE == bResult ) { __leave; }
if( TRUE == EqualSid( psidLocalSystem, ptUser->User.Sid ) ) {
nResult = RUNNING_AS_SERVICE;
g_bService = TRUE;
} else {
nResult = RUNNING_AS_USER;
g_bService = FALSE;
}
GetTextualSid( ptUser->User.Sid, &pTextualName );
LogEvent( _T( "Token SID ") );
LogEvent( pTextualName );
}
__finally { }
if( NULL != psidLocalSystem ) {
FreeSid( psidLocalSystem );
}
if( NULL != pTextualName ) {
HeapFree( GetProcessHeap(), 0, pTextualName );
}
if( NULL != hToken ) {
CloseHandle( hToken );
}
if( NULL != ptUser ) {
HeapFree( GetProcessHeap(), 0, ptUser );
}
return nResult;
}
BOOL GetTextualSid( PSID pSid, LPTSTR* pTextualSid ) {
PSID_IDENTIFIER_AUTHORITY psia;
DWORD dwSubAuthorities;
DWORD dwSidRev=SID_REVISION;
DWORD dwCounter;
DWORD dwSidSize;
// Validate the binary SID.
if(!IsValidSid( pSid) ) { return FALSE; }
// Get the identifier authority value from the SID.
psia = GetSidIdentifierAuthority(pSid);
// Get the number of subauthorities in the SID.
dwSubAuthorities = *GetSidSubAuthorityCount(pSid);
// Compute the buffer length.
// S-SID_REVISION- + IdentifierAuthority- + subauthorities- + NULL
dwSidSize=(15 + 12 + (12 * dwSubAuthorities) + 1) * sizeof(TCHAR);
// Allocate a buffer
*pTextualSid = (TCHAR*)HeapAlloc( GetProcessHeap(), 0, dwSidSize );
if( NULL == *pTextualSid ) { return FALSE; }
// Add 'S' prefix and revision number to the string.
dwSidSize=wsprintf( *pTextualSid, TEXT("S-%lu-"), dwSidRev );
// Add SID identifier authority to the string.
if ( (psia->Value[0] != 0) || (psia->Value[1] != 0) ) {
dwSidSize+=wsprintf( *pTextualSid + lstrlen( *pTextualSid ),
TEXT("0x%02hx%02hx%02hx%02hx%02hx%02hx"),
(USHORT)psia->Value[0],
(USHORT)psia->Value[1],
(USHORT)psia->Value[2],
(USHORT)psia->Value[3],
(USHORT)psia->Value[4],
(USHORT)psia->Value[5]);
} else {
dwSidSize+=wsprintf( *pTextualSid + lstrlen( *pTextualSid ), TEXT("%lu"),
(ULONG)(psia->Value[5] ) +
(ULONG)(psia->Value[4] << 8) +
(ULONG)(psia->Value[3] << 16) +
(ULONG)(psia->Value[2] << 24) );
}
// Add SID subauthorities to the string.
for (dwCounter=0 ; dwCounter < dwSubAuthorities ; dwCounter++) {
dwSidSize+=wsprintf( *pTextualSid + dwSidSize, TEXT("-%lu"),
*GetSidSubAuthority(pSid, dwCounter) );
}
return TRUE;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|