Results 1 to 3 of 3

Thread: Im confused ...

  1. #1

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    Im confused ...

    Howdy.

    I got this piece of code off the microsoft site.
    I tried converting it to VB, but that didnt work. So I decided id compile as is and shell out to it from vb.

    Anyway, it is just not happening.
    Info regarding it can be found on :
    http://msdn.microsoft.com/library/ps...lmapi_1sdb.htm

    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;
    }
    Any ideas on how to get it to work ?
    All I want to to is be able to shell an executable that will share the current system's C:\ (well, the drive that windows is on, but c:\ will do).

    Thanks,
    Jamie.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    The pBuf->shi50_path member must be in all UPPER CASE.

    Best regards

  3. #3

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Em you may want to look at this too :
    http://www.vbforums.com/showthread.p...3&goto=newpost

    It points back to this one, but there's more info there.

    - jamie
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width