Solved

Windows Programming question

Posted on 1997-09-24
7
355 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
7 Comments
 
LVL 4

Author Comment

by:md041797
Comment Utility
Adjusted points to 100
0
 
LVL 4

Author Comment

by:md041797
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Accepted Solution

by:
mattyg102096 earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…
This video discusses moving either the default database or any database to a new volume.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now