Solved

Creating a windows SHARE

Posted on 2000-04-01
2
196 Views
Last Modified: 2010-04-15
This bound to be simple for a programmer (which I am not)....I need either a)the file/code or b)where to find the file/code for a small batch usable exe which will let me CREATE a share on a 95/98 machine and specify username/password/sharename on the command line. NOTE: I need to create the share, not map a drive, there is no NET SHARE on 95/98 machines only a NET USE....
0
Comment
Question by:Egoslayer1
2 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 50 total points
ID: 2676392
Under both NT and Win9x it's done using the NetShareAdd() API.  Even though both operating systems have this function, the definition and operation of it are not identical.

Basically, NetShareAdd() on Win9x uses only the level 50 data structure.

The SDK docs have an example of the code:

#include <stdio.h>
#include <windows.h>
#include <svrapi.h>

int main(int argc, char FAR * argv[])
{
   char FAR * pszServerName = NULL;
   short nLevel = 50;
   struct share_info_50* pBuf = NULL;
   unsigned short cbBuffer;
   NET_API_STATUS nStatus;
   //
   // ServerName can be NULL to indicate the local computer.
   //
   if ((argc < 3) || (argc > 4))
   {
      printf("Usage: %s [\\\\ServerName] ShareName SharePath\n", argv[0]);
      exit(1);
   }

   if (argc == 4)
      pszServerName = argv[1];
   //
   // Allocate the memory required to specify a
   //   share_info_50 structure.
   //
   cbBuffer = sizeof(struct share_info_50);
   pBuf = malloc(cbBuffer);

   if (pBuf == NULL)
      printf("No memory\n");
   //
   // Assign values to the share_info_50 structure.
   //
   strcpy(pBuf->shi50_netname, argv[argc-2]);
   pBuf->shi50_type = STYPE_DISKTREE;
   pBuf->shi50_flags = SHI50F_FULL;
   pBuf->shi50_remark = NULL;
   pBuf->shi50_path = argv[argc-1];
   pBuf->shi50_rw_password[0] = '\0'; // No password
   pBuf->shi50_ro_password[0] = '\0'; // No password
   //
   // Call the NetShareAdd function
   //  specifying information level 50.
   //
   nStatus = NetShareAdd(pszServerName,
                         nLevel,
                         (char FAR *)pBuf,
                         cbBuffer);
   //
   // Display the result of the function call.
   //
   if (nStatus == NERR_Success)
      printf("Share added successfully\n");
   else
      fprintf(stderr, "A system error has occurred: %d\n", nStatus);
   //
   // Free the allocated memory.
   //
   if (pBuf != NULL)
      free(pBuf);

   return 0;
}
0
 
LVL 1

Author Comment

by:Egoslayer1
ID: 2776088
I think that's a good answer but to be honest it's over my head so I wouldn't know if you were BS'ing me but thanks
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now