+62 812-1171-5379 Fast Respond

Tips dan Trik Delphi - Windows

Shutdown Booting Logoff windows / Windows / Windows / Delphi 7 - XE
// reboot windows
      ExitWindowsEx(EWX_REBOOT,0);
      // shut down windows
      ExitWindowsEx(EWX_SHUTDOWN,0);
      // logoff andprompt for login
      ExitWindowsEx(EWX_LOGOFF,0);

Melihat nama komputer dari IP / Windows / Windows / Delphi 7 - XE
uses winsock; 
function IPAddrToName(IPAddr : string): string;
var
    SockAddrIn: TSockAddrIn;
    HostEnt: PHostEnt;
    WSAData: TWSAData;
begin
    WSAStartup($101, WSAData);
    SockAddrIn.sin_addr.s_addr:= inet_addr(PChar(IPAddr));
    HostEnt:= gethostbyaddr(@SockAddrIn.sin_addr.S_addr, 4, AF_INET);
    if HostEnt<>nil then
    begin
        result:=StrPas(Hostent^.h_name)
    end else
    begin
        result:='';
    end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
     // untuk tes lihat IP anda pada Lan
     Label1.Caption := IPAddrToName('192.168.0.2');
end;

Empty ricycle bin windows / Windows / Windows / Delphi 7 - XE
procedure EmptyRecycleBin;
const
    SHERB_NOCONFIRMATION = $00000001;
    SHERB_NOPROGRESSUI = $00000002;
    SHERB_NOSOUND = $00000004;
type
    TSHEmptyRecycleBin = function (Wnd: HWND;
    LPCTSTR: PChar;
    DWORD: Word): integer; stdcall;
var
    SHEmptyRecycleBin:TSHEmptyRecycleBin;
    LibHandle: THandle;
begin
    LibHandle := LoadLibrary(PChar('Shell32.dll'));
    if LibHandle <> 0 then
        @SHEmptyRecycleBin := GetProcAddress(LibHandle, 'SHEmptyRecycleBinA')
    else
    begin
        MessageDlg('Failed to load Shell32.dll.', mtError, [mbOK], 0);
        Exit;
    end;

if @SHEmptyRecycleBin <> nil then
    SHEmptyRecycleBin(Application.Handle, '', SHERB_NOCONFIRMATION or SHERB_NOPROGRESSUI or SHERB_NOSOUND);
    FreeLibrary(LibHandle);
    @SHEmptyRecycleBin := nil;
end;

Menampilkan mapdrive windows / Windows / Windows / Delphi 7 - XE

function GetNetworkDriveMappings(SList:TStrings):Integer;
var
    I:Char;
    ThePath:string;
    MaxNetPathLen:DWord;
begin
    SList.Clear;
    MaxNetPathLen:=MAX_PATH;
    SetLength(ThePath,MAX_PATH);
    for I := 'A' to 'Z' do
       if WNetGetConnection(PChar(''+I+':'),PChar(ThePath), MaxNetPathLen)=NO_ERROR then
          SList.Add(I+': '+ThePath);
    Result := SList.Count;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
     GetNetworkDriveMappings(ListBox1.Items);
end;

                                        
Menampilkna dan menyembunyikan tasbar windows / Windows / Windows / Delphi 7 - XE
procedure hideTaskbar;
var
    wndHandle :THandle;
    wndClass : array[0..50] of Char;
begin
    StrPCopy(@wndClass[0], 'Shell_TrayWnd');
    wndHandle := FindWindow(@wndClass[0], nil);
    ShowWindow(wndHandle, SW_HIDE); // Sakla
end;

procedure showTaskbar;
var
  wndHandle :THandle;
  wndClass : array[0..50] of Char;
begin
    StrPCopy(@wndClass[0], 'Shell_TrayWnd');
    wndHandle := FindWindow(@wndClass[0], nil);
    ShowWindow(wndHandle, SW_RESTORE); // Göster
end;

Meminimize semua windows aktif / Windows / Windows / Delphi 7 - XE
procedure TForm1.Minimize_all_windows;
var
    hnd : HWnd;
Begin
    hnd := handle;
    while hnd > 0 do
    begin
        if IsWindowVisible(hnd) then
           Postmessage(hnd, WM_SYSCOMMAND,SC_MINIMIZE,0);
        hnd := GetnextWindow(hnd, GW_HWNDNEXT);
    end;
End;

Mengganti IP komputer / Windows / Windows / Delphi 7 - XE
 uses ActiveX, Comobj, Winsock;
