Einzelnen Beitrag anzeigen

berens

Registriert seit: 3. Sep 2004
431 Beiträge
 
Delphi 2010 Professional
 
#5

Re: Laufwerk GUID Laufwerksbuchstabe auslesen / unmount

  Alt 15. Jul 2009, 11:56
Also damit klappt es, ich will das Ganze noch als Kommandozeilen Parameter erweitern, das ist ja aber kein Problem.

Meine Frage: Stimmt das mit den Variablen x und a? Ich glaube nicht ganz, aber atm funktioniert es :/

Delphi-Quellcode:
function GetVolumePathNamesForVolumeName(lpszVolumeName, lpszVolumePathNames: LPCSTR;
  cchBufferLength: DWORD; var lpcchReturnLength: DWORD): BOOL; stdcall;

Delphi-Quellcode:
program unmount;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  windows,
  ShellAPI,
  ShellObjExtended in 'ShellObjExtended.pas';

var
  t: string;
  x: array[0..MAX_PATH] of char;
  a: Cardinal;


begin
  try
    if ParamCount < 1 then begin
      writeln('Unmounts a MountPoint by its VolumeName (GUID)');
      writeln('USAGE: unmount GUID');
      writeln('EXAMPLE: unmount \\?\Volume{faf095ab-31d3-11de-92c2-001d09d96fe8}\');
      writeln(' ');
      writeln('You can determine your drive''s GUID by the command MOUNTVOL');
      exit;
    end;
    a := MAX_PATH;
    GetVolumePathNamesForVolumeName(pchar(ParamStr(1)), @x, MAX_PATH, a);
    ShellExecute(0, 'open', 'mountvol', pchar(x + ' /D'), '', SW_HIDE);
  except
    on E:Exception do
      Writeln(E.Classname, ': ', E.Message);
  end;
end.
Delphi-Quellcode:
unit ShellObjExtended;

interface

uses
  Windows, Messages, ShlObj;

const
  IID_IColumnProvider: TGUID = (
    D1: $E8025004; D2: $1C42; D3: $11D2; D4: ($BE, $2C, $0, $A0, $C9, $A8, $3D, $A1));

  SID_IColumnProvider = '{E8025004-1C42-11D2-BE2C-00A0C9A83DA1}';

  FILE_FLAG_OPEN_REPARSE_POINT = $00200000;
                                  
const
  MAX_COLUMN_NAME_LEN = 80;
  MAX_COLUMN_DESC_LEN = 128;

type
  HANDLE = Windows.THandle;

  SHCOLUMNINFO = packed record
    scid: SHCOLUMNID;
    vt: integer;
    fmt: DWORD;
    cChars: UINT;
    csFlags: dword;
    wszTitle: array[0..MAX_COLUMN_NAME_LEN - 1] of WideChar;
    wszDescription: array[0..MAX_COLUMN_DESC_LEN - 1] of WideChar;
  end;
  LPSHCOLUMNINFO = ^SHCOLUMNINFO;

  TShColumnInfo = SHCOLUMNINFO;
  PShColumnInfo = LPSHCOLUMNINFO;

  SHCOLUMNINIT = packed record
    dwFlags: ulong;
    dwReserved: ulong;
    wszFolder: array[0..MAX_PATH - 1] of WideChar;
  end;
  LPSHCOLUMNINIT = ^SHCOLUMNINIT;

  TShColumnInit = SHCOLUMNINIT;
  PShColumnInit = LPSHCOLUMNINIT;

const
  SHCDF_UPDATEITEM = $00000001;

type
  SHCOLUMNDATA = packed record
    dwFlags: ULONG;
    dwFileAttributes: DWord;
    dwReserved: ULONG;
    pwszExt: PWideChar;
    wszFile: array[0..MAX_PATH - 1] of WideChar
  end;
  LPSHCOLUMNDATA = ^SHCOLUMNDATA;

  TShColumnData = SHCOLUMNDATA;
  PShColumnData = LPSHCOLUMNDATA;

  IColumnProvider = interface
    [SID_IColumnProvider]
    function Initialize(psci: PSHCOLUMNINIT): HResult; stdcall;
    function GetColumnInfo(dwIndex: DWORD; psci: PSHCOLUMNINFO): HResult; stdcall;
    function GetItemData(pscid: PSHCOLUMNID; pscd: PSHCOLUMNDATA; pvarData: Variant): HResult; stdcall;
  end;

// From Winbase.h
function GetVolumePathNameA(lpszFileName: LPCSTR; lpszVolumePathName: LPSTR;
  cchBufferLength: DWORD): BOOL; stdcall;
{$EXTERNALSYM GetVolumePathNameA}
function GetVolumePathNameW(lpszFileName: LPCWSTR; lpszVolumePathName: LPWSTR;
  cchBufferLength: DWORD): BOOL; stdcall;
{$EXTERNALSYM GetVolumePathNameW}
function GetVolumePathName(lpszFileName: LPCSTR; lpszVolumePathName: LPSTR;
  cchBufferLength: DWORD): BOOL; stdcall;
{$EXTERNALSYM GetVolumePathName}

function GetVolumePathNamesForVolumeNameA(lpszVolumeName, lpszVolumePathNames: LPCSTR;
  cchBufferLength: DWORD; var lpcchReturnLength: DWORD): BOOL; stdcall;
{$EXTERNALSYM GetVolumePathNamesForVolumeNameA}
function GetVolumePathNamesForVolumeNameW(lpszVolumeName, lpszVolumePathNames: LPCWSTR;
  cchBufferLength: DWORD; var lpcchReturnLength: DWORD): BOOL; stdcall;
{$EXTERNALSYM GetVolumePathNamesForVolumeNameW}
function GetVolumePathNamesForVolumeName(lpszVolumeName, lpszVolumePathNames: LPCSTR;
  cchBufferLength: DWORD; var lpcchReturnLength: DWORD): BOOL; stdcall;
{$EXTERNALSYM GetVolumePathNamesForVolumeName}

function GetVolumeNameForVolumeMountPointA(lpszVolumeMountPoint: LPCSTR;
  lpszVolumeName: LPSTR; cchBufferLength: DWORD): BOOL; stdcall;
{$EXTERNALSYM GetVolumeNameForVolumeMountPointA}
function GetVolumeNameForVolumeMountPointW(lpszVolumeMountPoint: LPCWSTR;
  lpszVolumeName: LPWSTR; cchBufferLength: DWORD): BOOL; stdcall;
{$EXTERNALSYM GetVolumeNameForVolumeMountPointW}
function GetVolumeNameForVolumeMountPoint(lpszVolumeMountPoint: LPCSTR;
  lpszVolumeName: LPSTR; cchBufferLength: DWORD): BOOL; stdcall;
{$EXTERNALSYM GetVolumeNameForVolumeMountPoint}

function FindFirstVolumeA(lpszVolumeName: LPSTR; cchBufferLength: DWORD): HANDLE; stdcall;
{$EXTERNALSYM FindFirstVolumeA}
function FindFirstVolumeW(lpszVolumeName: LPWSTR; cchBufferLength: DWORD): HANDLE; stdcall;
{$EXTERNALSYM FindFirstVolumeW}
function FindFirstVolume(lpszVolumeName: LPSTR; cchBufferLength: DWORD): HANDLE; stdcall;
{$EXTERNALSYM FindFirstVolume}

function FindNextVolumeA(hFindVolume: HANDLE; lpszVolumeName: LPSTR;
  cchBufferLength: DWORD): BOOL; stdcall;
{$EXTERNALSYM FindNextVolumeA}
function FindNextVolumeW(hFindVolume: HANDLE; lpszVolumeName: LPWSTR;
  cchBufferLength: DWORD): BOOL; stdcall;
{$EXTERNALSYM FindNextVolumeW}
function FindNextVolume(hFindVolume: HANDLE; lpszVolumeName: LPSTR;
  cchBufferLength: DWORD): BOOL; stdcall;
{$EXTERNALSYM FindNextVolume}

function FindVolumeClose(hFindVolume: HANDLE): BOOL; stdcall;
{$EXTERNALSYM FindVolumeClose}

function FindFirstVolumeMountPointA(lpszRootPathName: LPCSTR;
  lpszVolumeMountPoint: LPSTR; cchBufferLength: DWORD): HANDLE; stdcall;
{$EXTERNALSYM FindFirstVolumeMountPointA}
function FindFirstVolumeMountPointW(lpszRootPathName: LPCWSTR;
  lpszVolumeMountPoint: LPWSTR; cchBufferLength: DWORD): HANDLE; stdcall;
{$EXTERNALSYM FindFirstVolumeMountPointW}
function FindFirstVolumeMountPoint(lpszRootPathName: LPCSTR;
  lpszVolumeMountPoint: LPSTR; cchBufferLength: DWORD): HANDLE; stdcall;
{$EXTERNALSYM FindFirstVolumeMountPoint}

function FindNextVolumeMountPointA(hFindVolumeMountPoint: HANDLE;
  lpszVolumeMountPoint: LPSTR; cchBufferLength: DWORD): BOOL; stdcall;
{$EXTERNALSYM FindNextVolumeMountPointA}
function FindNextVolumeMountPointW(hFindVolumeMountPoint: HANDLE;
  lpszVolumeMountPoint: LPWSTR; cchBufferLength: DWORD): BOOL; stdcall;
{$EXTERNALSYM FindNextVolumeMountPointW}
function FindNextVolumeMountPoint(hFindVolumeMountPoint: HANDLE;
  lpszVolumeMountPoint: LPSTR; cchBufferLength: DWORD): BOOL; stdcall;
{$EXTERNALSYM FindNextVolumeMountPoint}

function FindVolumeMountPointClose(hFindVolumeMountPoint: HANDLE): BOOL; stdcall;
{$EXTERNALSYM FindVolumeMountPointClose}

implementation

function GetVolumePathNameA; external kernel32 name 'GetVolumePathNameA';
function GetVolumePathNameW; external kernel32 name 'GetVolumePathNameW';
function GetVolumePathName; external kernel32 name 'GetVolumePathNameA';

function GetVolumePathNamesForVolumeNameA; external kernel32 name 'GetVolumePathNamesForVolumeNameA';
function GetVolumePathNamesForVolumeNameW; external kernel32 name 'GetVolumePathNamesForVolumeNameW';
function GetVolumePathNamesForVolumeName; external kernel32 name 'GetVolumePathNamesForVolumeNameA';

function GetVolumeNameForVolumeMountPointA; external kernel32 name 'GetVolumeNameForVolumeMountPointA';
function GetVolumeNameForVolumeMountPointW; external kernel32 name 'GetVolumeNameForVolumeMountPointW';
function GetVolumeNameForVolumeMountPoint; external kernel32 name 'GetVolumeNameForVolumeMountPointA';

function FindFirstVolumeA; external kernel32 name 'FindFirstVolumeA';
function FindFirstVolumeW; external kernel32 name 'FindFirstVolumeW';
function FindFirstVolume; external kernel32 name 'FindFirstVolumeA';

function FindNextVolumeA; external kernel32 name 'FindNextVolumeA';
function FindNextVolumeW; external kernel32 name 'FindNextVolumeW';
function FindNextVolume; external kernel32 name 'FindNextVolumeA';

function FindVolumeClose; external kernel32 name 'FindVolumeClose';

function FindFirstVolumeMountPointA; external kernel32 name 'FindFirstVolumeMountPointA';
function FindFirstVolumeMountPointW; external kernel32 name 'FindFirstVolumeMountPointW';
function FindFirstVolumeMountPoint; external kernel32 name 'FindFirstVolumeMountPointA';

function FindNextVolumeMountPointA; external kernel32 name 'FindNextVolumeMountPointA';
function FindNextVolumeMountPointW; external kernel32 name 'FindNextVolumeMountPointW';
function FindNextVolumeMountPoint; external kernel32 name 'FindNextVolumeMountPointA';

function FindVolumeMountPointClose; external kernel32 name 'FindVolumeMountPointClose';

end.
  Mit Zitat antworten Zitat