请教windows2003server上dcom的配置

handsome‘sboy 2009-06-30 12:16:53
加精
用户的服务器上有套软件是2000年左右用delphi5开发的,里面用到了DCom技术,然后部署在windows2000server上,现在用户要求把系统迁移到windows2003server上,可是在windows2003server上dcom的配置和2000server的配置区别很大,按照以前的配置说明,配不起来,心情比较急躁。。。请路过的大侠给你建议。。。。
...全文
471 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
shuihan20e 2009-07-01
  • 打赏
  • 举报
回复
运行->dcomcnfg
sxtaosdo 2009-07-01
  • 打赏
  • 举报
回复
http://www.130132.cn/0_7_263289.aspx
ifive 2009-06-30
  • 打赏
  • 举报
回复
很好很强大
MaTaijin 2009-06-30
  • 打赏
  • 举报
回复
生成TSecDCOMConnection的对象,然后对username和passsword赋值,最后连接
MaTaijin 2009-06-30
  • 打赏
  • 举报
回复
unit USecMConn;

interface

uses
MConnect, Classes, Activex, Windows, Sysutils, ComConst, ComObj;

const
RPC_C_AUTHN_NONE = 0;
RPC_C_AUTHN_DCE_PRIVATE = 1;
RPC_C_AUTHN_DCE_PUBLIC = 2;
RPC_C_AUTHN_DEC_PUBLIC = 4;
RPC_C_AUTHN_WINNT = 10;
RPC_C_AUTHN_DPA = 16;
RPC_C_AUTHN_MSN = 17;
RPC_C_AUTHN_GSS_KERBEROS = 18;
RPC_C_AUTHN_MQ = 100;
RPC_C_AUTHN_DEFAULT = $FFFFFFFF;

RPC_C_AUTHN_LEVEL_DEFAULT = 0;
RPC_C_AUTHN_LEVEL_NONE = 1;
RPC_C_AUTHN_LEVEL_CONNECT = 2;
RPC_C_AUTHN_LEVEL_CALL = 3;
RPC_C_AUTHN_LEVEL_PKT = 4;
RPC_C_AUTHN_LEVEL_PKT_INTEGRITY= 5;
RPC_C_AUTHN_LEVEL_PKT_PRIVACY = 6;

RPC_C_IMP_LEVEL_ANONYMOUS = 1;
RPC_C_IMP_LEVEL_IDENTIFY = 2;
RPC_C_IMP_LEVEL_IMPERSONATE = 3;
RPC_C_IMP_LEVEL_DELEGATE = 4;

SEC_WINNT_AUTH_IDENTITY_ANSI = $1;
SEC_WINNT_AUTH_IDENTITY_UNICODE = $2;

EOAC_NONE = 0;
type
PCoAuthIdentity = ^TCoAuthIdentity;
_COAUTHIDENTITY = record
User : LPWSTR;
UserLength : DWORD;
Domain : LPWSTR;
DomainLength : DWORD;
Password : LPWSTR;
PasswordLength : DWORD;
Flags : DWORD;
end;
TCoAuthIdentity = _COAUTHIDENTITY;

PCoAuthInfo = ^TCoAuthInfo;
_COAUTHINFO = record
dwAuthnSvc : DWORD;
dwAuthzSvc : DWORD;
pwszServerPrincName : LPWSTR;
dwAuthnLevel : DWORD;
dwImpersonationLevel : DWORD;
pAuthIdentityData : PCoAuthIdentity;
dwCapabilities : DWORD;
end;
TCoAuthInfo = _COAUTHINFO;

TSecDCOMConnection = class(TDCOMConnection)
private
FUserName: string;
FPassword : String;
protected
procedure DoConnect; override;
public
constructor Create(AOwner: TComponent); override;
published
property ComputerName;
property ObjectBroker;
property Username : String read FUserName write FUserName;
property Password : String read FPassword write FPassword;
end;


implementation

procedure SetProxyBlanket(itf: IUnknown; const AuthInfo: TCoAuthInfo);
var
Qr : HResult;
begin
with AuthInfo do
Qr := CoSetProxyBlanket(Itf, dwAuthnSvc, dwAuthzSvc, pWideChar(pAuthIdentityData^.Domain),
dwAuthnLevel, dwImpersonationLevel, pAuthIdentityData, dwCapabilities);
OleCheck(Qr);
end;

