RSS Forums RSS

Re: Accessing network share programmatically

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums

Accessing network share programmatically

Posts: 41
Reputation: mrmike is an unknown quantity at this point 
Solved Threads: 0
mrmike mrmike is offline Offline
Light Poster

Re: Accessing network share programmatically

  #7  
Jun 24th, 2005
i've never done this under VB but did write a routine that could map drives under delphi.

the following code is how it works under delphi, you could see if can change to work with VB.

function ConnectDrive(_drvLetter: String; _netPath: String; _password: String; _username: String; _showError: Boolean; _reconnect: Boolean; _interactive: Boolean): DWORD;
var
 nRes            :TNetResource;
 dwFlags         :DWORD;
 errCode         :DWORD;
begin
 FillChar(NRes,SizeOf(NRes),#0);
 nRes.dwType:=RESOURCETYPE_DISK;
 nRes.lpLocalName:=PChar(_drvLetter);
 nRes.lpRemoteName:=PChar(_netPath);
 nRes.dwScope:=RESOURCE_GLOBALNET;
 dwFlags:=0;
 If _reconnect then dwFlags:=CONNECT_UPDATE_PROFILE;
 If _reconnect and _interactive then dwFlags:=CONNECT_UPDATE_PROFILE and CONNECT_INTERACTIVE;
 Result:=WNetAddConnection3(form1.Handle,nRes,PChar(_password),PChar(_username),dwFlags);
 end;

function DisConnectDrive(_drvLetter: String; _showError: Boolean; _force: Boolean; _save: Boolean): DWORD;
var
 nRes           :TNetResource;
 dwFlags        :DWORD;
 errCode        :DWORD;
begin
if _save then
 dwFlags:=CONNECT_UPDATE_PROFILE
else
 dwFlags:=0;
 errCode:=WNetCancelConnection2(PChar(_drvLetter),dwFlags,_force);
if (errCode<>NO_ERROR) and (_showError) then
 begin
  Application.MessageBox(PChar(SysErrorMessage(GetLastError)),
  'Error Disconnecting Drive',
  MB_OK);
 end;
 Result:=errCode; {NO_ERROR}
end;

You could have a couple of text inputs on the form, with a command button. When clicking on this after filling the info in, you could connect the drive. When the program closes you could get it to call the disconnect feature to ensure properly disconnected.

If need further help, I'll try to get it converted to a VB app, but due to workload can be sometime before I get it done.

Good Luck

Mike
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:51 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC