- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我对使用 Windows PowerShell 暂停或休眠计算机很感兴趣。你是如何做到这一点的?
我已经知道 Stop-Computer
和 Restart-Computer
cmdlet,它们是开箱即用的,但是这些没有实现我的功能之后。
最佳答案
您可以在 System.Windows.Forms.Application
类上使用 SetSuspendState
方法来实现此目的。 SetSuspendState
方法是一个静态方法。
一共有三个参数:
[System.Windows.Forms.PowerState]
[bool]
[bool]
要调用 SetSuspendState
方法:
# 1. Define the power state you wish to set, from the
# System.Windows.Forms.PowerState enumeration.
$PowerState = [System.Windows.Forms.PowerState]::Suspend;
# 2. Choose whether or not to force the power state
$Force = $false;
# 3. Choose whether or not to disable wake capabilities
$DisableWake = $false;
# Set the power state
[System.Windows.Forms.Application]::SetSuspendState($PowerState, $Force, $DisableWake);
把它放到一个更完整的函数中可能看起来像这样:
function Set-PowerState {
[CmdletBinding()]
param (
[System.Windows.Forms.PowerState] $PowerState = [System.Windows.Forms.PowerState]::Suspend
, [switch] $DisableWake
, [switch] $Force
)
begin {
Write-Verbose -Message 'Executing Begin block';
if (!$DisableWake) { $DisableWake = $false; };
if (!$Force) { $Force = $false; };
Write-Verbose -Message ('Force is: {0}' -f $Force);
Write-Verbose -Message ('DisableWake is: {0}' -f $DisableWake);
}
process {
Write-Verbose -Message 'Executing Process block';
try {
$Result = [System.Windows.Forms.Application]::SetSuspendState($PowerState, $Force, $DisableWake);
}
catch {
Write-Error -Exception $_;
}
}
end {
Write-Verbose -Message 'Executing End block';
}
}
# Call the function
Set-PowerState -PowerState Hibernate -DisableWake -Force;
注意:据我所知,在我的测试中,-DisableWake
选项没有产生任何可区分的差异。即使此参数设置为 $true
,我仍然能够使用键盘和鼠标唤醒计算机。
关于.net - 从 PowerShell 暂停或休眠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20713782/
这个问题在这里已经有了答案: What is the JavaScript version of sleep()? (91 个回答) 关闭 9 年前。 是的,我知道 - 这个问题有成千上万的答案。请
有没有办法使用 native NHibernate linq 提供程序执行以下查询? var result = (from e1 in Session.Query() join e2
上下文:我正在尝试将Grails项目从1.0.3升级到1.3.7,并且遇到了很多问题。我刚得到很多DuplicateMappingExceptions,因为该项目同时具有Hibernate XML文件
我有标准: ICriteria criteria = Session.CreateCriteria() .SetFetchMode("Entity1", FetchMo
我正在寻找一种重新启动线程的方法,无论是从该线程的上下文内部还是从线程外部,可能是从另一个进程中。 (这些选项中的任何一个都可以。)我知道使整个进程休眠的困难,而且我很确定线程也会遇到同样的困难。但是
C 中是否有任何函数可以检查计算机是否进入 sleep 、休眠 或锁定 并从这些状态唤醒? 在msdn它们为 C#、C++ 提供,但不为 C 提供。我的操作系统是windows7 如下是我用来检查启动
我对 NHibenate 有疑问。当我运行 queryover 时,出现错误“无法解析属性:User.Name of:MegaOnlineChat.Core.Entities.Message”。我做错
我知道这里被问过很多次,也回答过很多次,这不是应该如何完成的方式,但再一次:) 是否有可能以某种方式调用异步函数(例如计时器/ajax 调用),基本上是常见的异步任务并同步等待直到它结束而不会出现 1
我在persistence.xml中有以下内容 com.merc.model.log.EventLogging org.hibernate.ejb.HibernatePersiste
目前我的存储库有 2 个构造函数。当我从我的 mvc 网站调用这些时,我总是调用第一个构造函数,从而打开一个新 session 。我应该在 session 中通过吗?我该怎么做。 public
hibernate session to list conversion Compilation Error occured when java converted into scala..!!
下面的remove()方法导致“超出了GC开销限制”。从A或B或C中删除ABC中存在的关联时。请您告知错误在哪里吗? 注-ABC是A,B,C的映射表 stacktrace如下: Caused by:
昨天我在 webhosting.net 的 Jelastic v2.2.2 上获得了一个试用帐户,并配置了一个最少 0 个 cloudlets 的环境(最多 8 个,即全部动态,无保留)。然后我部署了
设置:Grails 2.5.6和Hibernate 4.3.10 我有一个带有字符串ID的表。事实是,它的值是数字字符串,当我传入诸如get()这样的值时,这似乎使"000000"变得混乱。 域类:
hibernate session to list conversion Compilation Error occured when java converted into scala..!!
我有一个用于 PDA 的应用程序,它有一个长时间运行的进程,我遇到了一个问题,即 PDA 将在该进程完成之前进入休眠状态。 我无法控制 PDA 上的电源设置,有谁知道我的应用程序阻止 PDA 进入休眠
我正在创建一个将安装在 LaunchAgents 文件夹中的守护程序。关于使其 sleep 的一些问题: 因为它是一个 LaunchAgent 项,所以可执行文件会在用户/系统 sleep 时自动 s
我想使用 AsyncTask 创建启动画面。具体来说,在 doInBackground() 方法中,我使用静态方法 Thread.sleep() 并在它创建一个将应用程序重定向到其他 Activity
在我的网站上,我有一个 JavaScript 函数,它执行 AJAX 调用来获取帐户信息,然后打开一个模式,您可以在其中查看和编辑信息。 AJAX 调用用于更改您选择的数据库中的详细信息,然后刷新原始
除非线程告诉我醒来,否则我想睡 X 时间。在下面的示例中,我想休眠 10 毫秒(1/100 秒)或直到 foo 有 2000 个项目。以先到者为准。我该怎么做呢?我编了函数 主线程: pthread_
我是一名优秀的程序员,十分优秀!