Technical Forums (Troubleshooting)

This will provide you easy trouble shooting.

Thursday, October 6, 2011

How to Create System Log Using Batch Script

Several time we need to trace our log to check which types of error and waring exist in our computer system there is a easy way to generate system log.you  don't need any software installation.So copy this script and paste in notepad and give name like log.bat in your Operating System drive (like C: drive or whatever you want).
Script:
  1. @echo off
  2. echo. > l1.txt
  3. echo Log File >> l1.txt
  4. echo. >> l1.txt
  5. echo User : %username%  >> l1.txt
  6. Date />>l1.txt
  7. Time />> l1.txt
  8. echo. >> l1.txt
  9. echo Process Ran by %username% >> l1.txt
  10. echo. >> l1.txt
  11. qprocess  >> l1.txt
  12. echo. >> l1.txt
  13. echo Network Activities  >> l1.txt
  14. netstat ->> l1.txt
  15. exit

And here is another part of this application which is an HTML code to show you log in Browser.just Copy and paste this code in notepad and save as log.html .
Code :
  1. <!-- Author : Mohammad Usman
  2.     Date   : 12/07/2011    -->
  3. <head><title>Log File - Usman</title></head>
  4. <br/>
  5. <center><h1><u> Log File </u></h1>
  6. <i>This Log file is created by <b>Usman</b> for monitoring System Activities!</i>
  7. <br/>
  8. <ul>
  9. <center><a href="c:/l1.txt">Click here to view the Log File</a></center>
  10. </ul>
  11. </body>
  12. </html>

Thanks.

Tuesday, October 4, 2011

IP Messenger (Chat on your local network)

The ‘IP Messenger’ works similar to a LAN chat application there by offering the users to chat
textually within the same network. The hostname of the recipient is good enough to chat with them.

Copy and paste the above program in a notepad file and save it as a batch file, you will be getting 
a pop up windows that exactly looks like below screenshot, when you execute the batch file,In the user field you have to enter the system name of the recipient, and in the message field type 
in the message that you wanna convey to the recipient. You may use multiple chat with various persons at 
the same time.
Copy , paste this code on notepad and save as with bat extension (like chat.bat).
Script:
  1. @echo off
  2. :loop
  3. Title LAN CHAT
  4. color a
  5. Cls
  6. echo                     ########## LAN CHAT ##########
  7. echo.
  8. echo Type in the hostname of the recipient in the User: Field
  9. echo Enter the Message you wanna convey to the recipient in the Message: Field
  10. echo.
  11. set /p n=User:
  12. set /p m=Message:
  13. net send %n% %m%
  14. Pause
  15. Goto loop
Thanks.

How to lock Folder in Windows

If you want locking up your folder with a password, so the user who
knows the right password can only be able to access the folder, where others don’t (Well this is not quite
secure, but can be useful in learning batch programming, because even a noob can easily identify the
password, or can access the folder without using a password, there are a lot of ways to break it).
The batch file that is given below will create a directory named ‘Locker’, when it gets executed,
then you may place whatever you wish to place inside that directory, once done re-execute the same batch
file, then it will prompt you whether to lock the folder,  like this
press ‘y’ and hit enter, then the directory ‘Locker’ Disappears. In order to make the directory re-appear
again, you have to execute the same batch file once again, then it will prompt you to enter the password to
unlock the folder, you have to enter the password as ‘secret’, since it is already mentioned by default in
the program itself.
Once the password is matched, then the folder becomes visible, so that you can access the folder again.
So, what happens is that, the folder ‘Locker’ is set with the system and hidden attribute, hence it becomes
invisible, when the batch program is executed again, it prompt for password, which is already set as an
environment variable with a value ‘secret’, when the match is found, the attribute is set to normal and the
folder becomes visible and accessible.
Here is the snippet for the folder locke.
Copy , paste this code on notepad and save as with bat extension (like lock.bat). 
 
Script:
  1. @echo off
  2. title Folder Locker
  3. if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK
  4. if NOT EXIST Locker goto MDLOCKER
  5. :CONFIRM
  6. echo Are you sure u want to Lock the folder(Y/N)
  7. set/"cho=>"
  8. if %cho%==Y goto LOCK
  9. if %cho%==y goto LOCK
  10. if %cho%==n goto END
  11. if %cho%==N goto END
  12. echo Invalid choice.
  13. goto CONFIRM115
  14. :LOCK
  15. ren Locker "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
  16. attrib ++"Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
  17. echo Folder locked
  18. goto End
  19. :UNLOCK
  20. echo Enter password to Unlock folder
  21. set/"pass=>"
  22. admin
  23. if NOT %pass%== secret goto FAIL
  24. attrib --"Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
  25. ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Locker
  26. echo Folder Unlocked successfully
  27. goto End
  28. :FAIL
  29. echo Invalid password
  30. goto end
  31. :MDLOCKER
  32. md Locker
  33. echo Locker created successfully
  34. goto End
Thanks.

How many files and how much much disk space is used in a directory

How many files and how much much disk space is used in a directory and all its subdirectories. If called with the parameter /d it lists each subdirectory otherwise it just prints the total number of files and bytes. Actual disk space consumed is somewhat higher because of cluster slack. Figure about half of the cluster size times the number of files for overhead. 100 files with a cluster size of 8k wastes about 400K. A floppy with 512 byte clusters uses only 25K extra for the same 100 files.
Copy , paste this code on notepad and save as with bat extension (like space.bat). 
Script:
  1. @echo off
  2. if not '%1=='/goto justhowmuch
  3. dir /a-/s|find "i"|find /"Volume"|more
  4. goto done
  5. :justhowmuch
  6. dir /a-/s|find "file(s)"|sort /r|find /"f"|find "[1]"
  7. echo [1ATotal:
  8. :done
Thanks.

Wednesday, September 28, 2011

Display a printable calendar of the specified year

To display a printable calender of the specified year just copy and save in notepad as clean.bat.
Script :
  1. @ECHO OFF 
  2. :: Windows batch for generating calendars
  3. :: Chances look good for win 2000 and above
  4. IF "%~1"=="/?" (
  5.     ECHO START "%~NX0" WITHOUT ARGUMENTS AND THEN ENTER THE YEAR.
  6.     ECHO "%~NX0" WILL OPEN IN IT'S OWN WINDOW TO AVOID RESIZING
  7.    ECHO AN EXISTING WINDOW.
  8.    ECHO.
  9.    ECHO A SCREEN RESOLUTION AND/OR FONT SIZE THAT CAN DISPLAY
  10.    ECHO CMD WINDOWS OF 96 COLUMNS AND 39 LINES IS REQUIRED.
  11.    ECHO SOME CONFIGURATIONS MAY USE SCROLL BARS TO ACHIEVE
  12.    ECHO THIS.
  13.    EXIT /B
  14. )
  15. :: The current codepage is stored in variable %CodePage%,
  16. :: then changed to 850 to facilitate box drawing characters.....
  17. FOR /F "tokens=*" %%A IN ('CHCP') DO FOR %%B IN (%%~A) DO SET CodePage=%%B
  18. CHCP 850 >NUL 2>&1
  19. :: The title can be used to falicitate custom window
  20. :: positioning via the properties menu of "calendars..."
  21. :: /max is used so as much content as possible is visable
  22. :: without moving the window. /max must be removed for
  23. :: custom window positing.....
  24. IF NOT "%~1 %~2"=="WINDOW SIZE" (
  25.     START "CALENDARS..." /MAX CMD /C "%~F0" WINDOW SIZE
  26.     REM Restore the original codepage before exiting.....
  27.     CHCP %CodePage% >NUL 2>&1
  28.     EXIT /B
  29. )
  30. MODE CON:COLS=96 LINES=39
  31. SETLOCAL ENABLEDELAYEDEXPANSION
  32. :loop
  33. FOR %%Z IN (jan feb mar apr may jun jul aug sep oct nov dec year day leap noleap length test) DO SET %%Z=
  34. SET /P year=Enter a year to see it's calendar, or nothing to exitthen press enter:
  35. IF NOT DEFINED year (
  36.     REM Restore the original codepage before exiting.....
  37.     CHCP %CodePage% >NUL 2>&1
  38.     EXIT /B
  39. )
  40. ::Test that the input is only numbers...
  41. SET test=!year!
  42. FOR /%%IN (0 1 9) DO IF DEFINED test SET "test=!test:%%Z=!"
  43. IF DEFINED test CLS&GOTO loop
  44. :zero
  45. IF NOT DEFINED year (
  46.     :error
  47.     cls
  48.     echo The year entered can not be accepted.
  49.     echo.
  50.     pause
  51.     CLS
  52.     GOTO loop
  53. )
  54. :: remove leading zeros, if any...
  55. IF "%year:~0,1%"=="0" SET year=%year:~1%&&GOTO zero
  56. :: The %processor_architecture% test is used to test
  57. :: limits of caculations, if the variable is undefined
  58. :: or unrecognised the test will fall through and complete
  59. :: anyway, if the limit is surpassed this way the results may
  60. :: not be valid. The tested number is ~80% of the limit of the
  61. :: os so that year + year / 4 yields a valid result.
  62. IF /"!processor_architecture!"=="x86" (
  63.     IF !year! gtr 1717986917 GOTO :error
  64. ) else (
  65.     IF NOT "!processor_architecture:64=!"=="!processor_architecture!" (
  66.         IF !year! gtr 7378697629483820645 GOTO :error
  67.     )
  68. )
  69. :: Generate the first day of the year, 0=sun, 1=mon,...,6=sat
  70. :: A 365 day year ofsets by one day, so the next year will start
  71. :: the next day (i.e. 2009 starts on thr and 2010 starts on fri)
  72. :: an extra day must be added for every leapyear. Using modulo
  73. :: 7 on the total of offset days reviels the starting day of the
  74. :: year. one day must also be removed if the year is a leap year
  75. :: because the below will add one for it, the remainder for non
  76. :: leap years is not an issue because set /a only returns whole
  77. :: numbers.
  78. SET /A day=(year + year / 4) - (year / 100 - year / 400)
  79. SET /A leap=year %% 400
  80. SET /A noleap=year %% 100
  81. IF !leap! GTR 0 (
  82.     IF !noleap! NEQ 0 SET /A leap=year %% 4
  83. )
  84. IF %leap%==0 SET /A day-=1
  85. SET /A day%%=7
  86. :: For each year every month is padded to is starting offset
  87. :: with spaces, january has the original offset generated above.
  88. :: each additional offset is generated by adding the total days of
  89. :: the previous month then processing it by modulo 7.
  90. :: The days are stored in a varianle to display later, these variables
  91. :: are padded to 111 characters using spaces for display purposes.
  92. FOR %%IN (jan feb mar apr may jun jul aug sep oct nov dec) DO (
  93.     FOR %%IN (jan mar may jul aug oct dec) DO IF /%%U==%%V SET length=31
  94.     FOR %%IN (apr jun sep nov) DO IF /%%U==%%W SET length=30
  95.     IF /%%U==feb (
  96.         IF !leap!==0 (
  97.             SET length=29
  98.         ) else (
  99.             SET length=28
  100.         )
  101.     )
  102.     FOR /%%IN (1 1 !day!) DO SET "%%U=!%%U!   "
  103.     FOR /%%IN (1 1 !length!) DO (
  104.         IF %%Y lss 10 (
  105.             SET "%%U=!%%U!%%Y  "
  106.         ) else (
  107.             SET "%%U=!%%U!%%Y "
  108.         )
  109.     )
  110.     FOR /%%IN (!length! 1 54) DO IF "!%%U:~110!"=="" SET "%%U=!%%U! "
  111.     SET /A day=^(day + length^) %% 7
  112. )
  113. :test
  114. :: The results are displayed below using substrings of each month's
  115. variable.
  116. cls
  117. TITLE THE CALENDAR FOR THE YEAR OF %YEAR%
  118. echo. ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
  119. echo. º      JANUARY       º  º      FEBUARY       º  º       MARCH        º  º       APRIL        º
  120. echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
  121. echo. ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º
  122. echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
  123. echo. º%JAN:~0,20%º  º%FEB:~0,20%º  º%MAR:~0,20%º  º%APR:~0,20%º
  124. echo. º%JAN:~21,20%º  º%FEB:~21,20%º  º%MAR:~21,20%º  º%APR:~21,20%º
  125. echo. º%JAN:~42,20%º  º%FEB:~42,20%º  º%MAR:~42,20%º  º%APR:~42,20%º
  126. echo. º%JAN:~63,20%º  º%FEB:~63,20%º  º%MAR:~63,20%º  º%APR:~63,20%º
  127. echo. º%JAN:~84,20%º  º%FEB:~84,20%º  º%MAR:~84,20%º  º%APR:~84,20%º
  128. echo. º%JAN:~105%              º  º%FEB:~105%              º  º%MAR:~105%              º  º%APR:~105%              º
  129. echo. ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
  130. echo.
  131. echo. ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
  132. echo. º        MAY         º  º        JUNE        º  º        JULY        º  º       AUGUST       º
  133. echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
  134. echo. ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º
  135. echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
  136. echo. º%MAY:~0,20%º  º%JUN:~0,20%º  º%JUL:~0,20%º  º%AUG:~0,20%º
  137. echo. º%MAY:~21,20%º  º%JUN:~21,20%º  º%JUL:~21,20%º  º%AUG:~21,20%º
  138. echo. º%MAY:~42,20%º  º%JUN:~42,20%º  º%JUL:~42,20%º  º%AUG:~42,20%º
  139. echo. º%MAY:~63,20%º  º%JUN:~63,20%º  º%JUL:~63,20%º  º%AUG:~63,20%º
  140. echo. º%MAY:~84,20%º  º%JUN:~84,20%º  º%JUL:~84,20%º  º%AUG:~84,20%º
  141. echo. º%MAY:~105%              º  º%JUN:~105%              º  º%JUL:~105%              º  º%AUG:~105%              º
  142. echo. ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
  143. echo.
  144. echo. ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
  145. echo. º     SEPTEMBER      º  º      OCTOBER       º  º      NOVEMBER      º  º      DECEMBER      º
  146. echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
  147. echo. ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º
  148. echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
  149. echo. º%SEP:~0,20%º  º%OCT:~0,20%º  º%NOV:~0,20%º  º%DEC:~0,20%º
  150. echo. º%SEP:~21,20%º  º%OCT:~21,20%º  º%NOV:~21,20%º  º%DEC:~21,20%º
  151. echo. º%SEP:~42,20%º  º%OCT:~42,20%º  º%NOV:~42,20%º  º%DEC:~42,20%º
  152. echo. º%SEP:~63,20%º  º%OCT:~63,20%º  º%NOV:~63,20%º  º%DEC:~63,20%º
  153. echo. º%SEP:~84,20%º  º%OCT:~84,20%º  º%NOV:~84,20%º  º%DEC:~84,20%º
  154. echo. º%SEP:~105%              º  º%OCT:~105%              º  º%NOV:~105%              º  º%DEC:~105%              º
  155. echo. ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
  156. GOTO loop

Thanks.