function SetComputerName(AComputerName: string): Boolean;
var
  ComputerName: array[0..MAX_COMPUTERNAME_LENGTH + 1] of Char;
  Size: Cardinal;
begin
  StrPCopy(ComputerName, AComputerName);
  Result := Windows.SetComputerName(ComputerName);
end;

Mengganti nama komputer / Windows / Windows / Delphi 7 - XE
 uses ActiveX, Comobj, Winsock;
function SetComputerName(AComputerName: string): Boolean;
var
  ComputerName: array[0..MAX_COMPUTERNAME_LENGTH + 1] of Char;
  Size: Cardinal;
begin
  StrPCopy(ComputerName, AComputerName);
  Result := Windows.SetComputerName(ComputerName);
end;

Mengetahui macAdress komputer windows / Windows / Windows / Delphi 7 - XE


function TForm1.GetMACAdress: string;
var
  NCB: PNCB;
  Adapter: PAdapterStatus;

  URetCode: PChar;
  RetCode: char;
  I: integer;
  Lenum: PlanaEnum;
  _SystemID: string;
  TMPSTR: string;
begin
  Result    := '';
  _SystemID := '';
  Getmem(NCB, SizeOf(TNCB));
  Fillchar(NCB^, SizeOf(TNCB), 0);

  Getmem(Lenum, SizeOf(TLanaEnum));
  Fillchar(Lenum^, SizeOf(TLanaEnum), 0);

  Getmem(Adapter, SizeOf(TAdapterStatus));
  Fillchar(Adapter^, SizeOf(TAdapterStatus), 0);

  Lenum.Length    := chr(0);
  NCB.ncb_command := chr(NCBENUM);
  NCB.ncb_buffer  := Pointer(Lenum);
  NCB.ncb_length  := SizeOf(Lenum);
  RetCode         := Netbios(NCB);

  i := 0;
  repeat
    Fillchar(NCB^, SizeOf(TNCB), 0);
    Ncb.ncb_command  := chr(NCBRESET);
    Ncb.ncb_lana_num := lenum.lana[I];
    RetCode          := Netbios(Ncb);

    Fillchar(NCB^, SizeOf(TNCB), 0);
    Ncb.ncb_command  := chr(NCBASTAT);
    Ncb.ncb_lana_num := lenum.lana[I];
    // Must be 16
    Ncb.ncb_callname := '*               ';

    Ncb.ncb_buffer := Pointer(Adapter);

    Ncb.ncb_length := SizeOf(TAdapterStatus);
    RetCode        := Netbios(Ncb);
    //---- calc _systemId from mac-address[2-5] XOR mac-address[1]...
    if (RetCode = chr(0)) or (RetCode = chr(6)) then
    begin
      _SystemId := IntToHex(Ord(Adapter.adapter_address[0]), 2) + '-' +
        IntToHex(Ord(Adapter.adapter_address[1]), 2) + '-' +
        IntToHex(Ord(Adapter.adapter_address[2]), 2) + '-' +
        IntToHex(Ord(Adapter.adapter_address[3]), 2) + '-' +
        IntToHex(Ord(Adapter.adapter_address[4]), 2) + '-' +
        IntToHex(Ord(Adapter.adapter_address[5]), 2);
    end;
    Inc(i);
  until (I >= Ord(Lenum.Length)) or (_SystemID <> '00-00-00-00-00-00');
  FreeMem(NCB);
  FreeMem(Adapter);
  FreeMem(Lenum);
  GetMacAdress := _SystemID;
end;

Mendeteksi IP Lokal komputer windows / Windows / Windows / Delphi 7 - XE


Gunakan Uses Winsock;
function LocalIP: string;
type
  TaPInAddr = array[0..10] of PInAddr;
  PaPInAddr = ^TaPInAddr;
var
  phe: PHostEnt;
  pptr: PaPInAddr;
  Buffer: array[0..63] of Char;
  I: Integer;
  GInitData: TWSAData;
begin
    WSAStartup($101, GInitData);
    Result := '';
    GetHostName(Buffer, SizeOf(Buffer));
    phe := GetHostByName(buffer);
    if phe = nil then Exit;
    pPtr := PaPInAddr(phe^.h_addr_list);
    I := 0;
    while pPtr^[I] <> nil do
    begin
         Result := inet_ntoa(pptr^[I]^);
         Inc(I);
    end;
    WSACleanup;
end;