Solved

VB6: Problem regarding the API Function NetShareGetInfo

Posted on 2004-10-19
11
801 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

911 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

23 Experts available now in Live!

Get 1:1 Help Now