powershell - 这可以在远程计算机上工作吗?

标签 powershell powershell-2.0

我一直在努力让这个在远程计算机上运行,​​这有可能吗?如果是这样,有人可以指出我正确的方向吗?

代码如下:

    Function Lock-WorkStation { 
        #Requires -Version 2.0 
        $signature = @" 
            [DllImport("user32.dll", SetLastError = true)] 
            public static extern bool LockWorkStation(); 
        "@ 

        $LockWorkStation = Add-Type -memberDefinition $signature -name "Win32LockWorkStation" -namespace Win32Functions -passthru 
        $LockWorkStation::LockWorkStation() | Out-Null 
    }

最佳答案

我不能在这里测试,但对我来说它不能工作,因为正如您在 Microsoft documentation 中看到的那样, LockWorkStation 函数只能由交互式桌面上运行的进程调用。此外,用户必须登录。

因此,据我所知,当您使用 PSSession 连接到远程计算机时,您不在交互式 session 中。

关于powershell - 这可以在远程计算机上工作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6040463/

相关文章:

powershell - 如何添加多线程?

powershell - 显示远程运行的Powershell脚本的实时输出

windows - 在 powershell 2 中仅返回带有 Get-childitem 的文件

powershell - Powershell v2 Get-Eventlog:尝试执行未经授权的操作

powershell - 使用Powershell获取HDD序列号

Powershell 通过排除移动文件夹

azure - 删除 X 天前的 Azure 快照

powershell - 获取远程注册表值

PowerShell - 过滤唯一值

powershell - 如何在powershell中修剪文件中的所有行