C#Windows 7块输入
我已经使用C#在Win7中创建了一个服务。在该服务中,我想使用BlockInput函数,在Win7中它似乎需要admin 我在代码中将serviceprocessorinstaller的、帐户、用户名和密码设置为管理员帐户,BlockInput不起作用。注意:在“服务属性/登录”选项卡下已正确设置 然后,我为我的服务添加了一个清单,并将requestedExecutionLevel设置为“requireAdministrator”。但是BlockInput仍然不想工作 我尝试将BlockInput向下移动到客户端级别,然后移动到客户端包装器,但它仍然不想工作 没有主意了…有什么建议吗 从这里开始编辑: 这是我的清单(或其中的一部分,抱歉格式太糟糕了)C#Windows 7块输入,c#,windows-7,service,C#,Windows 7,Service,我已经使用C#在Win7中创建了一个服务。在该服务中,我想使用BlockInput函数,在Win7中它似乎需要admin 我在代码中将serviceprocessorinstaller的、帐户、用户名和密码设置为管理员帐户,BlockInput不起作用。注意:在“服务属性/登录”选项卡下已正确设置 然后,我为我的服务添加了一个清单,并将requestedExecutionLevel设置为“requireAdministrator”。但是BlockInput仍然不想工作 我尝试将BlockInpu
我继续,并使用SetWindowsHookEx捕获WH_键盘和WH_鼠标事件 我想尽一切办法让BlockInput正常工作。我仍然认为我只是配置了错误的服务或其他什么,但我没有时间再担心它了
谢谢。你能展示一下你的代码吗?不是我现在的代码,因为它是用来工作的。我将重新创建一个简单的服务,以演示我正在看到(或在本例中没有看到)的内容。我的服务处理WCF消息,因此我不认为它在会话0中运行,我无法看到它是问题所在。
namespace BlockInputService
{
[ServiceContract(Namespace = "http://BlockInputService")]
public interface IBlockInputTest
{
[OperationContract]
void BlockInputMethod();
}
public class BlockInputTest : IBlockInputTest
{
private const string SOURCE = "BlockInputService";
private const string LOGNAME = "Application";
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern bool BlockInput([In, MarshalAs(UnmanagedType.Bool)] bool fBlockIt);
public void BlockInputMethod()
{
if (!EventLog.SourceExists(SOURCE))
{
EventLog.CreateEventSource(SOURCE, LOGNAME);
}
try
{
bool flag = BlockInput(true);
EventLog.WriteEntry(SOURCE, "BlockInput(true) returned: " + flag);
EventLog.WriteEntry(SOURCE, "Sleep for 5 sec");
Thread.Sleep(5000);
}
catch (Exception ex)
{
EventLog.WriteEntry(SOURCE, ex.Message);
}
finally
{
bool flag = BlockInput(false);
EventLog.WriteEntry(SOURCE, "BlockInput(false) returned: " + flag);
}
}
}
}