locked
net use delete - open file RRS feed

  • Question

  • Hi,

    i have a batch script like this:

    net use x: /delete

    If there are open files from the network drive x, the cmd console ask whether the connection should still be disconnected (Y/N).

    I know that I can force to disconnect the network drive (/yes), but I do not want that. 

    I would like to decide here what is done when a file is open and what is done when no file is open.

    for example:

    net use x: /delete
    if there is an open file 
    do ...
    if there is no open file
    do ...

    Is there a possibility here?

    Thanks a lot and sorry for my bad english.
    Wednesday, May 29, 2019 6:43 PM

Answers

  • net use x: /delete /NO | findstr 'open files'

    if ERRORLEVEL 0

    Error os 0 if there are open files.


    \_(ツ)_/



    • Edited by jrv Wednesday, May 29, 2019 7:21 PM
    • Marked as answer by Fisto77 Wednesday, May 29, 2019 7:36 PM
    Wednesday, May 29, 2019 7:19 PM

All replies

  • net use x: /delete /NO | findstr 'open files'

    if ERRORLEVEL 0

    Error os 0 if there are open files.


    \_(ツ)_/



    • Edited by jrv Wednesday, May 29, 2019 7:21 PM
    • Marked as answer by Fisto77 Wednesday, May 29, 2019 7:36 PM
    Wednesday, May 29, 2019 7:19 PM
  • Thanks a lot!

    I have already come up with the same solution shortly before :D

    Wednesday, May 29, 2019 7:39 PM