How to hide the cmd window when running a batch? Little secrets of a big system How to hide the batch file console.


The article describes various ways to hide the cmd window while executing a batch file.

Bat files, also known as batch files, can be very useful for running a whole package of commands. But I think many people are wondering how to make sure that the console window does not appear on the monitor. I will focus primarily on the built-in capabilities of the system; I will briefly mention third-party programs. Along the way, we will solve some other problems, for example, by adding a separate shortcut for the batch file.

How to bypass UAC protection? Refer to article

How to hide cmd window. Is it possible to do this using the body file itself?

No. The code runs in the console environment, which means the window will be displayed. You have to come to terms with this: the window will be open as long as the code is executed. All you can do is take some steps to ensure that the window appears for a minimum period of time. In principle, this is useful: we can observe the operation of the code with our own eyes. But if you want to hide the console window, you will have to use third-party tools to do this: other developers or the capabilities of Windows itself. Let's start with it.

Run the batch file quietly. Windows only.

In the “code madness” file itself, you sing the song yourself. I will suggest optimizing its content for maximum quiet operation. There is an important point here: the shorter the code itself, the more likely it is that the console window will appear for a short time. If the volume is large or several commands are written at once, the window may attract attention.

For example, I’ll take the script code, which allows a little (specifically, the characteristics processor V System properties ). This is done for the duration of the Windows session: after a reboot, everything will fall into place.

In general, we have the following batch file code:

REGEDIT4 ; @ECHO OFF ; CLS ; REGEDIT.EXE /S "%~f0" ; EXIT "ProcessorNameString"="Intel(R) Core(TM) i112-3470 CPU @ 800.5GHz"

Pay attention to the processor specifications. He will be responsible for changing system information. We name the file spec .bat . Also note that I will use only Latin characters in file names and avoid Cyrillic in the paths to their location, so that the path to the script is read by the system correctly. That’s why I’ll put the created bat file in the system directory - directly in the C: drive.

However, its launch is accompanied by:

  • console window appears cmd
  • the appearance of a UAC confirmation window with the changes being made (the task, as you can see, has become more complicated in itself, because system information is changing)

before executing the batch file, a UAC window appears

I suggest you get rid of the first window using the following script, already formatted into another vbs file. And here is the script for it (see my path to the file C:\spec.bat):

"HideBat.vbs CreateObject("Wscript.Shell").Run "C:\spec.bat", 0, True

I will call it by any name with the extension .vbs. Now the work of the batch file by clicking on the vbs nickname is accompanied only by the appearance of a window Account Control: the fact is that the changes made by the batch file affect the registry, and the system logically does not let this pass uncontrollably. How is the topic of a separate article:

However, we will digress a little from the topic of the article and finish what we started by creating a console hide for the file ( vbs file) special label. In the Object location field, indicate the path in the format:

Wscript path-to-vbs-nick path-to-bat-nick

The label is ready (you can change its design via Shortcut properties). You can drop it into your Startup folder, place it in Windows Scheduler, or launch it by double-clicking it. There will be no console window.

How to hide cmd window? Special programs.

There are many of them, they are lightweight and easy to use. The downside is that they need to be downloaded and some installed. I will give the most popular of them:

  • Hidden Start (HStart)

Utility from a domestic manufacturer. I need to buy it, I don’t know the cost. However, with its help you can hide the window once and for all, and it doesn’t matter whether UAC confirmation is required or not - you can hide it too:

For 32 and 64 bit versions. It does not require installation; it is supplied as an executable file, which, when launched (as an administrator), is immediately sent to the Windows root directory. We agree, and she is now with us:

The utility can do a lot of things, including changing the sound level, opening drive trays, etc. For our case, to hide the cmd window, we could simply enter a command like:

Nircmd elevatecmd exec hide filepath

We didn’t get rid of the UAC window (elevatecmd exec is part of the command asking for UAC), but we weren’t promised that. And it’s inconvenient to constantly write the full path to the file in the console, so let’s immediately create a shortcut:

