Computer Hope
Microsoft => Microsoft DOS => Topic started by: silberzin on July 19, 2010, 01:44:07 AM
-
Hi All
can anybody help.
I have script:
echo Y|net use p: /delete
START /wait NET USE p: \\server1\MDPRD\distributions\Inbound\70\70_Customer_flat\Archive
call e:\batchfile.bat
echo Y|net use p: /delete
echo Y|net use p: /delete
START /wait NET USE p: \\server1\MDPRD\distributions\P31\BW__RACUGRP\Archive
call e:\batchfile.bat
echo Y|net use p: /delete
START /wait NET USE p: \\server1\MDPRD\distributions\Archive
call e:\batchfile.bat
echo Y|net use p: /delete
however after calling e:\batchfile.bat
echo Y|net use p: /delete
do not work
can anobydy advice how to solve that error?
E:\>echo Y | net use y: /delete
y: was deleted successfully.
E:\>START /wait NET USE y: \\server1\MDPRD\distributions\Inbound\70\70_Customer_flat\Archive
E:\>call e:\batchfile.bat
The device is being accessed by an active process. <---- here net use delete is failing
More help is available by typing NET HELPMSG 2404.
Press any key to continue . .
Please advice
Thank you very much.
BR
Michal
-
however after calling e:\batchfile.bat
echo Y|net use p: /delete
do not work
It would help if you posted the contents of batchfile.bat. It appears some process has an open handle to the P drive.
Any reason why you are using start with the net use command? There is no reason to run it in a separate window and running it inline produces the same result as the /wait switch would.
8)
-
hi Sidewinder
Thank you for replay, here is full batchfile.bat:
@echo off
CD /d p:\
REM grab todays date into variables
set MM=%Date:~3,2%
set DD=%Date:~0,2%
set YYYY=%Date:~6,4%
REM Add the date variables to the log name
REM putting the date in this order will sort the files sensibly
Set LogFile="e:\NewFiles_%YYYY%-%MM%-%DD%.Log"
REM create the vb script
>c:\evaluate.vbs echo Wscript.echo eval(WScript.Arguments(0))
REM extract todays date less 7 days
set OldestDate=
for /f "delims=" %%A in ( ' cscript //nologo c:\evaluate.vbs "Date -7" ' ) do set OldestDate=%%A
REM tidy
del c:\evaluate.vbs
REM break up the date into constituent parts
REM Note - the date is parsing YYYY-MM-DD format dates,
set MM=
set DD=
set YYYY=
set MM=%OldestDate:~5,2%
set DD=%OldestDate:~8,2%
set YYYY=%OldestDate:~0,4%
REM reconstruct US format with '-' separators
set OldestDate=%MM%-%DD%-%YYYY%
REM add the new entry to the log
>> %LogFile% Echo %DATE% %TIME%
>> %LogFile% Echo Since : %OldestDate%
net use p:|find "Remote name">> %LogFile%
REM list the files that would be copied if we really were doing a copy
REM force it to believe that the target NonExistentDirectory is a directory
REM and echo the name & time for each
for /f "delims=" %%A in ( ' xcopy /l /i /d:%OldestDate% *.* NonExistentDirectory ' ) do call :ProcessEach "%%A"
REM tidy up the log
>> %LogFile% Echo ========================================
goto :EOF
:ProcessEach
>> %LogFile% echo %~f1 %~t1
goto :EOF
Thank you for help :)
BR
Michal
-
The second line in batchfile.bat logs you on to the P drive. There is no other CD instruction in the file (that I could find), so when batchfile.bat ends, you are still logged into the P drive.
Batchfile.bat needs to be changed to log off the P drive before the calling file attempts to delete the mapping (net use p: /delete)
8)
-
Michal
I knew it would be something easy !
Sorry I couldnt finish this off without Sidewinder's help (cheers SW)
Graham
Try this
@echo off
CD /d p:\
REM grab todays date into variables
set MM=%Date:~3,2%
set DD=%Date:~0,2%
set YYYY=%Date:~6,4%
REM Add the date variables to the log name
REM putting the date in this order will sort the files sensibly
Set LogFile="e:\NewFiles_%YYYY%-%MM%-%DD%.Log"
REM create the vb script
>c:\evaluate.vbs echo Wscript.echo eval(WScript.Arguments(0))
REM extract todays date less 7 days
set OldestDate=
for /f "delims=" %%A in ( ' cscript //nologo c:\evaluate.vbs "Date -7" ' ) do set OldestDate=%%A
REM tidy
del c:\evaluate.vbs
REM break up the date into constituent parts
REM Note - the date is parsing YYYY-MM-DD format dates,
set MM=
set DD=
set YYYY=
set MM=%OldestDate:~5,2%
set DD=%OldestDate:~8,2%
set YYYY=%OldestDate:~0,4%
REM reconstruct US format with '-' separators
set OldestDate=%MM%-%DD%-%YYYY%
REM add the new entry to the log
>> %LogFile% Echo %DATE% %TIME%
>> %LogFile% Echo Since : %OldestDate%
net use p:|find "Remote name">> %LogFile%
REM list the files that would be copied if we really were doing a copy
REM force it to believe that the target NonExistentDirectory is a directory
REM and echo the name & time for each
for /f "delims=" %%A in ( ' xcopy /l /i /d:%OldestDate% *.* NonExistentDirectory ' ) do call :ProcessEach "%%A"
REM tidy up the log
>> %LogFile% Echo ========================================
REM ----------------------------
REM Release mapped drive
REM ----------------------------
E:
goto :EOF
:ProcessEach
>> %LogFile% echo %~f1 %~t1
goto :EOF
-
Hi :)
Now it looks to work with deleting p: drive when script is finished
It seems to be working as expected :)
Thank you very very very much :)
BR
Michal
-
Hi
I encouriage strange problem. Mentioned above script works fine on one computer, but on all others is failing.
I have that error message:
C:\MDM_Monitoring>echo Y | net use p: /delete
p: was deleted successfully.
C:\MDM_Monitoring>START /wait NET USE p: \\server1\P_Customer\Inbound\70\70_Customer_flat\Archive
C:\MDM_Monitoring>call e:\bathfile.bat
The system cannot find the drive specified.
The device is being accessed by an active process.
More help is available by typing NET HELPMSG 2404.
Press any key to continue . . .
Can you please help, I have no clue why that error occour. Special that it works on once computer only. On all other computers I have mentioned above error.
Thank you in advance.
BR
Michal
-
REM ----------------------------
REM Release mapped drive
REM ----------------------------
E:
I see remarks for deleting the mapped drive but no actual instructions. It may be time to rethink your design. Batchfile should contain all the instructions it needs to run whether from the command line or as a called file. By this I mean batchfile should map the drive, access the drive and release the drive; it should not rely on some caller batch file to supply these instructions.
Be aware that in a caller/calling sequence, that if any module fails to complete properly, your session status may be corrupt.
Why are you using start /wait with the net use command? Why are you piping Y to the net use command?
Special that it works on once computer only. On all other computers I have mentioned above error.
Let us know. 8)
Are all the computers running the same OS. Are they on the same network?
-
Hi All
Sorry I messed up, all works fine.
note. Always connect to disks mapped to your computer :)
BR
Silberzin