?
Solved

Windows Programming question

Posted on 1997-09-24
7
Medium Priority
?
363 Views
Last Modified: 2013-12-03
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
Comment
Question by:md041797
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 4

Author Comment

by:md041797
ID: 1407062
Adjusted points to 100
0
 
LVL 4

Author Comment

by:md041797
ID: 1407063
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
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1407064
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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

Accepted Solution

by:
mattyg102096 earned 100 total points
ID: 1407065
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
 
LVL 4

Author Comment

by:md041797
ID: 1407066
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
 

Expert Comment

by:mattyg102096
ID: 1407067
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
 
LVL 5

Expert Comment

by:y96andha
ID: 1407068
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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

752 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