konhon

忘掉過去,展望未來。找回自我,超越自我。
逃避不一定躲的过, 面对不一定最难过, 孤单不一定不快乐, 得到不一定能长久, 失去不一定不再拥有, 可能因为某个理由而伤心难过, 但我却能找个理由让自己快乐.

Google

BlogJava 首页 新随笔 联系 聚合 管理
  203 Posts :: 0 Stories :: 61 Comments :: 0 Trackbacks

一个在普通用户下设置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.

posted on 2005-12-01 20:21 konhon 优华 阅读(556) 评论(0)  编辑  收藏 所属分类: Delphi

只有注册用户登录后才能发表评论。


网站导航: