中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-23 17:20
47,812 topics / 349,917 posts / today 0 new / 48,274 members
DOS批处理 & 脚本技术(批处理室) » A question for everyone
Printable Version  1,366 / 8
Floor1 hanbsome Posted 2006-04-29 15:02
初级用户 Posts 14 Credits 36
Hello everyone, I'd like to ask the experts here for a batch file. Let's say I want to install e:\123.exe. The 123.exe file is a Windows installer. During the installation process, it will ask me to click Next, Yes, and OK and so on. How can this be done with a batch file, so that there is absolutely no need to manually click the mouse or press the keyboard?
Thanks, everyone,
Floor2 bagpipe Posted 2006-04-29 15:34
银牌会员 Posts 425 Credits 1,144 From 北京
What you want can't be done with a batch file alone, because batch files can't provide key input, such as what you mentioned about clicking the NEXT button and so on (at least I don't know how). But your requirement can be achieved with the help of a VBS script. I wonder what the OP thinks?
Floor3 hanbsome Posted 2006-04-29 16:33
初级用户 Posts 14 Credits 36
Originally posted by bagpipe at 2006-4-29 15:34:
A batch file alone can't do what you want, because batch files can't provide key input, such as what you mentioned about clicking the NEXT button and so on (at least I don't know how). But your requirement can be achieved with the help of VBS 脠...


If it can be done with a VBS script, that would also solve the problem. Please teach me. I'd be extremely grateful.
Floor4 3742668 Posted 2006-04-29 16:59
荣誉版主 Posts 718 Credits 2,013
Example:

According to your requirement, you only need to change notepad to e:\123.exe, and then send the Enter key. If the default tab stop is not on the Next button, then you'll need to send the Tab key as appropriate.
Floor5 hanbsome Posted 2006-04-29 17:07
初级用户 Posts 14 Credits 36
Thanks bagpipe and moderator. I'll test it first now. Thanks again to both of you.
Floor6 hanbsome Posted 2006-04-29 17:16
初级用户 Posts 14 Credits 36
With Wscript.CreateObject("Wscript.Shell")
.run "notepad" 'run Notepad
Wscript.Sleep 5000 'wait half a second
.SendKeys "D~" 'press the D key and Enter, ~ means Enter.
Wscript.Sleep 5000
.SendKeys "~O~"
Wscript.Sleep 30000
.SendKeys "~S"
End With

A question again for the moderator: I changed the time to 5 seconds. After pressing Enter twice in a row, the installation process can already complete automatically. I changed the last time to 30 seconds, because the installation process takes about 20 seconds. I hoped it would press Enter once more after the installation was completed. That way the program would automatically restart the system. Why is it that even after changing it to 30 seconds, it still doesn't execute that final one?
Floor7 hanbsome Posted 2006-04-29 17:17
初级用户 Posts 14 Credits 36
Sorry. I don't understand VBS scripts at all. Sorry to trouble you two, thanks, many thanks again.
Floor8 3742668 Posted 2006-04-29 17:35
荣誉版主 Posts 718 Credits 2,013
It may be because while waiting, you activated another window, causing the current window to lose focus.
Before sending keys each time, you can first activate that window. The method is:
WshShell.AppActivate "window title"
For example:
Floor9 bagpipe Posted 2006-04-30 14:03
银牌会员 Posts 425 Credits 1,144 From 北京
This has to be decided according to the steps in your installer. I can only give you a rough framework for you to modify yourself, because we also don't know exactly what kind of program you're installing, or how many steps the installer has. So I can only give you an example, and you can modify it based on that example. Below is a script for installing CCLEANER software. http://www.ccleaner.com/ccdownload.asp This is the program download. This tool is pretty good; I've been using it for about 2 years already. It's a small program for cleaning junk files from the disk. Go to the page above and click "Alternative Download" to download it. Below is the VBS code:

option explicit
dim bagpipe,hi,ok
set bagpipe=createobject("wscript.shell")
hi=inputbox("Enter the full path of the program you want to run~~","Don't type it wrong, or it won't work!","Full path of the program")
set ok=bagpipe.exec(hi)
with bagpipe
wscript.sleep 1000
.appactivate ok.processid
.sendkeys "{ENTER}"
wscript.sleep 1000
.sendkeys "{ENTER}"
wscript.sleep 1000
.sendkeys "{ENTER}"
wscript.sleep 1000
.sendkeys "c:\test" 'this changes the program's default installation path to c:\test
wscript.sleep 1000
.sendkeys "{TAB 3}"
wscript.sleep 1000
.sendkeys "{ENTER}"
wscript.sleep 1000
.sendkeys "{ENTER}"
wscript.sleep 6000
.appactivate ok.processid
.sendkeys "{ENTER}"
end with
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023