MEGA Search
20.3 Million


Sign Up
From: David J Taylor  
Subject: Disconnected network drive - how to restore?
NewsGroup: borland.public.delphi.nativeapi
Date Posted: 9-May-2003 at 9:47:14 PST
I have a program which works on files over the network.  It uses both
FindFirst/FindNext and FindFirstChangeNotification.

Under some circumstances, it seems that Windows does not completely
connect the network drive, and whilst the FindFirst/FindNext runs OK, the
FindFirstChangeNotification fails.  Clicking on the network drive in
Explorer seems to "reconnect" it, and restore normal operation.

Obviously, I do not like my program failing in this way, and requiring
user action to proceed.  Is there an API I can use to emulate Explorer's
refresh of the drive connection?  Any help or suggestions would be
appreciated.

Thanks,
David



From: Peter Below (TeamB)  
Subject: Re: Disconnected network drive - how to restore?
NewsGroup: borland.public.delphi.nativeapi
Date Posted: 9-May-2003 at 20:8:13 PST
In article <3ebb6b11$1@newsgroups.borland.com>, David J Taylor wrote:
> I have a program which works on files over the network.  It uses both
> FindFirst/FindNext and FindFirstChangeNotification.
> 
> Under some circumstances, it seems that Windows does not completely
> connect the network drive, and whilst the FindFirst/FindNext runs OK, the
> FindFirstChangeNotification fails.  Clicking on the network drive in
> Explorer seems to "reconnect" it, and restore normal operation.
> 
> Obviously, I do not like my program failing in this way, and requiring
> user action to proceed.  Is there an API I can use to emulate Explorer's
> refresh of the drive connection?  Any help or suggestions would be
> appreciated.

You can use WNetAddConnection2 to create connection to shares in code. Or 
you can use UNC filenames, unless the shares require a password to connect 
to  those will work whether the share is connected or not.


--
Peter Below (TeamB)  
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be



From: David J Taylor  
Subject: Re: Disconnected network drive - how to restore?
NewsGroup: borland.public.delphi.nativeapi
Date Posted: 9-May-2003 at 17:9:5 PST
"Rick Betting"  wrote in message
news:3ebbaddd$1@newsgroups.borland.com...
> Hi,
>
> The only suggestion I have is to disable autodisconnect of network
drives...
> This affects the entire system... You also could read the autodisconnect
> time value,
> Use the next code to disable auto disconnect, and at the end restoring
the
> original value...

Rick,

Thanks for the suggestion and the code (which I have stashed away!), but I
don't want to interfere that much with my users' PCs.  I would still like
to find another way.

Cheers,
David



From: Rick Betting  
Subject: Re: Disconnected network drive - how to restore?
NewsGroup: borland.public.delphi.nativeapi
Date Posted: 9-May-2003 at 15:34:32 PST
Hi,

The only suggestion I have is to disable autodisconnect of network drives...
This affects the entire system... You also could read the autodisconnect
time value,
Use the next code to disable auto disconnect, and at the end restoring the
original value...

function TForm1.DisableAutoDisconnect: Boolean;
type
  NET_API_STATUS = DWORD;
  PServerInfo102 = ^TServerInfo102;
  _SERVER_INFO_102 = record
     sv102_platform_id: DWORD;
     sv102_name: LPWSTR;
     sv102_version_major: DWORD;
     sv102_version_minor: DWORD;
     sv102_type: DWORD;
     sv102_comment: LPWSTR;
     sv102_users: DWORD;
     sv102_disc: LongInt;
     sv102_hidden: BOOL;
     sv102_announce: DWORD;
     sv102_anndelta: DWORD;
     sv102_licenses: DWORD;
     sv102_userpath: LPWSTR;
  end;
  TServerInfo102 = _SERVER_INFO_102;
const
  netapi32lib = 'netapi32.dll';
  SV_NODISC = -1;
var
  BufPtr: Pointer;
  ServerInfo102: pServerInfo102;
  ParmError: LongWord;
  NetServerSetInfo: function(servername: LPWSTR; level: DWORD; buf: Pointer;
ParmError: PDWORD): NET_API_STATUS; stdcall;
  NetServerGetInfo: function (servername: LPWSTR; level: DWORD; var bufptr:
Pointer): NET_API_STATUS; stdcall;
  NetApiBufferFree: function (Buffer: Pointer): NET_API_STATUS; stdcall;
  NetApi32Handle: THandle;
