【问题标题】:StreamString(pipeClient) throws error Type is not definedStreamString(pipeClient) 抛出错误类型未定义
【发布时间】:2020-06-01 16:47:21
【问题描述】:

当计划的机器人试图在锁定的系统中运行进程时,我试图通过在 UiPath 中传递用户 ID 和密码来解锁机器

下面是我的代码

    'Create a new pipe client
    Using pipeClient As New System.IO.Pipes.NamedPipeClientStream(
        ".",
        "CredentialProviderPipe",
        PipeDirection.InOut,
        PipeOptions.None,
        System.Security.Principal.TokenImpersonationLevel.Impersonation)

        'Attempt to connect to it
        pipeClient.Connect(10000)
        'Send credentials
        Dim dom As String
         If Domain = "" Then
            dom = Environment.UserDomainName
        Else
            dom = Domain
        End If

        Dim ss As New StreamString(pipeClient)

        ss.WriteString(String.Format("LOGON{0}{1}{0}{2}{0}{3}", vbLf, dom, Username, Password))

        'Wait for reply
        Using pr As New StreamReader(pipeClient, System.Text.Encoding.Unicode)
            Response = pr.ReadLine()
            If Response = "OK" OrElse Response = "UNKNOWN" Then Return

            ErrorCode = pr.ReadLine()
            ErrorMessage = pr.ReadLine()
        End Using
    End Using
Catch ex As TimeoutException
    Response = "ERROR"
    ErrorCode = "0x80131505"
    ErrorMessage = ex.Message
Catch ex As Exception
    Response = "ERROR"
    ErrorCode = ""
    ErrorMessage = ex.Message
End Try

我遇到错误 BC30002: Type StringStream is not defined。

我不知道如何解决这个问题。请帮忙

【问题讨论】:

  • 您认为该类型应该来自哪里?您是否在不真正了解其功能的情况下从网络上复制代码?我搜索了那个类型,发现的信息很少。 This 看起来与您正在执行的操作相似,但未提供有关该类型的信息。基本上,与其他所有类型一样,您需要引用它声明的库并导入它所属的命名空间。如果您还不知道这些是什么,则由您自己决定。
  • 据我所知,StreamString 类型仅用于读写Stream。您已经在使用StreamReader 从Stream 中读取数据,所以我认为您可以使用StreamWriter 对其进行写入并完全取消StreamString 类。

标签: vb.net uipath


【解决方案1】:

看起来StreamString 的所有这些用法都基于示例here,其中包括该类的定义如下:

' Defines the data protocol for reading and writing strings on our stream
Public Class StreamString
    Private ioStream As Stream
    Private streamEncoding As UnicodeEncoding

    Public Sub New(ioStream As Stream)
        Me.ioStream = ioStream
        streamEncoding = New UnicodeEncoding(False, False)
    End Sub

    Public Function ReadString() As String
        Dim len As Integer = 0
        len = CType(ioStream.ReadByte(), Integer) * 256
        len += CType(ioStream.ReadByte(), Integer)
        Dim inBuffer As Array = Array.CreateInstance(GetType(Byte), len)
        ioStream.Read(inBuffer, 0, len)

        Return streamEncoding.GetString(inBuffer)
    End Function

    Public Function WriteString(outString As String) As Integer
        Dim outBuffer() As Byte = streamEncoding.GetBytes(outString)
        Dim len As Integer = outBuffer.Length
        If len > UInt16.MaxValue Then
            len = CType(UInt16.MaxValue, Integer)
        End If
        ioStream.WriteByte(CType(len \ 256, Byte))
        ioStream.WriteByte(CType(len And 255, Byte))
        ioStream.Write(outBuffer, 0, outBuffer.Length)
        ioStream.Flush()

        Return outBuffer.Length + 2
    End Function
End Class

【讨论】:

    猜你喜欢
    • 2012-04-14
    • 2019-06-06
    • 2020-02-11
    • 1970-01-01
    • 2014-05-30
    • 2014-07-09
    • 2018-11-15
    • 2020-02-03
    相关资源
    最近更新 更多