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:?

LVL 4
md041797Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.