Tuesday 12 June 2012

Tips, tricks and tutorial examples of commands and batch files

Some tips, tricks, examples to create, edit and customize the batch file. Solve problems and conflicts of use. Tutorial below commands and batch files, trivia, jokes, annexes.
After you have read the previous page to enter in a basic way to create batch files, if you are interested and attracted to the subject, you will find information that will help in editing and creation of these small tools. 
They are grouped and summarized on this page some of the answers to simple and practical issues that most often cause us to reach users

Create greetings in batch files.

A little to impress the naive or people with little knowledge, or just make you start your applications so friendly to make your batch files can include the user name in the introduction, greeting or beginning of the batch file as follows:
@ Echo off echo Welcome% username%, want to continue? 
pause> nul

How to display messages in batch files.

On the previous page showed the basic form of display messages in batch files:
msg * here's the text of the message
but the result is a little dry. 
scripts in VBScript events offer more expressive messages, so it is possible to link two files as follows. Create a batch file to write a script temporarily and then run it , it seems difficult but is easy. Try the following code:
@ Echo offecho MsgBox "Writing a script and then call it." 64, "NorfiPC">% temp% \ mensaje.vbs 
start% temp% \ mensaje.vbs
As you can see has a different style with an icon, title and even sound. Simply insert the text you want displayed on the message and the title will have the upper window. 
scripts created in this manner are stored in the Temp folder where it will cause discomfort and will be deleted when running cleanmgr.exe . 
In the same way before you can generate messages with icons and sounds different using the following lines:
MsgBox "Error message icon", 0, "Error"
MsgBox "Error message icon," 16, "Error"
MsgBox "message icon interrogation," 32, "polling"
MsgBox "message warning icon," 48, "Warning"
MsgBox "information icon message," 64, "Information"
MsgBox "message icon Application", 4096, "Application"

Chaining the batch files with scripts.

By chaining batch-script files in the above manner, we can expand and enrich the possibilities for different actions with batch scripts and have more resources at their disposal. The following examples make use of the method  SendKeys , with which it is possible to send commands to the keyboard just as if we did physically, are just two examples but can do many different things. The first sends the combination  Ctrl + Shift + Escape  starts with what the Task Manager. The second key  F3  thus opens the Windows Search tool. Try them.
@ Echo off ECHO set WshShell = WScript.CreateObject ("WScript.Shell")>% temp% \ tskm.vbs 
miss WshShell.SendKeys "^ + {ESC}" >>% temp% \ tskm.vbs 
start% temp% \ tskm.vbs 
cast set WshShell = WScript.CreateObject ("WScript.Shell")>% temp% \ buscar.vbs 
miss WshShell.SendKeys "{F3}" >>% temp% \ buscar.vbs 
start% temp% \ search. vbs

How to change the icon that shows the batch file.

In Windows by default, the batch file extension. CMD, like the bat extension. BAT, show the same icon of the two wheels. You can use another icon, this requires modifying the registry key which specifies the value. The registry key that contains information about the batch file is as follows:
HKEY_CLASSES_ROOT \ cmdfile \ DefaultIcon
and value, that is the path to the icon used by default is:
% SystemRoot% \ System32 \ imageres.dll, -68
You can use some of the icons used for executables exe only taking two clicks in the default and pasting one of the following routes:
% SystemRoot% \ System32 \ imageres.dll, -15 
% SystemRoot% \ System32 \ imageres.dll, -87
You can change the specified key using the command line, for it uses the following code in a batch file or by entering directly into the console, Start or Run.
REG ADD HKEY_CLASSES_ROOT \ cmdfile \ DefaultIcon / ve / t REG_EXPAND_SZ / d C: \ Windows \ System32 \ imageres.dll, -15 / f
Use the command line to make changes to the Windows registry is dangerous, any mistake in a character can be disastrous, so I advise caution and only carry them out if you have basic knowledge in editing the registry.
After you make the above modification to restart the computer or just restart explorer.exe, so that changes become effective, unless you know how to create a batch file with the following code and run it:
@ ECHO OFF 
taskkill / F / IM explorer.exe 
timeout / nobreak 04 
start explorer.exe
You can also restart your browser otherwise, copy the following code, paste it directly into the Start or Run box and press Enter:
CMD / C taskkill / F / IM explorer.exe & timeout / nobreak 04 & start explorer.exe

