23 Ağustos 2020 Pazar

Windows find komutu

/I seçeneği
find /i ile "case sensitive" olmadığını belirtiriz. find /n ile satır numarasını alırız.

Örnek
Bir java uygulamasının ana sınıfını görmek için şöyle yaparız.
jcmd | find /I /N "sun.tools.jconsole.JConsole"


IF "%ERRORLEVEL%" GTR "0" (
    jconsole.exe
)

IF %ERRORLEVEL% EQU 0 (
    echo Programm is running 
) 

9 Ağustos 2020 Pazar

GetDriveType metodu

Giriş
Çağrı sonucu olarak şunu döner
DRIVE_UNKNOWN - 0 - The drive type cannot be determined.

DRIVE_NO_ROOT_DIR - 1 - The root path is invalid; for example, there is no volume mounted at the specified path.

DRIVE_REMOVABLE - 2 - The drive has removable media; for example, a floppy drive, thumb drive, or flash card reader.

DRIVE_FIXED - 3 - The drive has fixed media; for example, a hard disk drive or flash drive.

DRIVE_REMOTE - 4 - The drive is a remote (network) drive.

DRIVE_CDROM - 5 - The drive is a CD-ROM drive.

DRIVE_RAMDISK - 6 - The drive is a RAM disk.
Örnek
Şöyle yaparız
#include <windows.h>
int main()
{
  wchar_t basePath[1024]{ L"" }, volName[1024]{ L"" };
  GetModuleFileName(NULL, basePath, 1024);
  GetVolumePathName(basePath, volName, 1024);

  UINT type = GetDriveType(volName);
  if (type == 2)
  {
    MessageBox(NULL, L"You are running from a flash drive (USB)",L"",MB_OK);
  }
  else
  {
    MessageBox(NULL, L"You are NOT running from a flash drive (USB)",L"", MB_OK);
  }
}

SetupDiGetClassDevs metodu

Giriş
  SetupDiGetClassDevs()
  SetupDiEnumDeviceInfo()

  SetupDiGetDeviceRegistryProperty()

çağrıları genellikle birlikte kullanılır

Örnek
Şöyle yaparız
HDEVINFO hdevinfo = SetupDiGetClassDevs(&GUID_DEVCLASS_DISKDRIVE,NULL, NULL,
  DIGCF_PRESENT);
if (hdevinfo == INVALID_HANDLE_VALUE) {
    WriteLog(L"hdevinfo is INVALID_HANDLE_VALUE");
    return USB_PROT_ERROR;
}
DWORD MemberIndex = 0;
SP_DEVINFO_DATA sp_devinfo_data;
ZeroMemory(&sp_devinfo_data, sizeof(sp_devinfo_data));
sp_devinfo_data.cbSize = sizeof(sp_devinfo_data);
while (SetupDiEnumDeviceInfo(hdevinfo, MemberIndex, &sp_devinfo_data)) {
  DWORD PropertyRegDataType;
  DWORD RequiredSize;
  TCHAR PropertyBuffer[500];
  //get the name of this device
  if (SetupDiGetDeviceRegistryProperty(hdevinfo, &sp_devinfo_data,
    SPDRP_PHYSICAL_DEVICE_OBJECT_NAME, &PropertyRegDataType, (PBYTE)&PropertyBuffer,
     sizeof(PropertyBuffer), &RequiredSize)) {
        WriteLog(L"Device name: %s", PropertyBuffer);
    ...    
    }
}