Solved

Windows Programming question

Posted on 1997-09-24
7
359 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
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

Accepted Solution

by:
mattyg102096 earned 50 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

685 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