Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Change Batch script to Vbs or run more faster.

Hi,

Change Batch script to Vbs or run more faster.
Any way the same script can be changed to run any faster or to convert to Vbs.
Vbs or the same script can it run multiple machines at the same time. Like take first 5 machine names and run at the same time.

REgards
Sharath
:: BATCH SCRIPT START 
@ECHO OFF
SETLOCAL EnableDelayedExpansion
SET NetShare=\\ophos\ps
SET InputFile=Machines.txt
IF NOT EXIST "%NetShare%" ECHO Network share not found. &GOTO :EndScript
IF NOT EXIST "%InputFile%" ECHO "%InputFile%" file does not exist. &GOTO :EndScript
FOR %%R IN ("%InputFile%") DO IF %%~zR EQU 0 ECHO "%InputFile%" file is empty. &GOTO :EndScript
FOR /F %%c IN ('TYPE "%InputFile%"') DO (
        ECHO Processing: %%c
        IF EXIST "!NetShare!\%%c.txt" DEL /F /Q "!NetShare!\%%c.txt"
        FOR /F "delims=: tokens=1" %%d IN ('WMIC /NODE:"%%c" LOGICALDISK WHERE "DriveType=3" GET Name ^|FIND ":"') DO (
                DIR \\%%c\%%d$\*.mp3 /S /B 2>NUL >>"!NetShare!\%%c.txt"
                DIR \\%%c\%%d$\*.avi /S /B 2>NUL >>"!NetShare!\%%c.txt"
                DIR \\%%c\%%d$\*.mpg /S /B 2>NUL >>"!NetShare!\%%c.txt")
        )
 
:EndScript
ENDLOCAL
EXIT /B 0
:: BATCH SCRIPT END

Open in new window

can you explain what this script do ?

please detail every thing
Avatar of bsharath

ASKER

When script run goes to each machine $ drives whose names are in a  txt file and checks (Searches) for all  drives in the machines for the 3 or 4 extensions that i want and creates txt files with the machine names and saves the paths the files were found in the txt files.

Basically its a script that scans all machines for specific extensions and lists the paths in individual files

Do let me know if you need more details.
When script run goes to each machine $ drives whose names are in a  txt file and checks (Searches) for all  drives in the machines for the 3 or 4 extensions that i want and creates txt files with the machine names and saves the paths the files were found in the txt files.

Basically its a script that scans all machines for specific extensions and lists the paths in individual files

Do let me know if you need more details.
Avatar of AmazingTech
AmazingTech

Give this a try. I haven't tried it yet.

This line sets the number of workstations it will do at one time.
SET AllowNumberOfConcurrentWorkstations=5

Put both batch files in 1 directory accessing it with a drive letter not from a server share.
The attached code is the main code.

Save this code as your secondbatch.bat

SET NetShare=\\ophos\ps
ECHO Processing: %1
TITLE Processing %1 %date% at %time%
ECHO Started %date% at %time%>"%NetShare%\THROTTLE\%1.txt"
FOR /F "delims=: tokens=1" %%d IN ('WMIC /NODE:"%1" LOGICALDISK WHERE "DriveType=3" GET Name ^|FIND ":"') DO (
    DIR \\%1\%%d$\*.mp3 \\%1\%%d$\*.avi \\%1\%%d$\*.mpg /S /B 2>NUL >>"%NetShare%\THROTTLE\%1.txt"
)

MOVE "%NetShare%\THROTTLE\%1.txt" "%NetShare%"
:: BATCH SCRIPT START 
@ECHO OFF
SETLOCAL EnableDelayedExpansion
SET AllowNumberOfConcurrentWorkstations=5
SET NetShare=\\ophos\ps
SET InputFile=Machines.txt
IF NOT EXIST "%NetShare%" ECHO Network share not found. &GOTO :EndScript
IF NOT EXIST "%InputFile%" ECHO "%InputFile%" file does not exist. &GOTO :EndScript
FOR %%R IN ("%InputFile%") DO IF %%~zR EQU 0 ECHO "%InputFile%" file is empty. &GOTO :EndScript
 
FOR /F %%c IN ('TYPE "%InputFile%"') DO CALL :THROTTLE %%c
 
:THROTTLE 
    for /f %%a in ('DIR "%NetShare%\THROTTLE" ^| FIND /i "File(s)"') do IF %%a LSS %AllowNumberOfConcurrentWorkstations% GOTO :GETINFO
    PING -n 10 127.0.0.1
    GOTO THROTTLE
 
:GETINFO
    START SECONDBATCH.BAT %1
 
:EndScript
ENDLOCAL
EXIT /B 0
:: BATCH SCRIPT END

Open in new window

I get this


File Not Found

Pinging 127.0.0.1 with 32 bytes of data:

Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Can both the bat files be of any name?
I have these files in a folder with the machines.txt in it
I get this


File Not Found

Pinging 127.0.0.1 with 32 bytes of data:

Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Can both the bat files be of any name?
I have these files in a folder with the machines.txt in it
I think i need to run the 2nd file. I get this


C:\Ps>"Mp3 2nd file.bat"

C:\Ps>SET NetShare=\\sophos\ps

C:\Ps>ECHO Processing:
Processing:

C:\Ps>TITLE Processing  Tue 01/06/2009 at 21:48:03.03

C:\Ps>ECHO Started Tue 01/06/2009 at 21:48:03.03 1>"\\sophos\ps\THROTTLE\.t
xt"
The system cannot find the path specified.

C:\Ps>FOR /F "delims=: tokens=1" %d IN ('WMIC /NODE:"" LOGICALDISK WHERE "DriveT
ype=3" GET Name |FIND ":"') DO (DIR \\\%d$\*.mp3 \\\%d$\*.avi \\\%d$\*.mpg /S /B
  2>NUL 1>>"\\sophos\ps\THROTTLE\.txt" )

C:\Ps>(DIR \\\C$\*.mp3 \\\C$\*.avi \\\C$\*.mpg /S /B  2>NUL 1>>"\\sophos\ps
\THROTTLE\.txt" )
The system cannot find the path specified.

C:\Ps>(DIR \\\D$\*.mp3 \\\D$\*.avi \\\D$\*.mpg /S /B  2>NUL 1>>"\\sophos\ps
\THROTTLE\.txt" )
The system cannot find the path specified.

C:\Ps>MOVE "\\sophos\ps\THROTTLE\.txt" "\\sophos\ps"
The system cannot find the file specified.

I think i need to run the 2nd file. I get this


C:\Ps>"Mp3 2nd file.bat"

C:\Ps>SET NetShare=\\sophos\ps

C:\Ps>ECHO Processing:
Processing:

C:\Ps>TITLE Processing  Tue 01/06/2009 at 21:48:03.03

C:\Ps>ECHO Started Tue 01/06/2009 at 21:48:03.03 1>"\\sophos\ps\THROTTLE\.t
xt"
The system cannot find the path specified.

C:\Ps>FOR /F "delims=: tokens=1" %d IN ('WMIC /NODE:"" LOGICALDISK WHERE "DriveT
ype=3" GET Name |FIND ":"') DO (DIR \\\%d$\*.mp3 \\\%d$\*.avi \\\%d$\*.mpg /S /B
  2>NUL 1>>"\\sophos\ps\THROTTLE\.txt" )

C:\Ps>(DIR \\\C$\*.mp3 \\\C$\*.avi \\\C$\*.mpg /S /B  2>NUL 1>>"\\sophos\ps
\THROTTLE\.txt" )
The system cannot find the path specified.

C:\Ps>(DIR \\\D$\*.mp3 \\\D$\*.avi \\\D$\*.mpg /S /B  2>NUL 1>>"\\sophos\ps
\THROTTLE\.txt" )
The system cannot find the path specified.

C:\Ps>MOVE "\\sophos\ps\THROTTLE\.txt" "\\sophos\ps"
The system cannot find the file specified.

You've named your second file "MP3 2nd file.bat" so we need to update the first file to start this name.
:: BATCH SCRIPT START 
@ECHO OFF
SETLOCAL EnableDelayedExpansion
SET AllowNumberOfConcurrentWorkstations=5
SET NetShare=\\ophos\ps
SET InputFile=Machines.txt
IF NOT EXIST "%NetShare%" ECHO Network share not found. &GOTO :EndScript
IF NOT EXIST "%InputFile%" ECHO "%InputFile%" file does not exist. &GOTO :EndScript
FOR %%R IN ("%InputFile%") DO IF %%~zR EQU 0 ECHO "%InputFile%" file is empty. &GOTO :EndScript
 
FOR /F %%c IN ('TYPE "%InputFile%"') DO CALL :THROTTLE %%c
 
:THROTTLE 
    for /f %%a in ('DIR "%NetShare%\THROTTLE" ^| FIND /i "File(s)"') do IF %%a LSS %AllowNumberOfConcurrentWorkstations% GOTO :GETINFO
    PING -n 10 127.0.0.1
    GOTO THROTTLE
 
:GETINFO
    START "%1" "MP3 2nd file.BAT" %1
 
:EndScript
ENDLOCAL
EXIT /B 0
:: BATCH SCRIPT END

Open in new window

I get this

Microsoft Windows [Version 5.2.3790]
(C) Copyright 1985-2003 Microsoft Corp.

C:\Documents and Settings\Administrator.DEVELOPMENT>cd\

C:\>cd ps

C:\Ps>"Mp3 2nd file.bat"

C:\Ps>SET NetShare=\\sophos\ps

C:\Ps>ECHO Processing:
Processing:

C:\Ps>TITLE Processing  Wed 01/07/2009 at 14:04:23.21

C:\Ps>ECHO Started Wed 01/07/2009 at 14:04:23.21 1>"\\sophos\ps\THROTTLE\.t
xt"
The system cannot find the path specified.

C:\Ps>FOR /F "delims=: tokens=1" %d IN ('WMIC /NODE:"" LOGICALDISK WHERE "DriveT
ype=3" GET Name |FIND ":"') DO (DIR \\\%d$\*.mp3 \\\%d$\*.avi \\\%d$\*.mpg /S /B
  2>NUL 1>>"\\sophos\ps\THROTTLE\.txt" )

C:\Ps>(DIR \\\C$\*.mp3 \\\C$\*.avi \\\C$\*.mpg /S /B  2>NUL 1>>"\\sophos\ps
\THROTTLE\.txt" )
The system cannot find the path specified.

C:\Ps>(DIR \\\D$\*.mp3 \\\D$\*.avi \\\D$\*.mpg /S /B  2>NUL 1>>"\\sophos\ps
\THROTTLE\.txt" )
The system cannot find the path specified.

C:\Ps>MOVE "\\sophos\ps\THROTTLE\.txt" "\\sophos\ps"
The system cannot find the file specified.

I get this

Microsoft Windows [Version 5.2.3790]
(C) Copyright 1985-2003 Microsoft Corp.

C:\Documents and Settings\Administrator.DEVELOPMENT>cd\

C:\>cd ps

C:\Ps>"Mp3 2nd file.bat"

C:\Ps>SET NetShare=\\sophos\ps

C:\Ps>ECHO Processing:
Processing:

C:\Ps>TITLE Processing  Wed 01/07/2009 at 14:04:23.21

C:\Ps>ECHO Started Wed 01/07/2009 at 14:04:23.21 1>"\\sophos\ps\THROTTLE\.t
xt"
The system cannot find the path specified.

C:\Ps>FOR /F "delims=: tokens=1" %d IN ('WMIC /NODE:"" LOGICALDISK WHERE "DriveT
ype=3" GET Name |FIND ":"') DO (DIR \\\%d$\*.mp3 \\\%d$\*.avi \\\%d$\*.mpg /S /B
  2>NUL 1>>"\\sophos\ps\THROTTLE\.txt" )

C:\Ps>(DIR \\\C$\*.mp3 \\\C$\*.avi \\\C$\*.mpg /S /B  2>NUL 1>>"\\sophos\ps
\THROTTLE\.txt" )
The system cannot find the path specified.

C:\Ps>(DIR \\\D$\*.mp3 \\\D$\*.avi \\\D$\*.mpg /S /B  2>NUL 1>>"\\sophos\ps
\THROTTLE\.txt" )
The system cannot find the path specified.

C:\Ps>MOVE "\\sophos\ps\THROTTLE\.txt" "\\sophos\ps"
The system cannot find the file specified.

ASKER CERTIFIED SOLUTION
Avatar of AmazingTech
AmazingTech

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I really dont know how i missed the mail Sorry for the delay...

Now which should i run i changed the 1st code and ran it just pings and the 2nd file comes out saying file not found....
I really dont know how i missed the mail Sorry for the delay...

Now which should i run i changed the 1st code and ran it just pings and the 2nd file comes out saying file not found....
Hi AT any views...