China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-07 16:25
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » A question for everyone View 1,248 Replies 8
Original Poster Posted 2006-04-29 15:02 ·  中国 安徽 宣城 电信
初级用户
Credits 36
Posts 14
Joined 2006-04-29 14:56
20-year member
UID 54667
Status Offline
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,
Floor 2 Posted 2006-04-29 15:34 ·  中国 北京 顺义区 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
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?
Floor 3 Posted 2006-04-29 16:33 ·  中国 安徽 宣城 电信
初级用户
Credits 36
Posts 14
Joined 2006-04-29 14:56
20-year member
UID 54667
Status Offline
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.
Floor 4 Posted 2006-04-29 16:59 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
Example:

With Wscript.CreateObject("Wscript.Shell")
.run "notepad" 'run Notepad
Wscript.Sleep 500 'wait half a second
.SendKeys "D~" 'press the D key and Enter, ~ means Enter.
Wscript.Sleep 500
.SendKeys "~O~"
Wscript.Sleep 500
.SendKeys "~S"
End With

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.
Floor 5 Posted 2006-04-29 17:07 ·  中国 安徽 宣城 电信
初级用户
Credits 36
Posts 14
Joined 2006-04-29 14:56
20-year member
UID 54667
Status Offline
Thanks bagpipe and moderator. I'll test it first now. Thanks again to both of you.
Floor 6 Posted 2006-04-29 17:16 ·  中国 安徽 宣城 电信
初级用户
Credits 36
Posts 14
Joined 2006-04-29 14:56
20-year member
UID 54667
Status Offline
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?
Floor 7 Posted 2006-04-29 17:17 ·  中国 安徽 宣城 电信
初级用户
Credits 36
Posts 14
Joined 2006-04-29 14:56
20-year member
UID 54667
Status Offline
Sorry. I don't understand VBS scripts at all. Sorry to trouble you two, thanks, many thanks again.
Floor 8 Posted 2006-04-29 17:35 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
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:

With Wscript.CreateObject("Wscript.Shell")
.run "notepad" 'run Notepad
Wscript.Sleep 500 'wait half a second
.SendKeys "D~",5 'press the D key and Enter, ~ means Enter.
Wscript.Sleep 500
.SendKeys "~O~"
Wscript.Sleep 10000
.AppActivate "Untitled - Notepad"
.SendKeys "~S"
End With
Floor 9 Posted 2006-04-30 14:03 ·  中国 北京 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
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
Forum Jump: