Solved

Need to program a driver to emulate the "subst" command (= to make a virtual drive "x:\" out of a folder) AND if someone displays the contents of x:\ then all filenames should be shown lowercase.

Posted on 2006-07-09
7
317 Views
Last Modified: 2010-05-18
((This question is for Windows XP and Delphi))

This is a pure academic task. I want to learn how to write my own driver and how to intercept the usual file handling/file listing.
So I don't actually care whether it is "lowercase" or "uppercase" or "all .pdf files are displayed as .exe".

Any idea?

I read already many of the other topics regarding "subst" and the following is NOT what I want:
* I don't want a delphi program that merely calls the 'subst' command (or the 'net' command) or merely changes the registry
* I don't want to write into an imagefile

I want something
1) that passes a command to Windows XP (e.g. a "file delete" should be passed to Windows XP, so that Windows XP can handle the "file delete" and thus delete the file on x:\)
AND
2) that handles a command itself (e.g. "display folder contents" should not be handled by Windows XP, thus all files can be displayed lowercase)

Any ideas are highly appreciated. If a solution is not possible in Delphi, then a solution in C++ or VB is also welcome. But Delphi is preferred,
0
Comment
Question by:knnknn
  • 2
  • 2
7 Comments
 
LVL 5

Expert Comment

by:Scay7
ID: 17069712
For creating a subst...

### start of API ###
unit Subst;
interface
uses Windows, SysUtils;

function SubstCreate(DriveLetter: Char; const Path: string): Boolean;
// create subst device. Path must be a real folder.

function SubstRemove(DriveLetter: Char): Boolean;
// destroy subst device.

function SubstQuery(DriveLetter: Char): string;
// get Path for subst device.
// return empty string if DriveLetter is not subst-device

implementation

procedure VxDCall; external kernel32 index 1;

function SubstCreate(DriveLetter: Char; const Path: string): Boolean;
var drvno: byte;
    buff: array[0..256] of char;
    FPath: string;

  function AddSlash(const Path: string): string;
  begin
    if (Path = '') or (Path[Length(Path)] <> '\') then Result:=Path+'\'
    else Result:=Path;
  end;

begin
  if Path[Length(Path)] = '\' then
    FPath:=Copy(Path,1,Length(Path)-1)
  else
    FPath:=Path;
  if Win32Platform = VER_PLATFORM_WIN32_NT then begin
    buff[0]:=DriveLetter;
    buff[1]:=':';
    buff[2]:=#0;
    Result:=DefineDosDevice(0,buff,PChar(Path));
  end else begin
    FPath:=ExtractShortPathName(FPath);
    if FPath <> '' then begin
      drvno:=Ord(UpperCase(DriveLetter)[1])-64;
      StrPCopy(buff,FPath);
      asm
         pushad
         push    es
         xor     ebx, ebx
         mov     bh,0
         mov     bl,drvno
         lea     edx,buff
         push    0       //ECX (unused)
         push    71AAh
         push    2A0010h
         call    VxDCall
         pop     es
         popad
      end;
    end;
    Result:=ANSIUpperCase(AddSlash(SubstQuery(DriveLetter))) = ANSIUpperCase(AddSlash(Path));
  end;
end;

function SubstRemove(DriveLetter: Char): Boolean;
var drvno: byte;
    Drive,Path: string;
begin
  if Win32Platform = VER_PLATFORM_WIN32_NT then begin
    SetLength(Drive,3);
    Drive[1]:=DriveLetter;
    Drive[2]:=':';
    Drive[3]:=#0;
    Path:=SubstQuery(DriveLetter);
    Result:=DefineDosDevice(DDD_REMOVE_DEFINITION,PChar(Drive),PChar(Path));
  end else begin
    drvno:=Ord(UpperCase(DriveLetter)[1])-64;
    asm
       pushad
       push    es
       xor     ebx, ebx
       mov     bh,1
       mov     bl,drvno
       push    0       //ECX (unused)
       push    71AAh
       push    2A0010h
       call    VxDCall
       pop     es
       popad
    end;
    Result:=SubstQuery(DriveLetter) = '';
  end;
end;

function SubstQuery(DriveLetter: Char): string;
var drvno: byte;
    buff: array[0..256] of char;
    lbuff: array[0..256] of char;
begin
  if Win32Platform = VER_PLATFORM_WIN32_NT then begin
    lbuff[0]:=DriveLetter;
    lbuff[1]:=':';
    lbuff[2]:=#0;
    buff[0]:=#0;
    QueryDosDevice(lbuff,buff,256);
    Result:=StrPas(buff);
    if Copy(Result,1,4) = '\??\' then
      Result:=Copy(Result,5,Length(Result))
    else
      Result:='';
  end else begin
    drvno:=Ord(UpperCase(DriveLetter)[1])-64;
    buff[0]:=#0;
    asm
       pushad
       push    es
       xor     ebx, ebx
       mov     bh,2
       mov     bl,drvno
       lea     edx,buff
       push    0       //ECX (unused)
       push    71AAh
       push    2A0010h
       call    VxDCall
       pop     es
       popad
    end;
    Result:=StrPas(buff);
    if Result = '' then Exit;
    // convert to longfilename
    asm
       // expand long path
       pushad
       push    ds
       push    es
       xor     ebx, ebx
       lea     esi, buff
       lea     edi, lbuff
       mov     ecx,0
       mov     cl, 2
       mov     ch, 0
       push    ECX
       push    7160h
       push    2A0010h
       call    VxDCall
       pop     es
       pop     ds
       popad
    end;
    Result:=StrPas(lbuff);
  end;
end;

end.
### end of API ###



For list of dirs...

var
  Rec: TSearchRec;
begin
  if FindFirst('c:\*.*', faAnyFile, Rec) =0 then  //search for any file on C:
  repeat
    ListBox1.Items.Add(Rec.Name);  //list on listbox/memo etc...
  until FindNext(Rec) <> 0;
  FindClose(Rec);
end;



Hope this helps

Peace Scay7
0
 

Author Comment

by:knnknn
ID: 17088439
No, that doesn't help. Sorry. It merely calls the subst command and is not related to my problem.
0
 
LVL 6

Expert Comment

by:House_of_Dexter
ID: 17093471
Sounds like you want to Hook into the Windows Shell...using Namespace Extensions


check out this site http://www.torry.ru/pages.php?id=515 for components that are already doing that...

0
 

Author Comment

by:knnknn
ID: 17163302
I am not sure whether it could be called "Hook into windows shell" what I want. I want to create a new drive letter ("x:\") that lists what other drives list ("c:\" + "d:\")

From reading the description of "Namespace Extensions" ($800) I don't think this is what that delphi code is doing:

* Create an extra folder in Explorer
* function as a protocol handler for Internet Explorer (think ftp, http)
* stand-alone file viewer that can browse files in-place like regular file system folders

Also none of the other delphi components even deal with creating a new drive letter.
0
 
LVL 6

Accepted Solution

by:
House_of_Dexter earned 450 total points
ID: 17164737
If you want to create a new drive letter and tie into that drive letter...then Namespace Extension is what you want...Namespaces are nothing more than virtual drives and folders...allowing you to handle whats in the Extension...i.e. Zip and Cab Files look like folders and work like folders because they hook into the  Windows Shell through Namespace Extensions...If this is not what you want...then you need to better describe the system you are invisioning...

If you can read C++ code...check out this site...

http://www.codeproject.com/shell/namespcextguide1.asp

for more info on Namespace Extension and Shell programming...
http://www.codeproject.com/shell/
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

20 Experts available now in Live!

Get 1:1 Help Now