- 论坛徽章:
- 0
|
最近我也建了一个Virtual PC,原本想全自动开机和关机的,自动开机与关机,都很容易解决,但最后被卡在了Virtual PC的启动上。
最后没办法,自己用VB6精简版写了一个小软件。原码在下面,有兴趣的同行可以试用一下。
这个软件流程很简单,首先要安装Virtual PC后(我是默认安装在C盘),运行这个软件会自动启动,之后暂停5秒中,Virtual PC 控制台开启后,向Virtual PC 控制台发送alt+s命令,这样就成功了。我为了可靠发送alt+s命令做了三次。
***************************************
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Delay(ByVal ParTime As Long)
Dim tim
tim = Timer
While Timer - tim < ParTime
DoEvents
Wend
End Sub
Private Sub Form_Load()
ReturnValue = Shell("C:\Program Files\Microsoft Virtual PC\Virtual PC.exe", 1)
Sleep 5000
AppActivate "Virtual PC 控制台"
SendKeys "%S"
Delay 2
SendKeys "%A"
Delay 2
SendKeys "S"
Sleep 1000
keybd_event VK_Alt, 0, 0, 0 '按下alt键
keybd_event VK_S, 0, 0, 0 '按下S键
Sleep 500 '延时500毫秒
keybd_event VK_S, 0, KEYEVENTF_KEYUP, 0 '释放S键
keybd_event VK_Alt, 0, KEYEVENTF_KEYUP, 0 '释放alt键
End
End Sub |
|