92

我正在尝试将进程作为另一个帐户运行。我有命令:

runas "/user:WIN-CLR8YU96CL5\network service" "abwsx1.exe"

但是这会要求输入密码。但是没有为网络服务设置密码。

我正在尝试做的事情可能吗?

4

5 回答 5

140

使用SysInternals中的 PsExec.exe,从提升的命令提示符运行。

例如,这将打开一个作为 NETWORK SERVICE 运行的新命令提示符:

psexec -i -u "nt authority\network service" cmd.exe 

这将作为本地系统运行它:

psexec -i -s cmd.exe 

whoami您可以通过从 cmd 提示符运行来验证这些。

也可以看看:

于 2013-07-31T14:52:36.050 回答
17

在任务计划程序中,创建一个任务以在 NETWORK SERVICE 用户下运行应用程序。然后,您可以使用从命令行运行任务

schtasks /run /TN "任务名"

其中taskname是您的任务的名称。

于 2012-01-06T20:29:40.313 回答
6

您通常只能从 Windows 服务冒充为服务帐户,就像这篇文章提到的那样:

诀窍是将您的代码作为本地系统运行,然后您可以从那里使用适当的用户名来模拟服务帐户,而无需密码。以本地系统帐户运行代码的一种方法是使用下面显示的技术(取自此原始帖子)创建命令行 shell,并从那里执行您的程序集。调用System.Diagnostics.Debugger.Break()您的代码允许您进行调试。

要创建在本地系统帐户下运行的命令行 shell,请打开一个新的命令行窗口并输入:

c:\sc create testsvc binpath= "cmd /K start" type= own type= interact

其次是:

c:\sc start testsvc

应该打开一个新的命令窗口。在该窗口中运行您的 application.exe - 您将看到您现在以内置系统用户帐户的身份运行。完成测试后,您可以通过输入以下命令删除您创建的测试服务:

c:\sc delete testsvc

如果您尝试在自己的用户上下文中执行此操作,那么此类尝试应该会失败。

于 2011-08-02T12:12:34.593 回答
5

我已经测试过了

PsExec -i -s cmd.exe

PsExec -i -u "nt authority\network service" cmd.exe

在 PsExec64-v2.2 上,对于 win10-home-x64-10.0.14393 和 win10-pro-x64-10.0.15063 使用普通控制台失败,使用提升控制台它工作正常

于 2017-07-29T01:04:47.000 回答
1

I know this is an old thread but it is the top result for this problem and I wanted to be able to run a command using PowerShell without having to install any additional tools on our Windows Server. I came up with the following PowerShell script that creates a scheduled task, runs it, and then deletes it. It is also written to allow you to run the command under different user accounts.

function InstallDotNetCoreGlobalTool($PackageId, $Action = "install", $User = "NT AUTHORITY\NETWORK SERVICE", $Password = "")
{
    $TaskName = "AzureDotNetCoreGlobalToolConfiguration"
    $Command = "dotnet.exe"
    $Arguments = "tool $Action -g " + $PackageId
    $TaskAction = New-ScheduledTaskAction -Execute $Command -Argument $Arguments

    Write-Host "Setting up scheduled task to run" $Command $Arguments

    Register-ScheduledTask -TaskName $TaskName -User $User -Action $TaskAction
    Start-ScheduledTask -TaskName $TaskName

    Write-Host ""
    Write-Host "Waiting on scheduled task to complete."

    while ((Get-ScheduledTask -TaskName $TaskName).State  -ne 'Ready') 
    {
      # keep waiting
    }

    Write-Host ""

    If((Get-ScheduledTask $TaskName | Get-ScheduledTaskInfo).LastTaskResult -eq 0)
    {
        Write-Host $PackageId $Action "completed successfully"
    }
    else
    {
        If ($Action -eq "install")
        {
            Write-Host $PackageId "failed to $Action. Ensure the proper dependencies have been installed or that it isn't already installed."
        }
        Else {
            Write-Host $PackageId "failed to $Action. It may not currently be installed."
        }        
    }

    Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false
}

InstallDotNetCoreGlobalTool "Amazon.Lambda.Tools" "uninstall"
于 2019-07-28T21:48:21.543 回答