Solved

Unsharing a drive or path

Posted on 2000-03-15
8
258 Views
Last Modified: 2010-05-18
Hi all :-)

I want to know how to unshare a drive or a path on a win9x box with no username or password set.

Thanks
0
Comment
Question by:mabell
8 Comments
 

Expert Comment

by:b26
ID: 2619097
Hi,

Use the function: (extras from MSDN)

NET_API_STATUS NetShareDel(
  LPWSTR servername,  
  LPWSTR netname,    
  DWORD reserved      
);
 
(could be found in in netapi32.dll NT, or svrapi.dll WIN95/98)

Parameters
servername
[in] Pointer to a Unicode string specifying the name of the remote server on which the function is to execute. If this parameter is NULL, the local computer is used.
netname
[in] Pointer to a Unicode string specifying the network name of the share to delete.
reserved
Reserved, must be zero.
Return Values
If the function returns account information, the return value is NERR_Success.

If the function fails, the return value can be one of the following error codes:

ERROR_ACCESS_DENIED The user does not have access to the requested information.
ERROR_INVALID_PARAMETER The specified parameter is invalid.
ERROR_NOT_ENOUGH_MEMORY Insufficient memory is available.
NERR_NetNameNotFound The share name does not exist.
0
 
LVL 4

Expert Comment

by:jeurk
ID: 2619159
hello,

Here http://www.jgsoftware.com/files/netconn.zip
you have a component that does all for you.
This component manages connections to network resources in Windows 95
      and NT.  You may establish connections, map local resources (drives and
      ports) to network resources, and you may break connections with this
      component.
It's using the Win32 API functions
      WNetAddConnection2 and WNetCancelConnection2 that you should use instead of netshareDel that is a 16 bit function (I think).

the site is here : http://www.jgsoftware.com/nt.htm

CU

0
 
LVL 4

Expert Comment

by:jeurk
ID: 2619161
it's free and with sources...
0
 

Expert Comment

by:b26
ID: 2619390
netshareDel it's not a 16 bit function

take care,
B
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.

 
LVL 20

Accepted Solution

by:
Madshi earned 100 total points
ID: 2619437
Hi guys,

with WNetAddConnection&Co you can map drives to an existing share respectively delete such a drive map. But you can't delete the share itself with this function. For this purpose you must use (as b26 suggested) NetShareDel, which is a 32bit function. But the function definition is different under win9x than it is under winNT!!! Here comes the win9x function definition:

extern API_FUNCTION
  NetShareDel ( const char FAR * pszServer,
                const char FAR * pszNetName,
                unsigned short   usReserved );

Which is this in Delphi:

procedure DelShare9x(shareName: string);
var svrDll : dword;
    NetShareDel9x : function (server, netName: pchar; reserved: word) : cardinal; stdcall;
begin
  svrDll := LoadLibrary('svrapi.dll');
  NetShareDel9x := GetProcAddress(svrDll, 'NetShareDel');
  NetShareDel9x(nil, pchar(shareName), 0);
  FreeLibrary(svrDll);
end;

Regards, Madshi.
0
 

Expert Comment

by:Rusfist
ID: 2619513
Listening...
0
 

Author Comment

by:mabell
ID: 2621021
Thanks all for your help :-))
but Madshi will have the points. So Madshi post your comment as an answer :-)
Thx!!!
0
 
LVL 1

Expert Comment

by:yk030299
ID: 2622071
listen
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

Suggested Solutions

Title # Comments Views Activity
Thread safe  opinion 7 126
Delphi Seattle: Project Options : Version info for all platforms, all releases? 2 76
Delphi 2 45
JAudiorecorder record freezing the app 29 59
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
A short film showing how OnPage and Connectwise integration works.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

948 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

21 Experts available now in Live!

Get 1:1 Help Now