How I created a system for installing printers at work


Hello dear% user%. Today I’ll talk about how I wrote a user system to enable users to install the printers they need for themselves. I’ll talk a little about the place where I work, so that it was clear why I did it. I will say in advance that I knew about the role component in Windows Server 2012 R2, which makes it possible to install a printer from a browser. But I wanted to invent my bike, and the restrictions here will probably be in imagination. To whom it became interesting welcome under cat. For those who are not patient, I’ll say right away that the screenshots are at the end of the article.

A bit about work

I work in helpdesk in a large organization that has many branches. There are more than a thousand employees working in front of computers. You can guess that there is a large zoo of network printers, there are individual employees responsible for the operation of printers. We install printers for computers - helpdesk. Very often, employees of different departments move from one workplace to another, come or leave, or even change their position and profession, and so on. A bunch of interesting things. Accordingly, because of this, very often calls come to our help desk about a request to install a printer for them. You see, asking the user to say the IP address of the printer is like asking the monkey to cook soup. I will give an example of dialogue (real case):

U - user, I - I
U- Hello, this helpdesk I got there?
I- Yes. Right. You got there
U- Please help me install the printer on my computer
I-Well, please tell me the name of your computer.
U-name of my computer comp-01 (fictitious name)
I-Which printer do you put? (Connecting to a computer)
U-HP LaserJet 600, it is located in% place%
I - the location of the printer does not give me anything (and really will change it with another printer since the first one has deteriorated, or will change its place). Ok, can you tell me the ip address of this printer?
U- ....
Pause at the end of the handset. I already heard the user stir a brain, blood began to flow from the ears, and finally he asked
U- Excuse me? Aimee? What do you say? Aimee address?
I am IP, IP address.
U- IP? And what is it? How can I look at him?
I - Okay, tell me, besides you, someone else uses this printer?
U-Well, it uses% another_user%
I-Please ask him for the computer name and get permission to connect to him for a second
U- Ok, now (and I hear a muffled voice as he asks% another_user% for the computer name and permission to connect )
I- ... .. (thinking to myself: Aim Aim Aim, Christmas tree sticks what rhyme for Aym can come up with)
I- Yes, I'm listening to you
U- Computer name comp-02, you can connect
I- Ask% another_user% show me the printer that he constantly uses (connect to a computer)
U- Ok, now (again a muffled voice) ....... - This
I- Ok, okay, I understand I won’t keep you on the line now I’ll put everything on my own and set it up
U- Okay, thanks. However, you did not tell me what aymi is.
I- Probably you mean IP. Well, it will be difficult to explain now, since there are too many calls, but in general this is the address of the device on the network.
Have you ever heard how the brain breaks down in the humanities? I heard this sound, you know such a dull sound with splashes of a large amount of information containing only "water".
U - .... (long pause) ... I see. I'll go away on business and you put the printer
I- Yes, okay, goodbye

Now imagine that every third caller in the helpdesk asking to install the printer in the same condition. How to be This kind of dialogue is very tiring, and explaining to the user how to print the configuration of the device in order to look at the IP of the printer is something super-heavy. So some kind of automation is needed. But what if you centrally collect all the printers on one separate printer server, write a simple website with a friendly interface. A couple of clicks and the printer is installed. Challenge accepted.

Everything is not so difficult as it seems

I asked system administrators to allocate a separate server on Windows Server 2012 R2.

To printer server

  • Installed the role of Printer Sever
  • Created scripts $ folder to store printer installation scripts
  • Installed XAMPP
  • Added apache and mysql as a service to autoload, so that in case of a server reboot, the website will not crash

With printers:

  • I pasted on all the printers to which the hands with their numbers reach the hands and installed them on the printer server. The serial number is an identifier for the printer. Wherever he is, the juver can always find him by the serial number. For example: “HP LaserJet 600 Printer #id% filial%”, where% filial% is the name of the branch, #id is the printer’s unique serial number. A piece of paper with a serial number is printed and glued to the printer. Even the name of the printer is not required for the user. The number coincided with what is on the site - so it is.
  • I agreed with the managers of the branches, asked for someone who knows in the branch to collect and send me the names, ip addresses of the printers and paste their serial numbers. Added all printers one at a time to the printer server.

Start programming

The website is built on PHP by writing a self-written MVC engine, using only the Notepad ++ editor, Google and the browser (yes - only on hardcore). I don’t have the knowledge of any framework, to study laziness, to use javascript frameworks in 2k17 ?, and is there too much for printers?

We set the goal that we need from this system:

  • The most simple and intuitive for the user
  • Ability to create administrator accounts
  • Ability to add / remove printers to administrators
  • Ability to add / remove branches to administrators
  • The presence of any reference information for the user
  • Switch language
  • The ability to install printers not one but several methods (scripts)

Define the structure of the project:

  • The app
    1. Configs
    2. Controllers
    3. Locale

  • Uploads

In the root folder, create the index.php file, add the code:

In the configs folder, create the database.php file:

We’ll go into the browser in phpmyadmin, create the printer database using the utf8_general_ci encoding. Create 3 tables named branches, printers, users.

Structure of branches:
NameA typeAdditionally
branch_namevarchar (255)
imagevarchar (255)

Printers structure:
NameA typeAdditionally
Namevarchar (255)
branchidint (6)Default value: 1
ipaddressvarchar (255)
imagevarchar (255)
File1varchar (255)
File2varchar (255)
File3varchar (255)

Users structure:
NameA typeAdditionally
Loginvarchar (128)
Tokenvarchar (128)
passwordvarchar (128)
langvarchar (10)
logindatevarchar (255)

