Silent installation of programs on a remote computer. For the little ones

At the moment, when many foreign companies have suspended their activities in Russia, the issue of automating routine work processes is becoming increasingly relevant. henchmen available free of charge.

I bring to your attention an article about remote installation of programs using regular Windows 10 tools and free console utilities.

Consider installing the two most common types of installation files .exe and .msi, using the example of everyone’s favorite free 7-zip archiver and the Google Chrome browser

To get started, we need the latest distributions, which can be downloaded from the official sites:

  1. At the time of this writing, the current version of 7-zip was 21.07 (64 bit installer for Windows)

  2. We will download Google Chrome in the form of MSI installation packages, at the time of writing the current version is 102.0.5005.63 (download msi installer)

    #Please note that the installer itself is packaged in an archive with a .zip extension, and in order to extract it, you will first need to install the previously downloaded 7-zip archiver.

We also need the psexec utility, which is included in the PsTools package, you can download them here.

Now the installation files we downloaded and the psexec utility must be placed in the same folder, let it be D:\silent\7z and D:\silent\chrome for convenience

#After unpacking the archive with the Chrome distribution, the file we need will be in the \Installers\ folder GoogleChromeStandaloneEnterprise64.msi

##Because most modern Windows installations are 64-bit, we will use the PsExec64.exe file

Now you can use the Windows command line to start installing programs on a remote computer

# Press the key combination wir + R, enter CMD and press OK

Let’s go to the directory with the downloaded 7-zip by running the command

c:\>cd d:\silent\7z

I’ll tell you more about how the PsExec utility works.

In the simplest case, the syntax of our command will be as follows:

psexec \\computer [-u пользователь [-p пароль]]program [аргументы]

Where:

\\a computer – the name of the remote computer on which we will install our archiver (we have it user_pc)

[-u пользователь [-p пароль]] – optional parameters if your account has rights to install programs or administrator rights in the domain. If not, these parameters help you specify the username and password of a user that has sufficient rights.

program – name of the executable file, (7z2107-x64.exe)

arguments – application installation settings that affect the installation process itself. Other arguments are called keys.

#For example, the argument /S – will mean a silent installation of the program, without user intervention on a remote computer. There can be many silent installation keys, and they may differ for different programs. You can pick them up by studying the documentation for the program, but as a rule, most of them are universal.

So our final command will look like this:

PsExec64.exe \\user_pc –c 7z2107-x64.exe /S

the -c switch copies 7z2107-x64.exe to a remote computer for later launch

In case of successful installation of the program in the command line window, we should see the following:

7z2107-x64.exe exited on user_pc with error code 0.

error code 0 means that the program was installed successfully.

In case of successful installation of the program in the command line window, we should see the following:

7z2107-x64.exe exited on user_pc with error code 0.

error code 0 means that the program was installed successfully.

Everything! The user working on user_pc absolutely imperceptibly became the happy owner of the 7zip archiver.

Now let’s proceed with the remote installation of the Google Chrome browser, which we downloaded as an installation file with the .msi extension.

To install MSI packages in windows, use the msiexec utility, which is already installed in the operating system. As a rule, this utility is located in the c:\Windows\system32\msiexec.exe directory.

It will be more convenient and faster if you copy the pre-installation file to the target computer and run it remotely from there. The xcopy utility built into Windows will help us with this. It has a very simple syntax in style:

xcopy what_copy where_to_copy copy_options

xcopy D:\silent\Chrome\GoogleChromeStandaloneEnterprise64.msi \\user_pc\c$\Windows\Temp\ /s /e

Where:

D:\silent\Chrome\GoogleChromeStandaloneEnterprise64.msi – full path to the installation file on our computer

\\user_pc\c$\Windows\Temp\ – destination path for the copied file on the remote computer

/s /e- Copy directories with subdirectories, including empty ones.

Now everything is ready to start the remote installation of the program.

psexec64.exe \\user_pc c:\Windows\system32\msiexec.exe /ic:\Windows\Temp\GoogleChromeStandaloneEnterprise64.msi /qn /quiet /norestart

In the first part of the command, we specify the name of the remote computer to the psexec64.exe utility \\user_pc and the location of the utility responsible for installing .msi files c:\Windows\system32\msiexec.exe (as a rule, it is always located along this path), then comes the /i key, which means that the program will be installed (install), after which we specify the full executable file on the remote computer c:\Windows\Temp\GoogleChromeStandaloneEnterprise64.msi and at the end we specify several silent installation keys:

/qn – completely hides the installation process from the user

/quiet – Quiet mode without user interaction. All windows will be hidden. If a reboot is required after the update, it will be done.

/norestart – cancels the restart, if it is necessary after installing the program.

