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 優華 閱讀(574) 評論(0)  編輯  收藏 所屬分類: Delphi
          主站蜘蛛池模板: 仙游县| 六枝特区| 巩留县| 湄潭县| 高青县| 荣成市| 邵阳县| 盐亭县| 安顺市| 广州市| 潢川县| 大洼县| 西安市| 惠州市| 洞头县| 丁青县| 大悟县| 额济纳旗| 那曲县| 孙吴县| 平江县| 井研县| 克拉玛依市| 洛扎县| 宝坻区| 泗阳县| 洪雅县| 乡城县| 平昌县| 永德县| 通海县| 汉中市| 达孜县| 定边县| 安国市| 册亨县| 新乡县| 霍林郭勒市| 霞浦县| 台南县| 嘉禾县|