• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 369
  • Last Modified:

Windows Programming question

Win 95 / Win NT4


How do you get the name of the local computer?  

How do you get all share names for a local drive?  All of the Net*** functions return nothing for local resources.  In other words, how do I find all the available share names for my drive C:?

0
md041797
Asked:
md041797
1 Solution
 
md041797Author Commented:
Adjusted points to 100
0
 
md041797Author Commented:
I know I can get these directly via the registry, but I need to get them via the Win API so the code don't break when Win 98 comes out, or whatever else may happen.
0
 
RONSLOWCommented:
What is happening with points here?  strange things are brewing in the experts exchange - I've seen questions with points like 33.3333333333 - now this one says "adjusted to 100" but only shows 50?

0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
mattyg102096Commented:
Re: Question 1... Local computer name.  How about:

BOOL GetComputerName(LPTSTR lpBuf, LPDWORD nSize);
where

lpBuf = pointer to a buffer to receive the null-terminated string
nSize = pointer to a DWORD with the size of the buffer

returns BOOL for success/failure.  On failure, GetLastError will return more info.

Re: Question 2...

My Win32 docs say that some of the Net***() functions are obsolete.  There are new WNet***() functions.  The one I'd look at here is WNetEnumResource() which is suggested by my docs when I ask about NetShareEnum() which is the function I was going to suggest.  It is also suggested as a replacement for NetUseEnum() WNetEnumResource() enums resources based on a hEnum handle created by the WNetOpenEnum() API.

I also noted that both APIs are used by the NET command on Windows NT (I don't have Win95 to check for it).
0
 
md041797Author Commented:
Number 1 is a good answer.  

Number 2:
The WNet*** is what I'm talking about in my question.  They only enumerate remote resources.  I need the share names of the folders on the local drive, such as can be found in

HKEY_LOCAL_MACHINE\system\CurrentControlSet\Services\LanmanServer\Shares\driveletter (NT)

or

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Network\LanMan\Sharename (95)


The scores are really screwed up. I initailly gave 100 points for this question.  I saw it posted as 50, and thought I screwed up, so I upped it to 100.  Looking at my Current Balance, I see that this question has escrowed 150 points.  It probably will grant 150.  Also the title was changed from "Retrieve computer name / Share names" along with other titles too.  I'll bet they are looking for some new digital grease monkeys.


0
 
mattyg102096Commented:
Hmmm.... I'm stuck.  I thought WNetEnumResource would be the answer.  Actually, I checked out NET.EXE again and I see that it does use some registry functions as well.  Who knows... maybe NET.EXE "cheats", too.
0
 
y96andhaCommented:
The following code enumerates local shares on my computer (NT Workstation 4.0).

      int status;
      DWORD entread, tent;
      PSHARE_INFO_2 p;
      status = NetShareEnum(0, 2, (LPBYTE*)&p, 100000, &entread, &tent, 0);
      if(status == 0) {
            int i;
            for(i = 0; i < entread; i++) {
                  wprintf(L"%s %s\n", p[i].shi2_netname, p[i].shi2_path);
            }
      } else {
            printf("Error %d while getting share names\n", i);
      }

0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now