Solved

Creating a windows SHARE

Posted on 2000-04-01
2
216 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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Trouble linking program with -lcrypt 3 149
Problem in finding output of a program 11 104
Concatenate two strings Last and First Name 10 60
Socket Programming (Unix) 8 127
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

776 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