Solved

VB6: Problem regarding the API Function NetShareGetInfo

Posted on 2004-10-19
11
795 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 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…

746 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

12 Experts available now in Live!

Get 1:1 Help Now