Need to create batch file for "net share" command


  1. Posts : 25
    windows 10
       #1

    Need to create batch file for "net share" command


    I created a simple command from powershell that maps a drive for me using the "net share" command (see below). However, i want to turn this in to a batch file so I do not have to type it every time. When I name it filename.bat and try to run it, I get a

    system error 5 has occured, access denied

    I assume I have to make this a powershell script. My question is, if I cant run it as a batch file, how do I run this as a powershell script so I only have to click on it to run it?

    *I am extremely new to powershell

    Thank you

    net share myshare=z:\ /grant:user,full /users:1
      My Computer


  2. Posts : 809
    Win10
       #2

    You have to run that command with Administrator privileges. Right-click the batch file and click Run as administrator.
      My Computer


  3. Posts : 5,330
    Windows 11 Pro 64-bit
       #3

    eeps24 said:
    I created a simple command from powershell that maps a drive for me using the "net share" command (see below). However, i want to turn this in to a batch file so I do not have to type it every time. When I name it filename.bat and try to run it, I get a

    system error 5 has occured, access denied

    I assume I have to make this a powershell script. My question is, if I cant run it as a batch file, how do I run this as a powershell script so I only have to click on it to run it?

    *I am extremely new to powershell

    Thank you

    net share myshare=z:\ /grant:user,full /users:1

    You are not mapping a drive you are configuring share options for Z: drive.

    Mapping a drive to a network share assigns that share a drive letter so that it’s easier to work with.

    To map a network drive, type the following command and then hit Enter:
    Code:
    net use x: \\computer name\sharename /user username password
    

    In order to make the connection to the shared folder permanent, you need to add the /P parameter. This will ensure the drive will remain even after a restart. In some versions of Windows, you may have to use /PERSISTENT instead of /P.
    Code:
    net use x: \\computer name\sharename /P:Yes
    You can delete a mapped network drive using the command prompt by typing in the command below.

    Code:
    net use x: /delete
    To delete all mapped network drives by executing below command.

    Code:
    net use * /delete
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 06:49.
Find Us




Windows 10 Forums