可以使其在远程计算机上工作吗?
我一直在试图让它在远程计算机上工作,这可能吗?如果是这样,有人可以指出我正确的方向吗?
这是代码:
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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
与此无关,但它可以在 Windows Vista/7 2008/R2 中提供帮助,您可以使用命令 tsdiscon.exe 锁定远程桌面会话或工作站。
这是一个示例,在我的计算机上以管理员域身份登录,我首先列出然后锁定服务器上的控制台会话。
Nothing to do with this, but it can help in Windows Vista/7 2008/R2, you can use the command
tsdiscon.exe
to lock a Remote Desktop session or your workstation.Here is a sample where, logged as adminstrator domain on my computer, I first list, then lock the console session on my server.
这是有可能的。但您需要一种解决方法来连接到交互式会话。
下载 PowerShellPack 并安装。您只需要一个名为“TaskScheduler”的模块。
我已经测试了以下代码:
您可以像这样使用它:
或像这样:
如果在指定凭据时在 Connect-ToTaskScheduler 中收到错误,那是因为模块中存在拼写错误(编辑 Connect-ToTaskScheduler.ps1 和将 "$NetworkCredentail.Domain," 替换为 "$NetworkCredential.Domain,"
It's possible. But you need a workaround to connect to the interactive session.
Download the PowerShellPack and install it. You only need one module called "TaskScheduler".
I've tested the following code:
You can use it like this:
or like this:
If you receive an error in Connect-ToTaskScheduler when specifying a credential, it's because there is a typo in the module (edit Connect-ToTaskScheduler.ps1 and replace "$NetworkCredentail.Domain," with "$NetworkCredential.Domain,"
我无法在这里进行测试,但对我来说它无法工作,因为正如您可以在 Microsoft 文档中,
LockWorkStation
函数只能由运行在交互式桌面上的进程调用。此外,用户必须登录。因此,据我所知,当您使用 PSSession 连接到远程计算机时,您并不处于交互式会话中。
I can't test here, but for me it can NOT work because, as you can read in Microsoft documentation, the
LockWorkStation
function is callable only by processes running on the interactive desktop. In addition, the user must be logged on.So when you connect to a remote computer using PSSession as far as I understand you are not in the interactive session.