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
323 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Downloading email attachments 2 74
Delphi inherited method 6 70
Delphi and Access based Enumeration 9 64
DBCtrlGrid, Delphi, Scroll 8 15
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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