Thus, after running our command to silently install the Google Chrome browser remotely, the user on the remote computer will not notice anything exactly until the browser shortcut appears on his desktop.

What if you have 100 computers on your network that need to install the same Google Chrome browser? You can do it manually by running the copy and install commands for each computer separately – this is a long and laborious process, or you can automate it by writing a simple script and giving it a file with a list of computers to install.

We will write the script as a .bat file, in which commands will be sequentially executed.

In the D:\silent\chrome folder, create the install.txt and userspc.txt files and open them in notepad.

In the file userspc.txt we enter a list of PCs on which we plan to install Chrome, the file should not contain any extra characters, except for the names of the PCs and the line break character. You can also use IP addresses of computers instead of names. The file can then be saved and closed.

Now it would be nice to know on which computers the browser was successfully installed and on which the installation did not take place (for example, the computer could be turned off at the time the script was run). To do this, in the chrome folder we will create a log folder in which we will create two files install-good.txt and install-bad.txt, in which the script will enter the names of computers with (un)successful installation.

In the install.txt file we write the following:

for /f %%i in (d:\silent\Chrome\userspc.txt) do (

mkdir \\%%i\c$\Windows\Temp\Chrome

xcopy D:\silent\Chrome\googlechromestandaloneenterprise64.msi \\%%i\c$\Windows\Temp\Chrome /s /e

psexec64 \\%%ic:\Windows\system32\msiexec.exe /ic:\Windows\Temp\Chrome\googlechromestandaloneenterprise64.msi /qn /quiet /norestart

 if errorlevel 1 (

echo %%i >>D:\silent\Chrome\log\install-bad.txt

) ELSE (

echo %%i >>D:\silent\Chrome\log\install-good.txt

)

rmdir /s /q \\%%i\c$\Windows\Temp\Chrome

)  

pause

Let’s analyze the commands and the algorithm of this script line by line:

The algorithm is simple, in a loop we read the names of computers from the userspc.txt file line by line, each name is assigned to the variable \\%%i, then the commands we compiled earlier for copying and silently installing Google Chrome are executed. At the end, the script checks the code of the error returned by the script. If the script returns 0, the install-good.txt file contains the name of the current computer on which an attempt was made to install the program. If the error code is different, then the computer is recorded in the install-bad.txt file.

for /f %%i in (d:\silent\Chrome\userspc.txt) do (

…

)

The for loop is designed to execute repeated commands of the same type,

Let’s take a closer look at his work. %%i is a variable that is a counter of loop steps, it must be written exactly as in the example using a double percent sign and a letter of the English alphabet, one. At each step of the loop, the commands written after the word do are executed. The /f switch indicates that the loop will work with files. The word in is followed by the path to the file where the computer names are stored.

This program block reads the names of computers line by line and executes the commands in parentheses for each of them.

mkdir \\%%i\c$\Windows\Temp\Chrome

mkdir is a command for creating directories. In our case, we create a Chrome folder on the remote computer in the \Windows\Temp\ folder. Let me remind you that the current name of the remote computer is stored in the %%i variable.

How xcopy works was discussed earlier in the article, so we will not focus on it.

psexec64 \\%%i c:\Windows\system32\msiexec.exe /i c:\Windows\Temp\Chrome\googlechromestandaloneenterprise64.msi /qn /quiet /norestart – starts the installation of Chrome on each individual computer.

if errorlevel 1 (

echo %%i >>D:\silent\Chrome\log\install-bad.txt

) ELSE (

echo %%i >>D:\silent\Chrome\log\install-good.txt

)

if – a command that processes some kind of logical condition, it is also a branch operator. Those. if the condition given after the if is met, then the command following the condition will be executed. Otherwise, the commands following the ELSE statement will be executed. Upon completion, the program returns an exit code, using errorlevel they can be used as a condition.

echo %%i >>D:\silent\Chrome\log\install-bad.txt

echo – a command that displays some text in the command line window, the command output can also be redirected to a file using the >> operator. In our case, with this command, the names of computers with (un)successful installation are recorded in the install-bad.txt and install-good.txt log files.

rmdir /s /q \\%%i\c$\Windows\Temp\Chrome – the effect of this command is back to mkdir, i.e. it will delete the Chrome directory we previously created on the user’s PC, thereby putting things in order and not leaving unnecessary installation files clogging disk space.

pause – will simply leave the command line window hanging, and will not let it close automatically after the completion of our script.

As you can see, everything is simple.

Additional information about types of installers and silent installation keys can be read here.

About the subtleties of the team xcopy here.

Try writing your own script to install 7-zip.

If you have any questions, I’ll be happy to answer them in the comments.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *