

InterviewSolution
Saved Bookmarks
1. |
Solve : net use /delete in script - do not work? |
Answer» <html><body><p>Hi All<br/><br/>can anybody help.<br/><br/>I have <a href="https://interviewquestions.tuteehub.com/tag/script-345000" style="font-weight:bold;" target="_blank" title="Click to know more about SCRIPT">SCRIPT</a>:<br/> Code: <a>[Select]</a>echo Y|net use p: /delete<br/><br/>START /wait NET USE p: \\server1\MDPRD\distributions\Inbound\70\70_Customer_flat\Archive<br/>call e:\batchfile.bat<br/>echo Y|net use p: /delete<br/><br/>echo Y|net use p: /delete<br/>START /wait NET USE p: \\server1\MDPRD\distributions\P31\BW__RACUGRP\Archive<br/>call e:\batchfile.bat<br/>echo Y|net use p: /delete<br/><br/>START /wait NET USE p: \\server1\MDPRD\distributions\Archive<br/>call e:\batchfile.bat<br/>echo Y|net use p: /delete<br/>however after calling e:\batchfile.bat <br/>echo Y|net use p: /delete<br/>do not work<br/><br/>can anobydy advice how to solve that error?<br/><br/> Code: <a>[Select]</a>E:\>echo Y | net use y: /delete<br/>y: was deleted successfully.<br/><br/>E:\>START /wait NET USE y: \\server1\MDPRD\distributions\Inbound\70\70_Customer_flat\Archive<br/><br/><br/>E:\>call e:\batchfile.bat<br/>The device is being accessed by an active process. <---- here net use delete is failing<br/><br/>More help is available by typing NET HELPMSG 2404. <br/><br/>Press any key to continue . . <br/>Please advice <br/><br/>Thank you very much.<br/><br/>BR<br/>Michal Quote</p><blockquote>however after calling e:\batchfile.bat<br/>echo Y|net use p: /delete<br/>do not work<br/></blockquote> <br/>It would help if you posted the contents of batchfile.bat. It appears some process has an open handle to the P drive.<br/><br/>Any reason why you are using <em>start</em> with the <strong>net use</strong> 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.<br/><br/> hi Sidewinder<br/><br/>Thank you for replay, here is full batchfile.bat:<br/><br/><br/> Code: <a>[Select]</a>echo off<br/>CD /d p:\<br/><br/>REM grab todays date into variables<br/>set MM=%Date:~3,2%<br/>set DD=%Date:~0,2%<br/>set YYYY=%Date:~6,4%<br/><br/>REM Add the date variables to the log name<br/>REM putting the date in this <a href="https://interviewquestions.tuteehub.com/tag/order-238912" style="font-weight:bold;" target="_blank" title="Click to know more about ORDER">ORDER</a> will sort the files sensibly<br/>Set LogFile="e:\NewFiles_%YYYY%-%MM%-%DD%.Log"<br/><br/>REM create the vb script<br/>>c:\evaluate.vbs echo Wscript.echo eval(WScript.Arguments(0))<br/><br/>REM extract todays date less 7 days<br/>set OldestDate=<br/>for /f "delims=" %%A in ( ' cscript //nologo c:\evaluate.vbs "Date -7" ' ) do set OldestDate=%%A<br/><br/>REM tidy<br/>del c:\evaluate.vbs<br/><br/>REM break up the date into constituent parts<br/>REM Note - the date is parsing YYYY-MM-DD format dates,<br/><br/>set MM=<br/>set DD=<br/>set YYYY=<br/><br/>set MM=%OldestDate:~5,2%<br/>set DD=%OldestDate:~8,2%<br/>set YYYY=%OldestDate:~0,4%<br/><br/>REM reconstruct <a href="https://interviewquestions.tuteehub.com/tag/us-243201" style="font-weight:bold;" target="_blank" title="Click to know more about US">US</a> format with '-' separators<br/>set OldestDate=%MM%-%DD%-%YYYY%<br/><br/>REM add the new entry to the log<br/>>> %LogFile% Echo %DATE% %TIME%<br/>>> %LogFile% Echo Since : %OldestDate%<br/>net use p:|find "Remote name">> %LogFile% <br/><br/>REM list the files that would be copied if we really were doing a copy<br/>REM force it to believe that the target NonExistentDirectory is a directory<br/>REM and echo the name & time for each<br/><br/>for /f "delims=" %%A in ( ' xcopy /l /i /d:%OldestDate% *.* NonExistentDirectory ' ) do call :ProcessEach "%%A"<br/><br/>REM tidy up the log<br/>>> %LogFile% Echo ========================================<br/><br/>goto :EOF<br/><br/>:ProcessEach<br/><br/>>> %LogFile% echo %~f1 %~t1<br/><br/>goto :EOF<br/><br/><br/><br/>Thank you for help <br/><br/>BR<br/>MichalThe second line in batchfile.bat <a href="https://interviewquestions.tuteehub.com/tag/logs-1077946" style="font-weight:bold;" target="_blank" title="Click to know more about LOGS">LOGS</a> 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.<br/><br/>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)<br/><br/> Michal <br/>I knew it would be something easy !<br/>Sorry I couldnt finish this off without Sidewinder's help (cheers SW)<br/>Graham<br/><br/>Try this<br/> Code: <a>[Select]</a>echo off<br/>CD /d p:\<br/><br/>REM grab todays date into variables<br/>set MM=%Date:~3,2%<br/>set DD=%Date:~0,2%<br/>set YYYY=%Date:~6,4%<br/><br/>REM Add the date variables to the log name<br/>REM putting the date in this order will sort the files sensibly<br/>Set LogFile="e:\NewFiles_%YYYY%-%MM%-%DD%.Log"<br/><br/>REM create the vb script<br/>>c:\evaluate.vbs echo Wscript.echo eval(WScript.Arguments(0))<br/><br/>REM extract todays date less 7 days<br/>set OldestDate=<br/>for /f "delims=" %%A in ( ' cscript //nologo c:\evaluate.vbs "Date -7" ' ) do set OldestDate=%%A<br/><br/>REM tidy<br/>del c:\evaluate.vbs<br/><br/>REM break up the date into constituent parts<br/>REM Note - the date is parsing YYYY-MM-DD format dates,<br/><br/>set MM=<br/>set DD=<br/>set YYYY=<br/><br/>set MM=%OldestDate:~5,2%<br/>set DD=%OldestDate:~8,2%<br/>set YYYY=%OldestDate:~0,4%<br/><br/>REM reconstruct US format with '-' separators<br/>set OldestDate=%MM%-%DD%-%YYYY%<br/><br/>REM add the new entry to the log<br/>>> %LogFile% Echo %DATE% %TIME%<br/>>> %LogFile% Echo Since : %OldestDate%<br/>net use p:|find "Remote name">> %LogFile% <br/><br/>REM list the files that would be copied if we really were doing a copy<br/>REM force it to believe that the target NonExistentDirectory is a directory<br/>REM and echo the name & time for each<br/><br/>for /f "delims=" %%A in ( ' xcopy /l /i /d:%OldestDate% *.* NonExistentDirectory ' ) do call :ProcessEach "%%A"<br/><br/>REM tidy up the log<br/>>> %LogFile% Echo ========================================<br/><br/>REM ----------------------------<br/>REM Release mapped drive<br/>REM ----------------------------<br/><br/>E:<br/><br/>goto :EOF<br/><br/>:ProcessEach<br/><br/>>> %LogFile% echo %~f1 %~t1<br/><br/>goto :EOF<br/>Hi <br/><br/>Now it looks to work with deleting p: drive when script is finished<br/><br/>It seems to be working as expected <br/><br/>Thank you very very very much <br/><br/>BR<br/>MichalHi <br/><br/>I encouriage strange problem. Mentioned above script works fine on one computer, but on all others is failing.<br/><br/>I have that error message:<br/><br/>C:\MDM_Monitoring>echo Y | net use p: /delete<br/>p: was deleted successfully.<br/><br/><br/>C:\MDM_Monitoring>START /wait NET USE p: \\server1\P_Customer\Inbound\70\70_Customer_flat\Archive<br/><br/>C:\MDM_Monitoring>call e:\bathfile.bat<br/>The system cannot find the drive specified.<br/>The device is being accessed by an active process.<br/><br/>More help is available by typing NET HELPMSG 2404.<br/><br/>Press any key to continue . . .<br/><br/><br/>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.<br/><br/>Thank you in advance.<br/><br/>BR<br/>Michal Quote<blockquote>REM ----------------------------<br/>REM Release mapped drive<br/>REM ----------------------------<br/><br/>E:<br/></blockquote> <br/>I see remarks for deleting the mapped drive but no actual <a href="https://interviewquestions.tuteehub.com/tag/instructions-1046362" style="font-weight:bold;" target="_blank" title="Click to know more about INSTRUCTIONS">INSTRUCTIONS</a>. 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.<br/><br/>Be aware that in a caller/calling sequence, that if any module fails to complete properly, your session status may be corrupt.<br/><br/>Why are you using <em>start /wait</em> with the net use command? Why are you <em>piping</em> Y to the net use command? <br/><br/> Quote<blockquote>Special that it works on once computer only. On all other computers I have mentioned above error.<br/></blockquote> <br/>Let us know. <br/><br/>Are all the computers running the same OS. Are they on the same network?<br/><br/>Hi All<br/><br/>Sorry I messed up, all works fine.<br/><br/>note. Always connect to disks mapped to your computer <br/><br/>BR<br/>Silberzin</body></html> | |