As you can see from the tables, branchid determines which branch the printer belongs to (by getting its id value).

Create an entry with id equal to 1, branch name “none” and image with value “none”. This entry is needed to set the printer to an uninstalled branch. The first entry is hardcoded and does not appear in the list of branches, as for juzverejs and in the admin panel. It cannot be deleted.

The Database class I found on the Internet. It has a function for connecting to our database, using the values ​​for connecting from the database.php file located in the configs folder and a function for making queries to the database. İnfo

Classused to retrieve, modify, delete data from the database. It is using this class that all operations in the system are carried out.

One important class is the Controller.php class . As the name implies, this class is a controller that accepts GET and POST requests in __construct ($ get, $ post) from index.php. After receiving a specific request, he collects the pieces of the page in a single according to the desired request and performs the required functions from Info.php .

The Views class is a class that loads pieces of a page. Each page has its own name corresponding to the php file in the Views folder. So for example, to display the main page, you should write:

$views = new Views;
$views->addView('header', 'header.php');
$views->addView('menu', 'menu.php');
$views->addView('dashboard', 'dashboard.php');
$views->addView('footer', 'footer.php');

In the same class, the current user language is determined, localization is loaded from the ini file, and the $ lang variable is created, which is already used in the very piece of the page. Example code for the main page ( dashboard.php ):

The views folder also has css, javascript files. I used Bootstrap as the basis of CSS styles.

The Lang class defines the current language of the user. First he tries to get the cookie "cookie_lang". If it does not detect it, it sets the default language to Russian. The getLangArray () function loads the desired ini file and returns an array of the form "key" -> "value". This function is used in the views class.

What we got

The user goes to the main page. There is a description of where he got and a button that opens a list of all branches. After the user selects a branch, a list of printers opens. Printers are displayed in a grid, where their photos and their names. The user selects a printer, a page with the selected printer opens, where there is a large “Install” button (also there is information about the printer, its İP address). When you click on this button, a bat file is downloaded, which in turn opens a vbs script shared in the scripts $ folder on the printer server. The problem is that if you download the vbs file, then instead of downloading it, the browser opens this file in a new tab. Therefore, I had to be so perverted. Vbs files on the ball folder are also sorted together with their bat file into folders. For example, the folder structure is as follows:

Printer # id
  • Printer # id.bat
  • Printer # id.vbs

Where #id is the serial number of the printer.

When adding a new printer through the admin panel, the required fields are filled in and the desired bat file is selected from the balls. Setup file, printer photo is uploaded to uploads folder. The admin panel has made it so that we can upload up to three different installation files. How many files have been downloaded and there are so many “Install” buttons. In this case, there were no alternative methods for installing printers. VBS script turned out to be enough.

Vbs script

The Vbs script installing the printer looked like this:

printerName = "\\prnserver01\HP LaserJet 600 printer1 branch1"
Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.AddWindowsPrinterConnection printerName
WSHNetwork.SetDefaultPrinter printerName

This script is executed in invisible mode, for a while the command window appears, then it disappears. This script has the minus of what is not clear what is happening. Therefore, thinking a little changed it in this form:

'Задаем путь принтера
printerName = "\\prnserver01\HP LaserJet 600 printer1"
'Создаем окно Internet Explorer
Set objExplorer = CreateObject("InternetExplorer.Application")
'Задаем настройки окна - длину, ширину, позицию на экране
objExplorer.Navigate "about:blank"  
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Left = 500
objExplorer.Top = 250
objExplorer.Width = 550
objExplorer.Height = 170 
objExplorer.Visible = 1
'Задаем заголовок
objExplorer.Document.Title = "Ustanovka printera"
'Задаем html код страницы, со своим крутым дизайном
objExplorer.Document.Body.InnerHTML = "
Ustanovka printera: 0%
" & printerName & "
" 'Ждем 500 миллисекунд, находим на странице объект с id progress и меняем его значение. Психологический фактор для юзверя, толку от этого 0 Wscript.Sleep 500 objExplorer.document.getElementById("progress").innerText = " Ustanovka printera: 10%" 'Создаем объект для установки принтера, устанавливаем принтер и ставим его по умолчанию. Скрипт не продолжит выполнятся пока принтер не установится или выйдет ошибка Set WshNetwork = CreateObject("WScript.Network") WshNetwork.AddWindowsPrinterConnection printerName WSHNetwork.SetDefaultPrinter printerName 'Психологический фактор на 200 миллисекунд, хотя принтер уже установился или вышла ошибка Wscript.Sleep 200 objExplorer.document.getElementById("progress").innerText = " Ustanovka printera: 20%" 'Ещё один психологический фактор на 200 миллисекунд Wscript.Sleep 200 objExplorer.document.getElementById("progress").innerText = " Ustanovka printera: 40%" 'Ещё один, это же такой кайф когда проценты быстро идут Wscript.Sleep 200 objExplorer.document.getElementById("progress").innerText = " Ustanovka printera: 60%" 'В этом моменте можно уже откинуться Wscript.Sleep 200 objExplorer.document.getElementById("progress").innerText = " Ustanovka printera: 80%" 'О свершилось чудо, наконец! Wscript.Sleep 100 objExplorer.document.getElementById("progress").innerText = " Printer ustanovlen!" 'Получим на 3 секунды еще кайфа от того, что установили принтер и прощаемся Wscript.Sleep 3000 objExplorer.Quit


















The source code for all this has been uploaded to github.

Now there are much less calls to install printers.
Thanks for attention!

Also popular now: