[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
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
Medium Priority
?
352 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1800 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

650 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