?
Solved

VB6: Problem regarding the API Function NetShareGetInfo

Posted on 2004-10-19
11
Medium Priority
?
825 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 1500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

800 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