Restoring the association of the batch file (cmd) and bat (bat).

Windows uses file extensions to know what kind of information they contain and therefore that it is necessary to run programs, sometimes this association is impaired by various causes and then files are displayed with an unknown file type icon and give two clicks in them opens the dialog box to choose the program need to stop opening.
To restore the association of the batch file cmd file extension, open a command window and paste the following and press Enter: assoc. cmd should return the following:. cmd = cmdfile if not well written: assoc. cmd = cmdfile If this does not resolve the situation using the following REG file and add the key that contains your registration.



Key to restore the CMD file association
Windows Registry Editor Version 5.00 
[HKEY_CLASSES_ROOT \. CMD] 
@ = "cmdfile"
[HKEY_CLASSES_ROOT \. CMD \ PersistentHandler] 
@ = "{bf96-11cd-5e941d80-b579-08002b30bfeb}"
[HKEY_CLASSES_ROOT \ cmdfile] 
@ = "Windows Command




[HKEY_CLASSES_ROOT\cmdfile\DefaultIcon]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,69,00,6d,00,\
61,00,67,00,65,00,72,00,65,00,73,00,2e,00,64,00,6c,00,6c,00,2c,00,2d,00,36,\
00,38,00,00,00
[HKEY_CLASSES_ROOT \ cmdfile \ shell]
[HKEY_CLASSES_ROOT \ cmdfile \ shell \ edit]
[HKEY_CLASSES_ROOT\cmdfile\shell\edit\command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,4e,00,4f,00,\
54,00,45,00,50,00,41,00,44,00,2e,00,45,00,58,00,45,00,20,00,25,00,31,00,00,\
00
[HKEY_CLASSES_ROOT \ cmdfile \ shell \ open] 
"EditFlags" = hex: 00,00,00,00
[HKEY_CLASSES_ROOT \ cmdfile \ shell \ open \ command] 
@ = "\"% 1 \ "% *"
[HKEY_CLASSES_ROOT\cmdfile\shell\print\command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,4e,00,4f,00,\
54,00,45,00,50,00,41,00,44,00,2e,00,45,00,58,00,45,00,20,00,2f,00,70,00,20,\
00,25,00,31,00,00,00
[HKEY_CLASSES_ROOT \ cmdfile \ shell \ runas] 
"HasLUAShield" = ""
[HKEY_CLASSES_ROOT\cmdfile\shell\runas\command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,63,00,6d,00,\
64,00,2e,00,65,00,78,00,65,00,20,00,2f,00,43,00,20,00,22,00,25,00,31,00,22,\
00,20,00,25,00,2a,00,00,00
[HKEY_CLASSES_ROOT\cmdfile\shell\runasuser]
@=”@shell32.dll,-50944″
“Extended”=”"
“SuppressionPolicyEx”=”{F211AA05-D4DF-4370-A2A0-9F19C09756A7}”
[HKEY_CLASSES_ROOT\cmdfile\shell\runasuser\command]
“DelegateExecute”=”{ea72d00e-4960-42fa-ba92-7792a7944c1d}”
[HKEY_CLASSES_ROOT \ cmdfile \ shellex \ ContextMenuHandlers] 
@ = "Compatibility"
[HKEY_CLASSES_ROOT\cmdfile\ShellEx\ContextMenuHandlers\Compatibility]
@=”{1d27f844-3a1f-4410-85ac-14651078412d}”
[HKEY_CLASSES_ROOT \ cmdfile \ ShellEx \ DropHandler] 
@ = "{86C86720-42A0-1069-A2E8-08002B30309D}"
[HKEY_CLASSES_ROOT\cmdfile\ShellEx\PropertySheetHandlers\PifProps]
@=”{86F19A00-42A0-1069-A2E9-08002B30309D}”
[HKEY_CLASSES_ROOT \ cmdfile \ ShellEx \ PropertySheetHandlers \ ShimLayer Property Page] 
@ = "{-2A8E-4F51 513D916F-AEAB-0CBC76FB1AF8}"
[HKEY_CLASSES_ROOT\cmdfile\ShellEx\{8895b1c6-b41f-4c1c-a562-0d564250836f}]
@=”{1531d583-8375-4d3f-b5fb-d23bbd169f22}”
[-HKEY_CURRENT_USER \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ FileExts \. CMD \ UserChoice]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.CMD\OpenWithProgids]
“cmdfile”=hex(0):
To restore the file association bat bat file extension, open a command window, paste the following and press Enter: assoc. bat  should return the following:. bat = batfile if not well written: assoc. bat = batfile  If this does not resolve the situation using the following REG file and add the key that contains your registration.



Key to restore the file association BAT
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT \. BAT] 
@ = "batfile"
[HKEY_CLASSES_ROOT \. BAT \ PersistentHandler] 
@ = "{bf96-11cd-5e941d80-b579-08002b30bfeb}"
[HKEY_CLASSES_ROOT \ batfile] 
@ = "Windows Batch




[HKEY_CLASSES_ROOT\batfile\DefaultIcon]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,69,00,6d,00,\
61,00,67,00,65,00,72,00,65,00,73,00,2e,00,64,00,6c,00,6c,00,2c,00,2d,00,36,\
00,38,00,00,00
[HKEY_CLASSES_ROOT\batfile\shell\edit\command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,4e,00,4f,00,\
54,00,45,00,50,00,41,00,44,00,2e,00,45,00,58,00,45,00,20,00,25,00,31,00,00,\
00
[HKEY_CLASSES_ROOT \ batfile \ shell \ open] 
"EditFlags" = hex: 00,00,00,00
[HKEY_CLASSES_ROOT \ batfile \ shell \ open \ command] 
@ = "\"% 1 \ "% *"
[HKEY_CLASSES_ROOT\batfile\shell\print\command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,4e,00,4f,00,\
54,00,45,00,50,00,41,00,44,00,2e,00,45,00,58,00,45,00,20,00,2f,00,70,00,20,\
00,25,00,31,00,00,00
[HKEY_CLASSES_ROOT \ batfile \ shell \ runas] 
"HasLUAShield" = ""
[HKEY_CLASSES_ROOT\batfile\shell\runas\command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,63,00,6d,00,\
64,00,2e,00,65,00,78,00,65,00,20,00,2f,00,43,00,20,00,22,00,25,00,31,00,22,\
00,20,00,25,00,2a,00,00,00
[HKEY_CLASSES_ROOT\batfile\shell\runasuser]
@=”@shell32.dll,-50944″
“Extended”=”"
“SuppressionPolicyEx”=”{F211AA05-D4DF-4370-A2A0-9F19C09756A7}”
[HKEY_CLASSES_ROOT\batfile\shell\runasuser\command]
“DelegateExecute”=”{ea72d00e-4960-42fa-ba92-7792a7944c1d}”
[HKEY_CLASSES_ROOT \ batfile \ shellex \ ContextMenuHandlers] 
@ = "Compatibility"
[HKEY_CLASSES_ROOT\batfile\ShellEx\ContextMenuHandlers\Compatibility]
@=”{1d27f844-3a1f-4410-85ac-14651078412d}”
[HKEY_CLASSES_ROOT \ batfile \ ShellEx \ DropHandler] 
@ = "{86C86720-42A0-1069-A2E8-08002B30309D}"
[HKEY_CLASSES_ROOT\batfile\ShellEx\PropertySheetHandlers\PifProps]
@=”{86F19A00-42A0-1069-A2E9-08002B30309D}”
[HKEY_CLASSES_ROOT \ batfile \ ShellEx \ PropertySheetHandlers \ ShimLayer Property Page] 
@ = "{-2A8E-4F51 513D916F-AEAB-0CBC76FB1AF8}"
[HKEY_CLASSES_ROOT\batfile\ShellEx\{8895b1c6-b41f-4c1c-a562-0d564250836f}]
@=”{1531d583-8375-4d3f-b5fb-d23bbd169f22}”
[-HKEY_CURRENT_USER \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ FileExts \. BAT \ UserChoice]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.BAT\OpenWithProgids]
“batfile”=hex(0):

How to convert batch files into exe (executable).

When you create your batch files to make your own tasks can become the easily executable, this will in some cases provide advantages and benefits. Some are:
1 - There may be amended using the text editor in the same way that the batch to right click, which will prevent deterioration by accident. 
2 - If the execution of the batch to use auxiliary files such as images, icons, text files etc.. able to group and encapsulate them all in one exe file (executable) created. 
3 - Impedirás display the code used in their creation (not my style). 
4 - You will laugh at those who feel aversion (unjustified) against BAT files .
Can be created in two ways. 
a) Using the tool provided with Windows for that purpose, it is easy to use just follow the wizard. To start box type in the Start or Run: iexpress.exe  and press Enter. 
b) Download the following application  Bat To Exe Converter  on the website of the author at:  http://www.f2ko.de
Both applications include options to add passwords to the file created to run it, an icon of your choice, comments, etc..

How to insert letters with accents in batch files.

In batch files for letters that have accents, and other special characters ñ own Spanish language and display correctly on the console cmd to run the batch, the method requires the use of  alt codes .

Tips, suggestions and examples for creating batch files.


Using Wildcards.

The asterisk sign  *  replaces strings of characters. 
For example, using  DIR *. txt  specific that lists all files in that directory with the extension  . txt . 
The question mark  ?  replaced but only one character. You can specify more question marks. So if you specify  dir s??? *. *  we would list the directories and files with a name beginning with  
s  and other  3  letters any more about any character, then it  *  does that lists files with any extension.

Simple examples to practice:

Examples of information possible to retrieve and display the user using a batch. 
To run it, like the following code, copy it, paste it into a text file and save it with any name but has the file extension. cmd.
@ Echo off 
Color 07 
cast This is an example batch file 
pause 
cls 
echo The Time 
pause> nul 
cls 
date / t 
time / t 
pause> nul 
cls 
Let's change the color cast 
pause> nul 
Color 1E 
cls 
ECHO Who are you 
pause > nul 
cls 
echo% username% 
pause> nul 
miss Your task in execution 
pause> nul 
tasklist 
pause> nul 
cls 
cast your system information 
systeminfo 
pause> nul 
CLS 
directory miss in that these 
pause> nul 
cls 
echo% CD% 
pause> nul 
miss Sounds like you have a virus 
pause> nul 
@ echo
It's just a joke 
pause> nul 
exit
Simple example of interactive use of the SET command.
@ Echo off 
title Name 
set / p name = Enter your name and press Enter. 
set / p name = Enter your first name? 
set / p apellido2 = enter your last name? 
echo. 
echo Your name is% name%% apellido2% name%% 
pause> nul 
exit
Example of a simple mathematical calculation, calculate the average of two numbers.
@ Echo off 
title Do numbers mean of two 
set / p num1 = What is the first number? 
set / p num2 = What is the second number? 
set / mid = (% num1 num2%% +%) / 2 
echo. 
miss The average mean%% 
pause> nul 
exit
Another example of calculating the average, in this case between various numbers.
@ Echo off 
title mean Make two numbers 
: the top 
set / p = cant numbers between those who want to do the mean? 
set / a counter =% qty% 
set total = 0 
if% qty% LSS 2 (goto bad) else (goto question ) 
: wrong 
cast must enter a number greater than or equal to 2 
goto start 
: question 
set / p num =% Type one of the numbers cant% 
set / a total =% total% +% num% 
set / a counter =% counter% -1 
if not% count% == 0 (goto question) 
September / mid =% total% /% qty% 
echo. 
echo The average mean%% 
pause> nul 
exit
Another example of a simple mathematical operation.
@ Echo off 
title Division of two numbers 
set / p a = Enter the numerator 
: denominator 
set / p two = Enter the denominator 
if% two% == 0 (goto nosepuede) else (goto split) 
: nosepuede 
echo The denominator can not be zero. 
goto denominator 
: Divide 
set / three =% a% /% two% 
echo The result of% a% /% two% three% is% 
pause> nul 
exit
Sample loop, ie the infinite repetition, in this case of two lines.
@ Echo off 
title loop example 
0A Color 
: loop 
cast 1001010010010100100101001010010010100100101001010010010100100101001010010010 
0110101101101011011010110101101101011011010110101101101011011010110110101101 miss 
goto loop 
exit

0 comments:

Post a Comment

 
Design by Wordpress Theme | Bloggerized by Free Blogger Templates | coupon codes