Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7716673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:41:33+00:00 2026-06-01T02:41:33+00:00

I need to share a folder with read and write permissions . In windows

  • 0

I need to share a folder with read and write permissions.

In windows 7 I am able to share it by executing:

net share temp=A:\MySharedFolder /GRANT:Everyone,FULL

If I execute the same code in windows xp it does not work. I can however execute:

net share temp=C:\MySharedFolder

but the folder will not be shared with full permissions.


EDIT

JotaBe posted a link and from that link I constructed the following program which seems to work.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
    class Program
    {

        [DllImport("Netapi32.dll")]
        private static extern uint NetShareAdd(
            [MarshalAs(UnmanagedType.LPWStr)] string strServer,
            Int32 dwLevel,
            ref SHARE_INFO_502 buf,
            out uint parm_err
        );

        private enum NetError : uint
        {
            NERR_Success = 0,
            NERR_BASE = 2100,
            NERR_UnknownDevDir = (NERR_BASE + 16),
            NERR_DuplicateShare = (NERR_BASE + 18),
            NERR_BufTooSmall = (NERR_BASE + 23),
        }

        private enum SHARE_TYPE : uint
        {
            STYPE_DISKTREE = 0,
            STYPE_PRINTQ = 1,
            STYPE_DEVICE = 2,
            STYPE_IPC = 3,
            STYPE_TEMPORARY = 0x40000000,
            STYPE_SPECIAL = 0x80000000,
        }

        [StructLayout(LayoutKind.Sequential)]
        private struct SHARE_INFO_502
        {
            [MarshalAs(UnmanagedType.LPWStr)]
            public string shi502_netname;
            public SHARE_TYPE shi502_type;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string shi502_remark;
            public Int32 shi502_permissions;
            public Int32 shi502_max_uses;
            public Int32 shi502_current_uses;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string shi502_path;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string shi502_passwd;
            public Int32 shi502_reserved;
            public IntPtr shi502_security_descriptor;
        }


        static void Main(string[] args)
        {

            string shareName = "testshare";
            string shareDesc = "This is a test share kekelar2000";
            string path = @"C:\MyShareDirectory"; // do not append comma, it'll fail

            SHARE_INFO_502 info = new SHARE_INFO_502();
            info.shi502_netname = shareName;
            info.shi502_type = SHARE_TYPE.STYPE_DISKTREE;
            info.shi502_remark = shareDesc;
            info.shi502_permissions = 0;   
            info.shi502_max_uses = -1;
            info.shi502_current_uses = 0;    
            info.shi502_path = path;
            info.shi502_passwd = null;       
            info.shi502_reserved = 0;
            info.shi502_security_descriptor = IntPtr.Zero;

            uint error = 0;

            uint result = NetShareAdd("192.168.0.120", 502, ref info, out error);
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:41:34+00:00Added an answer on June 1, 2026 at 2:41 am

    Use this:

    netshareadd (netapi32)

    You’ll have to run your program as administrator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to be able to install a program in a shared folder on
BACKGROUND I need to write a tool using .NET version 2.0 at highest (using
I need to perform some operations on all folders within a file share which
I need to share SSO information between two different domains with a cookie, can
I need to share a stack of strings between processes (possibly more complex objects
I have 2 Java EE applications which need to share some common user related
I have Client-Server environment and developed a project for Client-Server. I need to share
I need to create several applications that all share a Microsoft SQL Server database.
I need a script to run on Vista Ultimate to share an external drive
I need to find an open source alternative to VSS where people will share

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.