我如何“运行”? “网络服务”?

发布于 2024-11-27 14:43:02 字数 166 浏览 2 评论 0原文

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

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

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

我想做的事情可能吗?

I am trying to run a process as another account. I have the command:

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

but then this asks for the password. However there is no password set for the network service.

Is what I am trying to do possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

最冷一天 2024-12-04 14:43:02

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

例如,这将打开一个作为网络服务运行的新命令提示符:

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

这将作为本地系统运行:

psexec -i -s cmd.exe 

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

另请参阅:

Use PsExec.exe from SysInternals, running from an elevated command prompt.

e.g. this will open a new command prompt running as NETWORK SERVICE:

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

this will run it as LOCAL SYSTEM:

psexec -i -s cmd.exe 

You can verify these by running whoami from the cmd prompt.

See also:

青巷忧颜 2024-12-04 14:43:02

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

schtasks /run /TN "taskname"

,其中 taskname 是任务的名称。

In Task Scheduler, create a task to run the application under the NETWORK SERVICE user.
You can then run the task from the command line using

schtasks /run /TN "taskname"

Where taskname is the name of your task.

寻梦旅人 2024-12-04 14:43:02

通常,您只能模拟 Windows 服务中的服务帐户,例如 这篇文章提到:

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

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

c:\sc createtestsvc binpath=“cmd /K start”type=own type=interact

后跟:

c:\sc 启动testsvc

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

c:\sc 删除testsvc

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

You can only impersonate as service account from a Windows service typically, like this post mentions:

The trick is to run your code as Local System and from there you can impersonate the service accounts by using the appropriate username with no password. One way to run your code as the Local System account is to create a command line shell by using the technique shown below (taken from this orginal post), and execute your assembly from there. Calling System.Diagnostics.Debugger.Break() in your code allows you to debug.

To create a command-line shell that runs under the local system account, open a new command line window and enter:

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

followed by:

c:\sc start testsvc

A new command window should have opened up. In that window run your application.exe - you'll see that you're now running as the built-in System user account. After you've finished testing, you can delete the test service you created by entering:

c:\sc delete testsvc

If you try to do that in your own user context, then such attempts should fail.

情话难免假 2024-12-04 14:43:02

我已经在 PsExec64-v2.2 上进行了测试

PsExec -i -s cmd.exe

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

对于 win10-home-x64-10.0.14393 和 win10-pro-x64-10.0.15063 使用普通控制台失败了,使用提升的控制台工作正常

I have tested

PsExec -i -s cmd.exe

and

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

on PsExec64-v2.2, for win10-home-x64-10.0.14393 and win10-pro-x64-10.0.15063 to use normal console it's failed, use elevated console it works fine

我家小可爱 2024-12-04 14:43:02

我知道这是一个旧线程,但它是此问题的首要结果,我希望能够使用 PowerShell 运行命令,而无需在我们的 Windows Server 上安装任何其他工具。我想出了以下 PowerShell 脚本,该脚本创建计划任务、运行它,然后删除它。它还允许您在不同的用户帐户下运行该命令。

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"

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"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文