当调度的机器人试图在锁定的系统中运行进程时,我试图通过在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:类型StringStream未定义。
我不知道如何解决该问题。请帮忙
答案 0 :(得分:0)
看来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