如何在新的虚拟桌面中从powershell脚本打开CMD?
我知道如何打开虚拟桌面:
$KeyShortcut = Add-Type -MemberDefinition @"
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
//WIN + CTRL + D: Create a new desktop
public static void CreateVirtualDesktopInWin10()
{
//Key down
keybd_event((byte)0x5B, 0, 0, UIntPtr.Zero); //Left Windows key
keybd_event((byte)0x11, 0, 0, UIntPtr.Zero); //CTRL
keybd_event((byte)0x44, 0, 0, UIntPtr.Zero); //D
//Key up
keybd_event((byte)0x5B, 0, (uint)0x2, UIntPtr.Zero);
keybd_event((byte)0x11, 0, (uint)0x2, UIntPtr.Zero);
keybd_event((byte)0x44, 0, (uint)0x2, UIntPtr.Zero);
}
"@ -Name CreateVirtualDesktop -UsingNamespace System.Threading -PassThru
$KeyShortcut::CreateVirtualDesktopInWin10()
然后仍然在PowerShell脚本中打开cmd并运行一些脚本
CMD.EXE /C
cd "C:/users/.../..."
somescript
但CMD在当前桌面中打开,而不是在新创建的虚拟桌面中打开。
有什么建议吗?需要在新的虚拟桌面中打开CMD,然后调用somescript。