Use VBS scripts to automate GUI installation
What are the requirements and scenarios?
1, the reason why
Some time ago, the blogger wrote a note about the network adapter driver, there is a companion message related to the installation of dependency problems. It just so happens that bloggers want to give it a try, hence the current solution.
No NPCAP driver on Windows causes Golang to fail to obtain network adapter
2, requirements,
The installation of some software in Windows provides the GUI mode of custom installation, but in some scenarios you do not want to manually intervene. Is to want the so-called silent installation mode, but some software does not support silent installation mode under certain conditions.
0 x01, scheme
The general idea is to use script automation control to simulate the human-computer interaction process to achieve one-click installation.
1. Use script sprites and button sprites
There are a lot of introductions on the Internet, mainly to provide simulated click the mouse time, replay key events, by recording dot matrix coordinates to achieve click operation.
However, because it is achieved through coordinates, the disadvantages are also obvious, not suitable for transplant to other devices for operation. Even a slight discrepancy in resolution can cause automation to fail.
Others require a driver, which creates a chicken-and-egg problem.
2, with WinSpy++
Use WinSpy++ to get the form object, and use the default installation policy, press enter, to achieve the default one-click installation.
WinSpy++ comes from VC++, is a tool that can get a variety of program handles, such as form title, button, input box, progress bar and so on handle. You can send messages to the obtained handle to realize the background hang up. WinSpy involves quite a few calls to Windows API offerings that I won’t go into here.
Details can be viewed in this blog, more detailed. Use of Spy++ _smeller’s column -CSDN blog _spy++
3. Use C++ code to operate
C++ is more suitable, some programs are installed using C++ to operate. Mainly call kernel32 handle to obtain program PID, handle, similar process, are simulated interaction process, finally packaged into an EXE executable file.
4. Use VBS scripts
The VBS script is used to create objects that can be invoked by programs running on Windows, and the wscript. Shell object is used to perform SendKeys() operation. The default policy can be installed by one click, or custom policies can be automatically installed.
This method is not complicated and easy to use.
What is VBS?
Talking about VBS, we have to mention VB, what is VB?
1, Visual Basic
VB is the abbreviation of Visual Basic, is Microsoft company development of a general object based programming language, structured, modular, object-oriented, including to assist the development of the environment for the event driven mechanism of the Visual programming language, is a can be used for Microsoft’s own product development language.
2. Basic
And VB is derived from BASIC programming language, is not a kind of nesting baby feeling, in fact, there is no, but the development of technology is such a step by step process, from the original technical level to establish new technology, layer upon layer iteration.
3. Visual Basic Script
Without further ado, VBS is a Visual Basic-based scripting language. VBS stands for Microsoft Visual Basic Script Edition. Microsoft Visual BASIC Script, a language similar to Visual BASIC (VB), is used to efficiently generate type-safe and object-oriented applications. Programmers can easily use VB components to quickly build an application.
VBS is the default ASP language, which can be used in Windows scripting and web coding. Although its syntax is similar to VB, it is a completely different language. VBS does not use the VB runtime but is interpreted by the Windows script host.
What is wscript.shell?
Shell is the ProID of Wshshell. Wshshell is an object stored in the Wshom. ocx file in the Windows system, which can be called by programs running on Windows, and can be accessed by Windows shell programs. An object is a software set or library of related variables and methods. When you need a variable, method, or function in this object, you can use the language (code) to call it. ProID is an alias given by programmers to a CLSID. The composition such as.. CLSID is a code, short for Class ID, that uniquely represents what Windows systems assign to different applications, file types, OLE objects, special folders, and various system components.
Through the code
Set Obj = createobject("WScript.Shell")
Copy the code
Get the object Obj, that is, Wshshell is an object.
0x04 VBS code (Npcap.exe as an example)
1. First create the wscript.shell object and call its Run() method to Run the npCAP program.
2. Enter Y to confirm the reinstallation, as shown in the figure.
3. Press Enter to complete the installation.
In order to achieve better results, use delay to control the enter key, the code is as follows.
'D:\MyGit\ VBS \demo. VBS Set objShell = CreateObject(" wscript.shell ") strCommandLine = "D:\MyGit\ VBS \npcap-1.50.exe" objShell.Run(strCommandLine) Wscript.Sleep 1000 objShell.SendKeys "Y" Wscript.Sleep 300 objShell.SendKeys "{ENTER}" Wscript.Sleep 300 objShell.SendKeys "{ENTER}" Wscript.Sleep 26000 objShell.SendKeys "{ENTER}" Wscript.Sleep 300 objShell.SendKeys "{ENTER}"Copy the code
0x05. Custom mode installation
The wscript.shell object provides the SendKeys() function, which can be customized by keyboard manipulation, avoiding the need to emulate coordinates and improving accuracy.
For example, the [TAB] key is used to select the function, and the [ENTER] key is used to confirm the function. [LEFT, RIGHT, UP, and DOWN] correspond to “{LEFT}”, “{RIGHT}”, “{UP}”, “{DOWN}” respectively.
Others, Shift –>”+”, Alt –>”%”, CTRL –>”^”
Example file directory
Because you need administrator permission to run, avoid agreeing administrator permission to run pop-ups, use bat batch package layer 1, right click administrator to run bat file, realize one-click operation.
The bat code is as follows
:: D:\MyGit\vbs\run.bat
@echo off
@title install npcap program
@start D:\MyGit\vbs\demo.vbs
@echo.
@echo installing...
@echo please don't touch it.
@timeout /T 30
exit
Copy the code
The following figure shows the file directory.
0x07 effect GIF
0x08 References:
VBS (Scripting Language)
Baike.baidu.com/item/VBS/17…
Visual Basic (Programming Language)
Baike.baidu.com/item/Visual…
Use of Spy++ _smeller’s column -CSDN blog _spy++
Blog.csdn.net/smeller/art…
Wscript. Shell, rounding blog.csdn.net/yainyiyi123…