BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

NT Service / DCOM server failing on Windows 2003

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API)
View previous topic :: View next topic  
Author Message
Mike Collins
Guest





PostPosted: Wed Feb 22, 2006 5:03 pm    Post subject: NT Service / DCOM server failing on Windows 2003 Reply with quote



Hi all, got a really annoying problem that we are struggling to solve.
Sorry if this is not the correct group be since it involves NT Services and
ACL rights I thought I might be able to push it.

I posted a few weeks ago about creating a DCOM server interface as an NT
Service so that it could effectively run all the time, regardless of if any
users were logged on to Windows. Remy directed me to a MSDN article
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncomg/html/localserv.asp
which described the necessary registry changes that needed to be made in
order to get the service to work correctly.

Having followed this, we have created out DCOM / NTService which works
perfectly fine under Windows 2000.When we tested it on Windows XP service
pack two we had to make some amendments to the permissions in order to get
it to function properly (I notice a post on the cppbuilder.activex (R.E.
DCOM events WindowsXP SP2) which had a link to
http://www.ct2k.com/cns2006/CT2K-XPDCOM.ppt). Under XP SP2 the NT Service
ran ok but we couldn't connect to it with our client application. We
basically resolved it by adding the current user account into all the
permissions for DCOM on that machine AND for the particular DCOM server.

Now we are trying to get it to work under Windows 2003 Enterprise with no
sucess. We've tried all the combinations that we can think of, of adding in
users to the permissions with no success. It's is defiantly a security
permissions problem. The Service starts ok and runs fine but the client
cannot connect to it. One of our Russian Developers found this article
http://www.rsdn.ru/article/com/comsec.xml#ERBA which (although it is in
Russian) we've followed but still with not success. The code has been
tested with and without the following

HRESULT hr = CoInitializeSecurity(sd, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_PKT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);

to no avail - hr never equals S_OK. The article seems to suggest that if a
users is a member of a group that does not have permissions to run DCOM,
then even if the user is directly added to the permissions for that object,
they still will not be able to execute the DCOM object. It also seems to
suggest that if a user is a member of two groups, A & B, if A is allowed to
run DCOM and B is not, then overall the user will NOT be able to run the
DCOM object <- is this correct?

I anyone shed some light on this, it's a real problem for use

Many thanks in advance,

Mike Collins
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Feb 23, 2006 12:03 am    Post subject: Re: NT Service / DCOM server failing on Windows 2003 Reply with quote



"Mike Collins" <its (AT) TheBottomOfThePost (DOT) com> wrote in message
news:43fc85d2$1 (AT) newsgroups (DOT) borland.com...

Quote:
Hi all, got a really annoying problem that we are struggling to solve.

Win2003 changes the requirements of DCOM servers in services, and the VCL
prior to BDS 2006 could not natively handle it. The workaround is to edit
the project's WinMain() function to not call Application->Initialize() under
Win2003, and then call Application->Initialize() after the service is being
started. For example:

--- Project.cpp ---

#include <ComObj.hpp>
external bool bIsAppInitialized;

bool __fastcall IsRunningInInstallMode()
{
static TSysCharSet switches = TSysCharSet() << '-' << '/';

return FindCmdLineSwitch("REGSERVER", switches, true) ||
FindCmdLineSwitch("UNREGSERVER", switches, true) ||
FindCmdLineSwitch("INSTALL", switches, true) ||
FindCmdLineSwitch("UNINSTALL", switches, true);
}

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
Comobj::CoInitFlags = COINIT_MULTITHREADED;

CoInitializeEx(NULL, COINIT_MULTITHREADED);
CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_NONE,
RPC_C_IMP_LEVEL_ANONYMOUS, NULL, EOAC_NONE, NULL);

try
{
// To support Windows Server 2003 we need to make sure
// that StartServiceCtrlDispatcher() is called before
// CoRegisterClassObject(). Unfortunately, the VCL does
// not do this. Application->Initialize() below calls
// CoRegisterClassObject() first, which will then cause
// the COM server to fail to initialize properly under
// Windows Server 2003. Earlier versions of Windows do
// not suffer from this issue...

// Win Server 2003 = v5.2
if( !((Win32MajorVersion == 5) && (Win32MinorVersion >= 2)) ||
IsRunningInInstallMode() )
{
Application->Initialize();
bIsAppInitialized = true;
}

//...
}
catch (Exception &exception)
{
Sysutils::ShowException(&exception, Sysutils::ExceptAddr());
}

CoUninitialize();
return 0;
}

--- Service.cpp ---

bool bIsAppInitialized = false;

void __fastcall TVPIEventCenterService::ServiceStart(TService *Sender,
bool &Started)
{
ErrCode = 0;
Win32ErrCode = 0;

// To support Windows Server 2003 we need to make sure
// that StartServiceCtrlDispatcher() is called before
// CoRegisterClassObject(). Unfortunately, the VCL does
// not do this. Application->Initialize() calls
// CoRegisterClassObject() first, which will then cause
// the COM server to fail to initialize properly under
// Windows Server 2003. Application->Initialize() is
// delayed until below so that StartServiceCtrlDispatcher()
// can be called first. Earlier versions of Windows do
// not suffer from this issue...

if( !bIsAppInitialized )
{
Svcmgr::Application->Initialize();
bIsAppInitialized = true;
}

//...
}


As for BDS 2006, Borland tried to address the issue with a new property in
TApplication, but it did not work properly in the first release. I do not
know if Update 1 fixed it or not.


Gambit
Back to top
Mike Collins
Guest





PostPosted: Thu Feb 23, 2006 12:03 pm    Post subject: Re: NT Service / DCOM server failing on Windows 2003 Reply with quote



Thank you Remy, I have not had a chance to test this yet but I will post the
result as soon as I know. This is the sort of information that you would
just never come across with out the newsgroups. This looks like it is
exactly the problem. Out of interest, how did you discover this? I'm
intreged how you find this information or whether you can across it
yourself. I'm only asking because I want to try and resolve these problems
myself when I run up against a brick wall.

What are the backward compatibility issues with this code relating to win
2000 and win XP

Thanks again

Mike Collins



"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote in message
news:43fcf481$1 (AT) newsgroups (DOT) borland.com...
Quote:

"Mike Collins" <its (AT) TheBottomOfThePost (DOT) com> wrote in message
news:43fc85d2$1 (AT) newsgroups (DOT) borland.com...

Hi all, got a really annoying problem that we are struggling to solve.

Win2003 changes the requirements of DCOM servers in services, and the VCL
prior to BDS 2006 could not natively handle it. The workaround is to edit
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Feb 23, 2006 8:03 pm    Post subject: Re: NT Service / DCOM server failing on Windows 2003 Reply with quote

"Mike Collins" <its (AT) TheBottomOfThePost (DOT) com> wrote in message
news:43fd9660 (AT) newsgroups (DOT) borland.com...

Quote:
Out of interest, how did you discover this?

A newsgroup search. I had a problem with my COM server failing when I first
migrated it to Win2003. It took several days to track it down. Of course,
now that I know the problem, it takes only a minute or two to find the
information online now. Many people have reported the same issue and
similar workarounds.

Quote:
What are the backward compatibility issues with this code relating
to win 2000 and win XP

The code I gave you is a copy/paste from my own project, which works fine on
all NT-based systems. As you can see, the WinMain() function looks at the
OS version and then applies the workaround to only Win2003 and later
versions. Under earlier versions, the runtime behavior is exactly the same
as it used to be.


Gambit
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.