Nircmd cmdshortcut "~$folder.desktop$" "Batch file" elevatecmd exec hide path-to-file

How to hide the cmd window: batch turned into exe.

Also an option. This is already the music of the higher spheres. To those who are unfamiliar with this utility, check it out - it will come in handy: Bat To Exe Converter. As you can tell by the name, it turns a batch file into an executable file with the .exe extension. Download, install, use:

Good luck.

Read: 546

Sometimes there is a need to run bat file in invisible mode, hide, hide bat window. For example, if the file is executed through the scheduler. Or maybe a lot of commands are written there and take a long time to execute, while it flashes before your eyes. Examples of what you need hide bat window There are many files that can be cited. So if you are interested in how hide cmd window or how to run a program secretly, read carefully.

I suggest you familiarize yourself with the offers of my partners

1. Using the vbs script. With this script you can secretly launch programs, bat files, other files.

Dim oShell Set oShell = WScript.CreateObject ("WSCript.shell") oShell.run "application path\application name", 0 Set oShell = Nothing

For those who don’t know, just copy the text into notepad, put your path to the application and the name of the application, save it under any name - but with the vbs extension (for example - hide the start.vbs window)

Example: secretly launch the batch file qwerty.bat from drive C

Dim oShell Set oShell = WScript.CreateObject ("WSCript.shell") oShell.run "C:\qwerty.bat", 0 Set oShell = Nothing

Similar code

Set WshShell = CreateObject("WScript.Shell") RetCode = WshShell.Run("C:\qwerty.bat", 0, False)

You can run not only *.bat but also other files in hidden mode. For example, you want to run mp3 without a player window, provided you use Windows Media Player

Set WshShell = CreateObject("WScript.Shell") RetCode = WshShell.Run("C:\qwerty.mp3", 0, False)

If your mp3 is linked to another player, then add wmplayer.exe to the code

Set WshShell = CreateObject("WScript.Shell") RetCode = WshShell.Run("wmplayer.exe C:\qwerty.mp3", 0, False)

2. cmdow utility (place the utility itself in C:\windows\system32)

So, the command line console is present in all versions of Windows operating systems. Early versions of the OS supported MS-DOS mode directly, which made it possible to execute simple commands directly from the console. Representatives of the NT family, such as Windows 2000 or Windows Server 2003, work on completely different principles, however, MS-DOS is also supported in them, but through a virtual machine (NT Virtual DOS Machine, NTVDM), which allows you to control and administer system resources directly from the command mode console. The command mode interpreter is the cmd.exe program, which is launched through the “Start -> Run” menu. In addition, to launch the console, you can use the menu item “Start -> All Programs -> Accessories -> Command Prompt”.

By launching a command-mode console, the user can manage resources of both the local system and the resources of a remote machine. There are commands that monitor the system and identify critical points in the server settings. The difference between working from the command line is the complete absence of large and cumbersome graphical utilities. Command line programs allow finer tuning in the form of key parameters listed to the right of the command itself.

Using special script files (sets of commands executed sequentially or in a programmed order), the administrator can minimize routine daily operations. Existing modern utilities can run such scripts at specified intervals without the presence of a system administrator.

The administrator himself can execute both single commands and a list of commands using special control characters (&, |). For example:

Command 1 & Command 2 - Command 1 will be executed first and only then Command 2;
Command 1 && Command 2 - only after successful execution of Command 1 will Command 2 be launched. It is possible to redirect the program output stream directly to a text file for further processing. To do this, you must use the control character “>” and the name of the text file. An example of outputting the contents of the current directory to the text file Report.txt using the dir command is given below:
dir>Report.txt

An administrator can launch multiple copies of the console by calling cmd.exe from the command line. Using a nested console allows you to work with operating system environment variables without any consequences for the entire system as a whole, since changes to environment variables are not saved after closing the nested console. The setlocal, endlocal, and set commands are used to control this process.