function CreateRemoteSecComObject(const MachineName, UserName, Password: WIDEString;
const ClassID: TGUID): IDispatch;
const
LocalFlags = CLSCTX_LOCAL_SERVER or CLSCTX_REMOTE_SERVER or CLSCTX_INPROC_SERVER;
RemoteFlags = CLSCTX_REMOTE_SERVER;
var
MQI: TMultiQI;
ServerInfo: TCoServerInfo;
AuthInfo: TCoAuthInfo;
AuthIdent : TCoAuthIdentity;
IID_IUnknown: TGuid;
Flags, Size: DWORD;
LocalMachine: array [0..MAX_COMPUTERNAME_LENGTH] of char;
iiu:IDispatch;
qr:HRESULT;
begin
if @CoCreateInstanceEx = nil then
raise Exception.CreateRes(@SDCOMNotInstalled);
FillChar(ServerInfo, sizeof(ServerInfo), 0);
ServerInfo.pwszName := PWideChar(MachineName);
ServerInfo.pAuthInfo := @AuthInfo;
ServerInfo.dwReserved1 := 0;
ServerInfo.dwReserved2 := 0;

FillChar(AuthInfo, sizeof(AuthInfo), 0);
AuthInfo.dwAuthnSvc := RPC_C_AUTHN_WINNT;
AuthInfo.dwAuthzSvc := RPC_C_AUTHN_NONE;
AuthInfo.pwszServerPrincName := nil;
AuthInfo.dwAuthnLevel := RPC_C_AUTHN_LEVEL_DEFAULT;
AuthInfo.dwImpersonationLevel := RPC_C_IMP_LEVEL_IMPERSONATE;
AuthInfo.pAuthIdentityData := @AuthIdent;
AuthInfo.dwCapabilities := EOAC_NONE;

FillChar(AuthIdent, sizeof(AuthIdent), 0);
AuthIdent.User := PWideChar(UserName);
AuthIdent.UserLength := Length(UserName);
AuthIdent.Domain := PWideChar(MachineName);
AuthIdent.DomainLength := Length(MachineName);
AuthIdent.Password := PWideChar(Password);
AuthIdent.PasswordLength := Length(Password);
AuthIdent.Flags := SEC_WINNT_AUTH_IDENTITY_UNICODE;

IID_IUnknown := IUnknown;
MQI.IID := @IID_IUnknown;
MQI.itf := nil;
MQI.hr := 0;
{ If a MachineName is specified check to see if it the local machine.
If it isn't, do not allow LocalServers to be used. }
if Length(MachineName) > 0 then
begin
Size := Sizeof(LocalMachine); // Win95 is hypersensitive to size
if GetComputerName(LocalMachine, Size) and
(AnsiCompareText(LocalMachine, MachineName) = 0) then
Flags := LocalFlags else
Flags := RemoteFlags;
end else
Flags := LocalFlags;

OleCheck(CoCreateInstanceEx(ClassID, nil, Flags, @ServerInfo, 1, @MQI));
OleCheck(MQI.HR);

SetProxyBlanket(mqi.Itf, AuthInfo);
qr:=mqi.Itf.QueryInterface(idispatch, iiu);
OleCheck(qr);
SetProxyBlanket(IUnknown(iiu), AuthInfo);
Result := iiu;
end;


{ TSecDCOMConnection }

constructor TSecDCOMConnection.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;

procedure TSecDCOMConnection.DoConnect;
begin
if (ObjectBroker <> nil) then
begin
repeat
if ComputerName = '' then
ComputerName := ObjectBroker.GetComputerForGUID(GetServerCLSID);
try
SetAppServer(CreateRemoteComObject(ComputerName, GetServerCLSID) as IDispatch);
ObjectBroker.SetConnectStatus(ComputerName, True);
except
ObjectBroker.SetConnectStatus(ComputerName, False);
ComputerName := '';
end;
until Connected;
end else begin
if (ComputerName <> '') then begin
if UserName <> '' then begin
SetAppServer(CreateRemoteSecComObject(ComputerName, UserName, Password, GetServerCLSID));
end else begin
SetAppServer(CreateRemoteComObject(ComputerName, GetServerCLSID) as IDispatch);
end;
end else
inherited DoConnect;
end;
end;


end.
MaTaijin 2009-06-30
  • 打赏
  • 举报
回复
我在2000下能配通,但是在2003下面不行,最后修改代码完成
zyb6980972 2009-06-30
  • 打赏
  • 举报
回复
kan xia shi zm hui shi !!
jj2009dn 2009-06-30
  • 打赏
  • 举报
回复
http://www.130132.cn/0_7_263289.aspx
liangpei2008 2009-06-30
  • 打赏
  • 举报
回复
出的错误是什么?

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