Activate Mapped Drive

My Delphi Application cannot use certain Mapped Drives until and unless I click the Drive letter via Windows Explorer.
How can I activate the drive thru my Delphi Application itself.

My Machine is WinXP
Remote machine is Win7-64bit (mapped on my XP as R: with Reconnect on Logon)
From my Delphi Application I have tried FindFirst / GetDrives / SaveTo...(R:...) etc but no use.
Allan_FernandesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TemodyPickalbatros, IT ManagerCommented:
Microsoft fix in Vista Forum. Works with Win7 also.
https://support.microsoft.com/en-us/kb/937624
0
Allan_FernandesAuthor Commented:
It is not issue with UAC as the drive gets activated simply by clicking on Windows Explorer, I do not have to enter any password. After resetting the machines again the same situation.
0
Sinisa VukSoftware architectCommented:
Try this code to connect to shared folder with username/pwd. Should (re)enable link ... even if mapped folder acts like local.
(for user,pwd try blank/nil too)
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Allan_FernandesAuthor Commented:
Tried it but does not happen. You have correctly understood my issue though.
In my test code I run your function (tried with user/pass also) and next line just
Memo1.LoadFromFile('r:\....') nothing loads

Then thru windows explorer I click R: once and no password asked by windows (as it is full share)
then my program just loads into the memo.
0
Sinisa VukSoftware architectCommented:
I try with same user on both machine (xp, win7) and after xp restart works as should be
(FileExists function ...), then I restart win7 and works again. Do you have same user name?
0
Sinisa VukSoftware architectCommented:
alternatively,  you can pass flags:
flags := CONNECT_INTERACTIVE or CONNECT_CMD_SAVECRED or CONNECT_UPDATE_PROFILE;

Open in new window


WNetAddConnection2
0
Allan_FernandesAuthor Commented:
This did not help either.
I have understood the issue very clearly now.

WinXP has R:  (ie: \\Win7\D\)

Situation A
1. Win7 Switched On
2. WinXP Switched On
3. My Program on WinXP tries to access r:\abc.txt
4. IT Works!!

Situation B
1. WinXP Switched On
2. Windows message  that it could not reconnect all network drives
2. Win7 Switched On
3. My Program on WinXP tries to access r:\abc.txt
4. Fails.
5. Using Win Explorer I access R:
6.  My Program on WinXP tries to access r:\abc.txt
7. IT Works!!

What is it that Windows Explorer can trigger and my program cannot ?
0
Sinisa VukSoftware architectCommented:
I create simple example....
First I check if file exists - if not then try to refresh mapping.
Refresh check (using wmi) if mapping is disconected and if yes - try to force add mapping - mapping exists (exception comes up) - but mapping go active...

function RefreshMappedDrive(cDrvLetter: Char): Boolean;
const
  WbemUser            ='';
  WbemPassword        ='';
  WbemComputer        ='localhost';
  wbemFlagForwardOnly = $00000020;
var
  FSWbemLocator : OLEVariant;
  FWMIService   : OLEVariant;
  FWbemObjectSet: OLEVariant;
  FWbemObject   : OLEVariant;
  oEnum         : IEnumvariant;
  iValue        : LongWord;
  WshNetwork    : OLEVariant;
begin;
  Result := False;

  FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  FWMIService   := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword);
  FWbemObjectSet:= FWMIService.ExecQuery('SELECT LocalName,ConnectionState,RemotePath FROM Win32_NetworkConnection','WQL',wbemFlagForwardOnly);
  oEnum         := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
  while oEnum.Next(1, FWbemObject, iValue) = 0 do
  begin
    if String(FWbemObject.LocalName) = (cDrvLetter+':') then //if this drive
    begin
      if String(FWbemObject.ConnectionState) <> 'Connected' then //if disconnected
      begin
        //try to reconnect ....
        try
          WshNetwork := CreateOleObject('WScript.Network');
          WshNetwork.MapNetworkDrive(cDrvLetter+':', String(FWbemObject.RemotePath));
        except
        end;
        Result := True;
      end
      else
      begin
        Result := True;
      end;
      Break;
    end;
    FWbemObject:=Unassigned;
  end;
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
  if FileExists('z:\test.txt') then
    Memo2.Lines.Add('exists')
  else
  begin
    Memo2.Lines.Add('connecting');

    CoInitialize(nil);
    try
      RefreshMappedDrive('Z');
    finally
      CoUninitialize;
    end;
  end;
end;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Allan_FernandesAuthor Commented:
Superb !!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.