There are many commands and utilities in modern operating systems. Remember so many different programs, and even more so their parameters
very difficult, so one of the most important parameters for each program is the combination of symbols /?. After executing a command with this parameter, the user will receive a comprehensive message about the use of the utility and the syntax of its parameters.

Note that the illustration in the upper left corner of the next page uses complex syntax. So, immediately after the shutdown /? after the special separator “|” the more command is used, which allows you to display information on the screen not entirely, but in certain portions, convenient for further reading.

To close the command line console, you must run the exit command.

Who's in charge here?

According to their capabilities, console programs are divided into:

  • operating system control commands are commands such as shutdown or taskkill;
  • network commands - net and ipconfig;
  • commands for system monitoring - tasklist and systeminfo;
  • commands for file system support - dir, mkdir, copy;
  • commands for maintaining hard drives - defrag and diskpart;
  • commands to support directory services (Active Directories) - addrep and dsadd;
  • auxiliary commands, this section includes various utilities for creating scripts, setting up printers, working with environment variables, etc.

Let's look at typical representatives of each group and allow ourselves to give some recommendations for using the commands included in them.

Monitoring and diagnostic commands

Monitoring commands such as systeminfo and tasklist are used to identify hardware and software problems. These utilities were first introduced in the Windows Server 2003 operating environment, so administrators have not yet fully appreciated the functionality of these commands. So, for example, now you don’t need to go to the “Properties” tab of the “My Computer” icon - the systeminfo command will print basic information about all system components with a full decryption on the console screen. The /s parameter will display information about any remote computer. For example, to find out the configuration of the TESTSERVER computer, you would run the following command:

Systeminfo /s TESTSERVER

And the tasklist utility will show the processes running on your computer.

The tasklist utility allows you to query systems connected to a network. The /v parameter allows you to get detailed listings with useful information, including usernames, and the /t parameter shows the processes that loaded a specific dll file. Another useful utility, openfiles, allows you to obtain information about all open files on the local and remote operating system. In previous versions of Windows operating systems, you had to use the oh.exe command; in modern versions, it is enough to run a command in the console command line that sets the monitoring mode for all open files in the system:

Openfiles/local on

The user will receive information about all open files on the system using a command with a simple syntax:

Openfiles

The openfiles command with the /query /v options shows which users are running the processes that opened the files. Using other key parameters, you can set different information output modes.

Operating system commands

Windows Server 2003 provides administrators with new commands that help them not only diagnose the system, but also manage it. Such commands include the shutdown utility. The following can be used as key parameters for this utility:

  • /s - complete normal system shutdown;
  • /p - power off;
  • /f - shutdown active applications;
  • /d — transition to low power consumption mode;
  • /I - ends the session without turning off the computer.

In the form of a tool that registers all regular shutdowns of the computer, the shutdown event handler (Shutdown Event Tracker) acts as a tool that collects and diagnoses all shutdowns performed by the administrator. It is also possible to shut down the system indicating the reason; for this you need to use the /d switch.

The taskkill command, analogous to the kill command in operating systems of the *nix family, allows you to “kill” a frozen application. Together with the tasklist command, these utilities provide a powerful tool for quickly intervening in the execution of applications that pose a potential threat to server performance. Among the parameters of this command, you should note the /pid key, which allows you to terminate a process by its unique identifier, and the /im key, which allows you to terminate the application with the specified name. The following example terminates processes with IDs 1000 and 1240:

Taskkill /pid 1000 /pid 1240

Commands for Hard Drive Maintenance

The defrag command allows you to optimize your hard drive. The utility can defragment disks with the FAT, FAT32 and NTFS file systems. Defrag works equally well with both dynamic and basic disk types. The syntax for calling this command is as follows:

