25 Şubat 2020 Salı

Windows cmd.exe Kabuğu

Arka Arkaya Komut Çalıştırmak İçin
Örnek
Şöyle yaparız.
command1 & command2 & command3
Paralel Komut Çalıştırmak İçin
Örnek
Şöyle yaparız.
command1 | command2 | command3
Bir Önceki Komutun Başarılı Olmasına Bakarak Çalıştırmak İçin
Şöyle yaparız.
command1 && command2 && command3
Örnek
Şöyle yaparız. command2 başarısız olsa bile command3 çalışır
command1 && command2 & command3
Redirect
Örnek
Her iki komutun stdout çıktısını nul'a göndermek için şöyle yaparız.
(command1 & command2)>nul
Örnek
Her iki komutun hem stderr hem de stdout çıktısını nul'a göndermek için şöyle yaparız.
command1 >nul >2&1 & command2
Örnek
Sadece command1'in hem stderr hem de stdout çıktısını nul'a göndermek için şöyle yaparız.
(command1 & command2)>nul >2&1
/C seçeneği - Close
İş bitince kabuk penceresini kapatır. Açıklaması şöyle.
/C      Carries out the command specified by string and then terminates
Örnek
Şöyle yaparız.
start cmd /c command1 ^& command2 ^& command3
/K seçeneği - Keep
İş bitince kabuk penceresi açık kalır. Açıklaması şöyle.
/K      Carries out the command specified by string but remains
Örnek
Şöyle yaparız.
start cmd /k command1 & command2 & command3
/S seçeneği - Strip " quote characters from command.
Örnek
Şöyle yaparız
cmd.exe /S /C " do what you like here, quotes within the outermost quotes will be 
preserved"

10 Şubat 2020 Pazartesi

CertOpenStore metodu

Örnek
Şöyle yaparız.
HCERTSTORE certStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0, 0, 0);

CreateDIBSection metodu

Örnek
Bir pencereyi HBITMAP'e yazmak için şöyle yaparız.
// Get the client size.
RECT crect;
GetClientRect(hwnd, &crect);
int width = crect.right - crect.left;
int height = crect.bottom - crect.top;

// Create DC and Bitmap.
HDC windowDC = GetDC(hwnd);
HDC memoryDC = CreateCompatibleDC(windowDC);
BITMAPINFO bitmapInfo;
ZeroMemory(&bitmapInfo, sizeof(BITMAPINFO));
bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapInfo.bmiHeader.biWidth = width;
bitmapInfo.bmiHeader.biHeight = -height;
bitmapInfo.bmiHeader.biPlanes = 1;
bitmapInfo.bmiHeader.biBitCount = 32;
bitmapInfo.bmiHeader.biCompression = BI_RGB;
bitmapInfo.bmiHeader.biSizeImage = width * height * 4;
char* pixels;
HBITMAP bitmap = CreateDIBSection(windowDC, &bitmapInfo, DIB_RGB_COLORS,
  (void**)&pixels, 0, 0);
HGDIOBJ previousObject = SelectObject(memoryDC, bitmap);

// Take the screenshot. Neither BitBlt nor PrintWindow work.
BitBlt(memoryDC, 0, 0, width, height, windowDC, 0, 0, SRCCOPY);
Daha sonra bunu dosyaya yazmak için şöyle yaparız.
// Save the image.
BITMAPFILEHEADER bitmapFileHeader;
bitmapFileHeader.bfType = 0x4D42;
bitmapFileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
std::fstream hFile("./screenshot.bmp", std::ios::out | std::ios::binary);
if(hFile.is_open())
{
  hFile.write((char*)&bitmapFileHeader, sizeof(bitmapFileHeader));
  hFile.write((char*)&bitmapInfo.bmiHeader, sizeof(bitmapInfo.bmiHeader));
  hFile.write(pixels, (((32 * width + 31) & ~31) / 8) * height);
  hFile.close();
}

// Free Resources
ReleaseDC(hwnd, windowDC);
SelectObject(memoryDC, previousObject);
DeleteDC(memoryDC);
DeleteObject(bitmap);

13 Ocak 2020 Pazartesi

Windows auditpol komutu

Audit Succes Loglamasını Durdurmak
Şöyle yaparız.
auditpol /set /subcategory:"Filtering Platform Connection" /success:disable
  /failure:enable