用户的服务器上有套软件是2000年左右用delphi5开发的,里面用到了DCom技术,然后部署在windows2000server上,现在用户要求把系统迁移到windows2003server上,可是在windows2003server上dcom的配置和2000server的配置区别很大,按照以前的配置说明,配不起来,心情比较急躁请路过的大侠给你建议。

解决方案 »

  1.   

    kan xia  shi zm hui shi !!
      

  2.   

    unit USecMConn;interfaceuses
      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;
    implementationprocedure 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.
      

  3.   

    生成TSecDCOMConnection的对象,然后对username和passsword赋值,最后连接