Defrag disk [ -a j [ -f ] [ -v ] [ -? ]

The -a parameter provides only analysis of information on the disk, the -f parameter — optimization of information, including in the absence of the necessary disk space to create temporary files, and the -v parameter — outputs a report on the optimization progress. Don't forget that for defragmentation to succeed, the disk must contain at least 15% free space.

The fdisk command is no longer supported by the kernel of the Windows Server 2003 operating system. It has been replaced by the diskpart command, also intended for servicing hard drives. Split a disk into partitions, create logical drives, delete them - these are just some of the tasks solved by this utility. Basically, the diskpart command is focused on working with special script files that describe hard drive maintenance procedures. This is what calling this command looks like for the script file Scriptl.txt:

Diskpart /s Scriptl.txt

Each line of such a file is an instruction for some operation. So, for example, gives a command to create a new partition with a certain size line

Create partition logical size=2048

Network commands

Among the network commands, I would like to highlight two utilities. The first is the ipconfig command, the second is netstat. System administrators use these commands not only to monitor the network, but also to protect against dangerous programs that try to take control of the system.

Using the ipconfig utility, the user can find out the network address of his computer, and by calling this command with the /all parameter, obtain complete information about the network configuration on the local computer. The /renew parameter allows you to change network settings without rebooting the entire system.

If you notice that something wrong is happening with your computer, then the netstat command will help in this case, which will not only indicate open network ports through which attackers could connect to your system, but also identify processes running on the server without your knowledgeable Thus, the /o switch displays information about the process identifier (PID) using a particular network connection. It is possible to see which computers on the network are communicating with your local operating system.

Commands for Directory Service Support

The entire network consists of components and is a complex hierarchical structure built in the form of a tree. The objects of such a system are sites, subnets, servers, computers, groups, users, contacts, shared network devices.

To monitor such a complex structure, the operating system provides the dsquery command, which is designed for an advanced search of directory service components. This command can also be used to display information about the properties of selected components (the -attr switch). The -scope, -subtree, -onelevel, -base parameters determine the search nesting level, and the -filter key allows you to use the search filter.

The dsmod command can help if you need to modify one or more accounts for a selected directory service component. For example, you can remove a user from a group or assign a new password to them. An example of changing the account for the TestUser user is shown below:

Dsmod user
"CN=TestUser,CN=Users,DC=bigtex,DC=net " -pwd Uf@tfmgerelt -mustchpwd yes

The dsmove command moves an object within the current domain. Using the -newname and -newparent keys, you can set a new object name and change its location.

File System Support Commands

A description of some frequently used commands for working with files and directories is presented in the table. The deltree command, which performed cascade deletion of folders and files in them, is now replaced by rmdir with the /s switch.

Little secrets of a big system

Changing the command line prompt

Find the key in the registry: Create a string parameter “PROMPT” with type (REG_EXPAND_SZ) in this key and assign one of the following values:

  • $B – vertical bar “I”;
  • $D - current date;
  • $G - greater sign ">";
  • $1_ - less sign "<»;
  • $N — current disk;
    $P - current drive and path;
  • $Q - = "=";
  • $T - current time;
  • $V — Windows version;
  • $$ is the dollar sign “$”.

After the reboot, you will see the invitation in the form you defined.

Automatic commands

To enable the ability to auto-type commands by pressing the “Tab” key, find the key in the registry:

Then set the CompletionChar value to 9, which is the ID of the Tab key, close the registry, and restart your computer. In a console window, while typing part of a command name, you can now press the Tab key and Windows will automatically substitute the required command.

Changing console color

Find the key in the registry:

Change the DefaultCoior parameter. The -F0 value will output black text on a white background, and the IE value will surprise you with a yellow and blue console color.

Quickly launch the command line console from the context menu

Find the key in the registry:

Add subsections “CommandPrompt -> Command” to it. Set the Default parameter of the Command key to “cmd.exe /k cd “%1””.

Set the Default parameter of the Command Prompt key to “Open Command Prompt”.

By right-clicking on any folder in Explorer, you can select the Open Command Prompt command, which will launch a command line console in the desired directory.

Conclusion

OK it's all over Now. We talked about the basics of working with the console. Next, we give you the opportunity to explore the functionality and variety of console commands yourself. Just don’t forget the treasured key /?, and the rest will come with time and experience.







2024 gtavrl.ru.