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
Solved

VB6: Problem regarding the API Function NetShareGetInfo

Posted on 2004-10-19
11
809 Views
Last Modified: 2012-05-05
Hello experts,
in my VB6 program I encountered the following problem:

Problem regarding the API Function  NetShareGetInfo:
If a user myuser has the following rights (permissions) on a share  \\ComputerName\test_data
  Full Control                   not allowed
  Modify                          allowed
  Read & Execute             allowed
  List Folder Contents       allowed
  Read                            allowed
  Write                           allowed
  Special Permissions       not allowed
the API Function NetShareGetInfo returns the Return Code ERROR_ACCESS_DENIED (=5).

But it is possible to establish a connection to this share using the user myuser on my computer;
and the files can be modified, ...

What could be wrong
or
is there another way to determine wether the share \\ComputerName\test_data is available?

I have used the Visual Basic program for the NetShareGetInfo API Function which can be found at:
  http://www.mentalis.org/apilist/NetShareGetInfo.shtml

If anyone knows a solution,
please supply an appropriate code snippet.
Thank you very much.

  HStrix


0
Comment
Question by:HStrix
  • 6
  • 5
11 Comments
 
LVL 14

Expert Comment

by:Shiju Sasidharan
ID: 12349307
0
 
LVL 14

Expert Comment

by:Shiju Sasidharan
ID: 12349352
Hi

For  Connecting to Network Resources try this link

http://vbnet.mvps.org/index.html?code/network/netconnect.htm

For Enumerating Local Network Resources via WNetEnumResource follow this link

http://vbnet.mvps.org/index.html?code/network/wnetenumresource.htm


;-)
Shiju
0
 

Author Comment

by:HStrix
ID: 12349666
Thanks Shiju,
but it doesn't solve my problem.
I want to check if a share is available.
I know the computer name, I know the share name, I know the user name.
I can access the share using the explorer-tools menu point.
But the API says the "Access_DENIED".
I want to get rid of this.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 14

Expert Comment

by:Shiju Sasidharan
ID: 12350092
Hi
Have u set any password for the user 'Myuser'?

;-)
Shiju
0
 
LVL 14

Expert Comment

by:Shiju Sasidharan
ID: 12350264
i went through this link
http://www.mentalis.org/apilist/NetShareGetInfo.shtml

that code worked properly when i tried.

R u sure u have set the read permission for that user ?

;-)
Shiju

0
 

Author Comment

by:HStrix
ID: 12355135

The user 'myuser' has enough permission (read/write) accessing the share.
The user 'myuser' requires a password.
I establish the connection to the share using 'establish connection using mydomain\myuser/mypassword'.
And so it works.

But I want to check the connection programmatically.

I'm logged in as user 'mylocaluser' and not as 'myuser'.
It seems that this is the cause?
But how can I provide 'myuser' (or 'mydomain\myuser') and its password for NetShareGetInfo?
'myuser' is NOT a local user, it is a user in a domain (active directory).
My computer is NOT in the domain mydomain.
0
 
LVL 14

Accepted Solution

by:
Shiju Sasidharan earned 500 total points
ID: 12355496
hi HStrix

u need to map it to a drive letter.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wnet/wnet/wnetaddconnection2.asp

using this you can specify the name and password.  You can use GetLogicalDrives to get a bitmap of the drive letters that are in use

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/getlogicaldrives.asp

;-)
Shiju
0
 

Author Comment

by:HStrix
ID: 12355891
Thanks Shiju,
I understand what you mean.
"u need to map it to a drive letter." seems to be eqivalent to the connection  process.
This sounds that there is NO other way to check the availability of a share.

Then the process could be:
- check all drive letters for a share name
- if the share doesn't exist
  - check for an unused drive letter (could be a problem)
  - add this share using domain, user, pw and share name
- if the share already exists
  - check if the connection is possible <== how?
Is this sequence OK?

In addition:
How about using an UNC path and check if an access (connection) is possible?
This would be closer to the process I originally wanted to implement.
In this case I don't need to take care about the existing drive letters.
Do you have any suggestion for this?



0
 

Author Comment

by:HStrix
ID: 12378091
I found some useful information to solve the issue on
- Retrieving User, Share and Share User Name for Network Resources:
  http://vbnet.mvps.org/index.html?code/network/wnetdemo.htm
- How to check access rights to file/directory on NTFS volume in Windows NT/2000/XP:
  http://www.smsoft.ru/en/checkfileaccess.htm
I used the information from these pages to solve the issue for mapped drives.

Still open for me is "How to get simular information in case for UNC pathes".
0
 

Author Comment

by:HStrix
ID: 12378110
Thanks Shiju,
your comments did not completely solve the issue,
but they helped me coming toward a solution.

  HStrix
0
 
LVL 14

Expert Comment

by:Shiju Sasidharan
ID: 12387391
Hi HSrix

Thank u for giving the points & 
also for providing the link
  http://vbnet.mvps.org/index.html?code/network/wnetdemo.htm

regards

;-)
Shiju
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

860 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