ProcessStartInfo冒充其他用户无法正常工作 [英] ProcessStartInfo impersonate other user not working

查看:107
本文介绍了ProcessStartInfo冒充其他用户无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在这个问题上看到了很多问题和答案,但是,我似乎无法找到适合我情况的正确答案。只要我没有设置processStartInfo对象的用户名,密码和域,我就有完美的代码。



Hi all,

I have seen many questions and answers on this subject, however, I can't seem to find the right answer for my situation. I have code that works perfectly as long as I don't set the username, password and domain of the processStartInfo object.

Dim p As New ProcessStartInfo()
            With p
                Dim exec As String = "C:\Program Files\MyFiles\PsExec.exe"
                If File.Exists(exec) Then
                    p.FileName = exec
                    p.Arguments = "\\" & env & " -u username -p password -d icpcl -source """ & source & """ -script " & script
                    p.WindowStyle = ProcessWindowStyle.Hidden
                    p.UseShellExecute = False
                    p.RedirectStandardOutput = True
                    p.RedirectStandardError = True
                    'p.UserName = "myUser"
                    'p.Password = ConvertToSecureString("myPassword")
                    'p.Domain = "myDomain"

                    Dim x As Process = Process.Start(p)
                    Dim output As String = x.StandardOutput.ReadToEnd()
                    Dim err As String = x.StandardError.ReadToEnd()
                    WriteLog("output: " & output)
                    WriteLog("err: " & err)
                    x.WaitForExit()
                End If
            End With





如果我取消注释UserName,密码和域名行,我收到以下错误:



目录名无效



如果我改变了





If I uncomment the UserName, Password and Domain lines, I get the following error:

"The directory name is invalid"

If I change

p.FileName = exec





to





to

p.WorkingDirectory = "C:\Program Files\MyFiles\"
p.FileName = "PsExec.exe"





然后我得到一个不同的错误:



系统找不到指定的路径



如果我不使用UserName,密码和域,两种方式都可以正常工作。



我不明白我在这里缺少什么。非常感谢任何帮助。



提前谢谢你,

t shaffer



Then I get a different error:

"The system cannot find the path specified"

Both ways work just fine if I don't use the UserName, Password and Domain.

I don't understand what I'm missing here. Any help is greatly appreciated.

Thank you in advance,
t shaffer

推荐答案

也许Impersonization是错误的词,我需要在本地PC上运行一个程序,该程序作为与登录用户不同的用户运行。根据我的理解,当使用ProcessStartInfo时,设置UserName,Password和Domain将完成此任务。

我简化了我的代码,只需运行notepad.exe。我将notepad.exe复制到MyFiles目录。

请记住,我将UserName,Password和Domain设置为我自己的凭据。我仍然得到相同的结果:

Maybe Impersonization is the wrong word, I need to run a process on the local PC that the program runs on as a different user than the user that is logged on. From what I understand, when using ProcessStartInfo, setting the UserName, Password and Domain will accomplish this task.
I simplified my code to simply run notepad.exe. I copied notepad.exe into "MyFiles" directory.
Remember, I'm setting the UserName, Password and Domain to my own credentials. I still get the same results:
Dim p As New ProcessStartInfo()
            With p
                Dim exec As String = "C:\Program Files\MyFiles\notepad.exe"
                If File.Exists(exec) Then
                    p.FileName = exec
                    p.WindowStyle = ProcessWindowStyle.Hidden
                    p.UseShellExecute = False
                    p.RedirectStandardOutput = True
                    p.RedirectStandardError = True
                    'p.UserName = "myUser"
                    'p.Password = ConvertToSecureString("myPassword")
                    'p.Domain = "myDomain"

                    Dim x As Process = Process.Start(p)
                    Dim output As String = x.StandardOutput.ReadToEnd()
                    Dim err As String = x.StandardError.ReadToEnd()
                    WriteLog("output: " & output)
                    WriteLog("err: " & err)
                    x.WaitForExit()
                End If
            End With





在我看来,这有与我想要运行的流程无关。



谢谢,

tshaffer



In my opinion, this has nothing to do with what process I am trying to run.

Thank you,
tshaffer


这篇关于ProcessStartInfo冒充其他用户无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