Exemplo n.º 1
0
        protected override void Execute(CodeActivityContext context)
        {
            Int32 _timeout = TimeoutMS.Get(context);

            CallWithTimeout(new Action(() => {
                try
                {
                    string credName = CredentialName.Get(context);
                    IntPtr credPtr  = new IntPtr();
                    WReadCred(credName, CRED_TYPE.GENERIC, CRED_PERSIST.LOCAL_MACHINE, out credPtr);
                    if (credPtr.ToInt32() == 0)
                    {
                        SharedObject.Instance.Output(SharedObject.enOutputType.Error, "凭证不存在");
                        return;
                    }
                    Credential lRawCredential   = (Credential)Marshal.PtrToStructure(credPtr, typeof(Credential));
                    SecureString securePassWord = new SecureString();
                    foreach (char c in lRawCredential.CredentialBlob)
                    {
                        securePassWord.AppendChar(c);
                    }
                    UserName.Set(context, lRawCredential.UserName);
                    PassWord.Set(context, securePassWord);
                }
                catch (Exception e)
                {
                    SharedObject.Instance.Output(SharedObject.enOutputType.Error, "读取凭证执行过程出错", e.Message);
                }
            }), _timeout);
        }