begin
  Result := False;
  NetApi32Handle := SafeLoadLibrary(netapi32lib);
  if (NetApi32Handle <> 0) then
  begin
    @NetServerSetInfo := GetProcAddress(NetApi32Handle, 'NetServerSetInfo');
    @NetServerGetInfo := GetProcAddress(NetApi32Handle, 'NetServerGetInfo');
    @NetApiBufferFree := GetProcAddress(NetApi32Handle, 'NetApiBufferFree');
    if (@NetServerSetInfo <> nil) and (@NetServerGetInfo <> nil) and
(@NetApiBufferFree <> nil) then
    try
      NetServerGetInfo(nil, 102, BufPtr);
      ServerInfo102 := PServerInfo102(BufPtr);
      ServerInfo102^.sv102_disc := SV_NODISC;
      NetServerSetInfo(nil, 102, BufPtr, @ParmError);
      NetApiBufferFree(BufPtr);
      Result := True;
    except
    end;
    FreeLibrary(NetApi32Handle);
  end;
end;


--

Rick Betting,
Online Software.
rick@ATonlinegroepDOT.nl
(Remove AT and DOT )

Nam et ipsa scientia potestas est


"David J Taylor"  schreef in bericht
news:3ebb6b11$1@newsgroups.borland.com...
> I have a program which works on files over the network.  It uses both
> FindFirst/FindNext and FindFirstChangeNotification.
>
> Under some circumstances, it seems that Windows does not completely
> connect the network drive, and whilst the FindFirst/FindNext runs OK, the
> FindFirstChangeNotification fails.  Clicking on the network drive in
> Explorer seems to "reconnect" it, and restore normal operation.
>
> Obviously, I do not like my program failing in this way, and requiring
> user action to proceed.  Is there an API I can use to emulate Explorer's
> refresh of the drive connection?  Any help or suggestions would be
> appreciated.
>
> Thanks,
> David
>
>



From: David J Taylor  
Subject: Re: Disconnected network drive - how to restore?
NewsGroup: borland.public.delphi.nativeapi
Date Posted: 12-May-2003 at 19:35:31 PST
"Jason"  wrote in message
news:3ebfc72d$1@newsgroups.borland.com...
> This should should work...

Thanks very much,

David



From: Jason  
Subject: Re: Disconnected network drive - how to restore?
NewsGroup: borland.public.delphi.nativeapi
Date Posted: 12-May-2003 at 11:10:48 PST
This should should work...


function ConnectDrive(_drvLetter: string; _netPath: string; _showError:
Boolean;
  _reconnect: Boolean): DWORD;
var
  nRes: TNetResource;
  errCode: DWORD;
  dwFlags: DWORD;
begin
  { Fill NetRessource with #0 to provide uninitialized values }
  { NetRessource mit #0 füllen => Keine unitialisierte Werte }
  FillChar(NRes, SizeOf(NRes), #0);
  nRes.dwType := RESOURCETYPE_DISK;
  { Set Driveletter and Networkpath }
  { Laufwerkbuchstabe und Netzwerkpfad setzen }
  nRes.lpLocalName  := PChar(_drvLetter);
  nRes.lpRemoteName := PChar(_netPath); { Example: \\Test\C }
  { Check if it should be saved for use after restart and set flags }
  { Überprüfung, ob gespeichert werden soll }
  if _reconnect then
    dwFlags := CONNECT_UPDATE_PROFILE and CONNECT_INTERACTIVE
  else
    dwFlags := CONNECT_INTERACTIVE;

  errCode := WNetAddConnection3(Form1.Handle, nRes, nil, nil, dwFlags);
  { Show Errormessage, if flag is set }
  { Fehlernachricht aneigen }
  if (errCode <> NO_ERROR) and (_showError) then
  begin
    Application.MessageBox(PChar('An error occured while connecting:' +
#13#10 +
      SysErrorMessage(GetLastError)),
      'Error while connecting!',
      MB_OK);
  end;
  Result := errCode; { NO_ERROR }
end;








"David J Taylor"  wrote in message
news:3ebb6b11$1@newsgroups.borland.com...
> I have a program which works on files over the network.  It uses both
> FindFirst/FindNext and FindFirstChangeNotification.
>
> Under some circumstances, it seems that Windows does not completely
> connect the network drive, and whilst the FindFirst/FindNext runs OK, the
> FindFirstChangeNotification fails.  Clicking on the network drive in
> Explorer seems to "reconnect" it, and restore normal operation.
>
> Obviously, I do not like my program failing in this way, and requiring
> user action to proceed.  Is there an API I can use to emulate Explorer's
> refresh of the drive connection?  Any help or suggestions would be
> appreciated.
>
> Thanks,
> David
>
>