一个在普通用户下设置DNS的例子
unit uMain;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Registry;
type
  _STARTUPINFOW = record
    cb: DWORD;
    lpReserved: LPWSTR;
    lpDesktop: LPWSTR;
    lpTitle: LPWSTR;
    dwX: DWORD;
    dwY: DWORD;
    dwXSize: DWORD;
    dwYSize: DWORD;
    dwXCountChars: DWORD;
    dwYCountChars: DWORD;
    dwFillAttribute: DWORD;
    dwFlags: DWORD;
    wShowWindow: Word;
    cbReserved2: Word;
    lpReserved2: PByte;
    hStdInput: THandle;
    hStdOutput: THandle;
    hStdError: THandle;
  end;
  STARTUPINFOW = _STARTUPINFOW;
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    procedure DoOperation(aCmd: string);
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
function CreateProcessWithLogonW(lpUserName, lpDomain, lpPassword: LPCWSTR;
  dwLogonFlags: DWORD; lpApplicationName: LPCWSTR; lpCommandLine: LPWSTR;
  dwCreationFlags: DWORD; lpEnvironment: Pointer; lpCurrentDirectory: LPCWSTR;
  const lpStartupInfo: STARTUPINFOW; var lpProcessInformation: PROCESS_INFORMATION): BOOL; stdcall;
external advapi32 Name 'CreateProcessWithLogonW'
implementation
{$R *.dfm}
procedure DelRegCache;
begin
  with TRegistry.Create do
  try
    RootKey := HKEY_CURRENT_USER;
    DeleteKey('Software\Microsoft\Internet Explorer\TypedURLs');
  finally
    Free;
  end;
end;
procedure TForm1.DoOperation(aCmd: string);
var
  STARTUPINFO: StartupInfoW;
  ProcessInfo: TProcessInformation;
  AUser, ADomain, APass, AExe: WideString;
const
  LOGON_WITH_PROFILE = $00000001;
  LOGON_NETCREDENTIALS_ONLY = $00000002;
begin
  Screen.Cursor := crHourGlass;
  try
    FillChar(STARTUPINFO, SizeOf(StartupInfoW), #0);
    STARTUPINFO.cb := SizeOf(StartupInfoW);
    STARTUPINFO.dwFlags := STARTF_USESHOWWINDOW;
    STARTUPINFO.wShowWindow := SW_SHOW;
    AUser := 'administrator';
    APass := '123';
    ADomain := 'domain';
    AExe := aCmd;
    if not CreateProcessWithLogonW(PWideChar(AUser), PWideChar(ADomain),
      PWideChar(APass),
      LOGON_WITH_PROFILE, nil, PWideChar(AExe),
      NORMAL_PRIORITY_CLASS, nil, nil, STARTUPINFO, ProcessInfo) then
      RaiseLastOSError;
    WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
  finally
    Screen.Cursor := crDefault;
  end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
  DoOperation('netsh interface ip add dns "區域連線" 192.168.10.81 1');
  DoOperation('netsh interface ip add dns "區域連線" 202.96.128.166 2');
  Application.MessageBox('操作完成!', 'CrackNet', MB_OK + 64);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
  DelRegCache;
  DoOperation('netsh interface ip set dns "區域連線" dhcp');
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Hide;
  Button2.Click;
end;
end.