Solved

VB6: Problem regarding the API Function NetShareGetInfo

Posted on 2004-10-19
11
812 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
[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
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

730 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