Net.exe Can Use Hidden Switches /Y /N for Unconditional Yes/No

This article was previously published under Q156458
This article has been archived. It is offered "as is" and will no longer be updated.
SUMMARY
When you use Net.exe commands in a batch file, you can use the Y or Nswitch to unconditionally answer Yes or No to questions returned by the Netcommand.
MORE INFORMATION
Normally, you could pass a "Y" using Standard-in through redirection as inthe following example:
   delshare.bat file contents:   NET SHARE TOOLS /D  <y.txt   Y.txt file contents:   Y(cr) carriage return				

But the following error occurs using this method when the Delshare.bat fileis run and fails the operation.
NET SHARE TOOLS /D <y.txt
Users have open files on TOOLS. Continuing the operation will force the files closed.

Do you want to continue this operation? (Y/N) [N]:
No valid response was provided.
WORKAROUND
Change your batch file to include the Y switch to unconditionally answerYes to the question "Do you want to continue this operation? (Y/N) [N]:"
   Delshare.bat new contents:   NET SHARE TOOLS /D /Y				

After running this batch file, you will receive the following message:
   NET SHARE TOOLS /D /y   Users have open files on TOOLS. Continuing the operation will force the   files closed.   TOOLS was deleted successfully.				
std-in prodnt
Properties

Article ID: 156458 - Last Review: 12/04/2015 15:24:31 - Revision: 3.0

Microsoft Windows NT Advanced Server 3.1, Microsoft Windows NT Workstation 3.1, Microsoft Windows NT Workstation 3.5, Microsoft Windows NT Workstation 3.51, Microsoft Windows NT Workstation 4.0 Developer Edition, Microsoft Windows NT Advanced Server 3.1, Microsoft Windows NT Server 3.5, Microsoft Windows NT Server 3.51, Microsoft Windows NT Server 4.0 Standard Edition

  • kbnosurvey kbarchive kbusage KB156458
Feedback