Windows 使用PowerShell打开Access数据库,模拟shift键作为服务
所以我问了一个问题并得到了答案。所以我有我的脚本,当我作为一个用户运行它时,它可以工作Windows 使用PowerShell打开Access数据库,模拟shift键作为服务,windows,powershell,service,Windows,Powershell,Service,所以我问了一个问题并得到了答案。所以我有我的脚本,当我作为一个用户运行它时,它可以工作 Add-Type @" using System; using System.Runtime.InteropServices; public class Tricks { [DllImport("user32.dll")]
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Tricks {
[DllImport("user32.dll")]
public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);}
"@
cd "C:\db_location\"
$ms_access = New-Object -ComObject "Access.Application"
[tricks]::keybd_event(0xA0, 0x45, 0, 0);
$ms_access.OpenCurrentDatabase("C:\db_location\db_app.accdb", $false)
[tricks]::keybd_event(0xA0, 0x45, 0x2, 0);
$ms_access.Run("do_work")
$ms_access.Quit() | Out-Null
如果安装运行此PowerShell的服务失败,则为否。它从未到达$ms_access.Rundo_工作位,因此这意味着打开没有完成。打开无法完成的唯一原因是模拟的shift键不工作
当此脚本作为服务运行时,如何使keybd_事件工作?普通Windows服务既没有键盘也没有鼠标。无法为不存在的键盘生成键盘事件。您可以尝试将您的服务配置为交互式,或者找到其他方法打开access数据库,如