Showing posts with label Batch Processing. Show all posts
Showing posts with label Batch Processing. Show all posts

Thursday, August 9, 2018

Get inactive RDP connections logged off

@echo off
color 0a
title Logging off Disconnected RDP(s) . . . . .
cls

::Disconnected user logoff
for /f "tokens=2 delims= " %%a in ('query user ^| findstr Disc') do for %%b in (%%a) do (echo %~n0 script is logging off session id - %%a logoff %%a)

::Active user logoff
for /f "tokens=3 delims= " %%a in ('query user ^| findstr Active') do for %%b in (%%a) do (echo %~f0  is logging off session id - %%a logoff %%a)

title Logging off RDP(s) Complete . . . . .
exit

*Note - You must have administrator privileges.

Tuesday, May 30, 2017

How do you delete temporary files and folders?

@ECHO OFF
COLOR 0A
DEL /A /F /Q /S "%temp%\*.*"
FOR /D %%p IN ("%temp%\*.*") DO RD "%%p" /S /Q
DEL /A /F /Q /S "C:\Windows\Temp\*.*"
FOR /D %%p IN ("C:\Windows\Temp\*.*") DO RD "%%p" /S /Q
DEL /A /F /Q /S "C:\Windows\Prefetch\*.*"
FOR /D %%p IN ("C:\Windows\Prefetch\*.*") DO RD "%%p" /S /Q
FOR /D %%p IN ("C:\Windows\SoftwareDistribution\Download\*.*") DO RD "%%p" /S /Q

Monday, June 27, 2016

How do you create a jar file on Windows CLI?

1. Start Command Prompt.
2. Navigate to the folder that holds your class files:
   C:\>cd \mywork

3. Set path to include JDK’s bin.  For example:
   C:\mywork> path c:\Program Files\Java\jdk1.7.0_25\bin;%path%

4. Compile your class(es):
   C:\mywork> javac *.java

5. Create a manifest file and your jar file:
   C:\mywork> echo Main-Class: Craps >manifest.txt
   C:\mywork> jar cvfm Craps.jar manifest.txt *.class
  
   or
  
   C:\mywork> jar cvfe Craps.jar Craps *.class

6. Test your jar:
   C:\mywork> Craps.jar

   or

   C:\mywork> java -jar Craps.jar

Wednesday, June 8, 2016

How do you find out files with size more than 1GB in command prompt?

:: 1 GB = 1073741824 KB

forfiles /P E:\Movies\Hollywood\ /M *.* /S /C "cmd /c if @fsize gtr 1073741824 echo @path @fsize @fdate @ftime"

Monday, October 19, 2015

How do you run PostgreSQL query on Command Prompt?

@echo off
set REPORTNAME=%1
set timestamp=%date:~-4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%
set PGPASSWORD=<password>
"C:\Program Files (x86)\pgAdmin III\1.16\psql" -A -h %REPORTNAME% -U <UserName> -d <DatabaseName> -F , --pset footer -c "<Query>" -o "%REPORTNAME%_%timestamp%.csv"

Friday, September 11, 2015

How do you create a God Mode folder on Windows?

"God Mode" is a hidden feature of Windows that gives you access to every option in Control Panel on one screen. This is useful, especially for power users, since navigating the traditional Control Panel is tedious. The added advantage of this option can be further exploited to hide data in disguise.

Follow these steps to access God Mode on Windows 7/ 8/10 :

1. Create a new folder or use any existing folder wherever you want the would-be GodMode folder. Right-click in Windows Explorer, select New, then click Folder.

2. Open Command Prompt and traverse directory using CD command.

3. Next, rename the folder by executing the command below :

ren <Folder Name> <Folder Name>.{ED7BA470-8E54-465E-825C-99712043E01C}

e.g., ren robie robie.{ED7BA470-8E54-465E-825C-99712043E01C}

For Windows 9x :
  • Follow steps 1 & 2.
  • Next execute command
          ren <Folder Name> <Folder Name>.{21EC2020-3AEA-1069-A2DD-08002B30309D}

To restore the orginal folder, run the command below :
         ren <Folder Name>.{21EC2020-3AEA-1069-A2DD-08002B30309D} <Folder Name>

Tuesday, November 4, 2014

How do we find list of directories in a folder in batch file?

@echo off
set basedir=C:\work\perl

set PWD=%cd%
set today=%date:~-4%-%date:~4,2%-%date:~7,2%
if not exist %PWD%\%today% ( mkdir %PWD%\%today% )
dir /s /b /a:d %basedir% > %PWD%\%today%\%today%.ini

Monday, October 13, 2014

Create predefined folder & sub-folders on Windows.

@echo off

set PWD=%cd%
set dlist=CLASS01 CLASS02 CLASS03
set slist=PHY CHE BIO GEO MATH

for %%i in ( %dlist% ) do (
   if not exist %PWD%\%%i ( mkdir %PWD%\%%i )
   for %%j in ( %slist% ) do (
       if not exist %PWD%\%%i\%%j ( mkdir %PWD%\%%i\%%j )
   )
)

Rename multi files in a folder on Windows.

@echo off

set count=1
set basedir=C:\old_data\report
for /f "tokens=*" %%G in ('dir /a-d /b %basedir%') do (call :subroutine %%G)
goto :eof

:subroutine
for /F "delims=_" %%a in ("%1") do (
   ren "%basedir%\%1" "%%a_SPRW_Light_%count%.txt"
)
set /a count+=1
goto :eof

Example:
"20141013_Test_Rept.dat" will be renamed to "20141013_SPRW_Light_1.txt"

Thursday, September 18, 2014

How do you get timestamp in batch file?

@echo off
set timestamp=%date:~-4%-%date:~4,2%-%date:~7,2%:%time:~0,2%-%time:~3,2%-%time:~6,2%
echo %timestamp%

Wednesday, August 20, 2014

How do you add path of perl to environment variable on command prompt?

1. Open "cmd.exe" with Administrator Privilege (on right click on app) and type the command below.
     setx path "%path%;C:\Perl64\bin;"
2. Restart "cmd.exe".

Monday, July 7, 2014

Move N number of files from one directory to other.

@echo off

set Source=C:\PerlDrift_Bat\IN
set Target=C:\Perl\Drift_Bat\OUT

set MaxLimit=20

for /f "tokens=1* delims=[]" %%G in ('dir /A-D /B "%Source%\*.*" ^| find /v /n ""') do (
move /y "%Source%\%%~nxH" "%Target%"
if %%G==%MaxLimit% exit /b 0
)

Friday, April 18, 2014

How do you create a log file with name that of batch script?

@echo off
set me=%~n0
set list=Error Log Admin
for %%i in ( %list% ) do (
   if not exist %%i ( mkdir %%i 2>%me%_error.log )
)

Thursday, April 17, 2014

Saturday, March 29, 2014

How do you connect to remote desktop automatically via batch file?

@echo off
set domain=<DOMAIN NAME>
set password=<PASSWORD>
set server=<SERVER NAME or IP>
set user=<USER NAME>
cmdkey /generic:TERMSRV/%server% /user:%domain%\%user% /pass:%password%
start mstsc /v:%server% /f
exit /b

Thursday, September 13, 2012

Write a batch file to kill frozen programs.

@echo off
taskkill /f /fistatus eq not responding
exit

- Copy the above 3 lines to Notepad and save the file as "killall.bat".
- On click, it kills all the programs that do not respond.

Monday, April 23, 2012

How do you schedule to shutdown computer after some mins (VISTA OS)?

@ECHO OFF
TITLE AUTO SHUTDOWN TIMER BY RABINDRA
SET /p min=Enter the number of mins :
SET /a sec=%min% * 60
TIMEOUT /T %sec% /NOBREAK >NUL
SHUTDOWN /s /t 0 /f