Delphi modifies computer IP

xiaoxiao2021-03-06  62

Execute the DOS command NETSH with Winexec or Shellexecute, you can modify it. Also or modify the registry, I don't know if it is feasible?

Moderator Note: Netsh is a command line program for Win2K, which can be used to dynamically set IP addresses. Such as:

Netsh-C Interface IP Add Address "Local Connection" 192.168.1.105 255.255.255.0

For more information on this command, please refer to:

http://www.yesky.com/20030410/1662582.shtml

Modifying the registry can only modify the DNS and can take effect immediately. If you modify the IP address, you will need to restart the system before you can take effect. Therefore, the current found is probably only running netsh commands in the DOS environment. Here is a good program

Lhaipset.rar.

Registration Type Operation

Unit minireg; {---------------------------------------------- -------------------------------------------------- --- Function Examples: Procedure TFORM1.BUTTON1CLICK (Sender: Tobject); VAR BA1, BA2: Array Of Byte; N: Integer; S: String; D: Cardinal; Begin SetLENGTH (BA1, 10); for N: = 0 to 9 do ba1 [n]: = byte (n); RegSetString (HKEY_CURRENT_USER, 'Software / My Company / Test / foo / bar / TestString', 'TestMe'); RegSetExpandString (HKEY_CURRENT_USER, 'Software / My Company / Test / foo / bar / TestExpandString ','% SystemRoot% / Test '); RegSetMultiString (HKEY_CURRENT_USER,' Software / My Company / Test / foo / bar / TestMultiString ',' String1 '# 0'String2' # 0'String3 '); RegSetDword (HKEY_CURRENT_USER, 'Software / My Company / Test / foo / bar / TestDword', 7); RegSetBinary (HKEY_CURRENT_USER, 'Software / My Company / Test / foo / bar / TestBinary', ba1); To set the default value for a key, end the key name with a '/': regsetstring HKEY_CURRENT_USER, 'Software / My Company / Test /', 'Default Value'); RegGetString (HKEY_CURRENT_USER, 'Software / My Company / Test / foo / bar / TestString', s); RegGetMultiString (HKEY_CURRENT_USER, 'Software / My Company / Test / foo / bar / TestMultiString ', s); RegGetExpandString (HKEY_CURRENT_USER,' Software / My Company / Test / foo / bar / TestExpandString ', s); RegGetAnyString (HKEY_CURRENT_USER,' Software / My Company / Test / foo / bar / TestmultiString ', S, StringType); RegsetanyString (HKEY_CURRENT_USER,' Software / My Company / Test / Foo / Bar / TestMultiString ', S, StringType);

RegGetDWORD (HKEY_CURRENT_USER, 'Software / My Company / Test / foo / bar / TestDword', d); RegGetBinary (HKEY_CURRENT_USER, 'Software / My Company / Test / foo / bar / TestBinary', s); SetLength (ba2, Length ( s)); for n: = 1 to Length (s) DO ba2 [N-1]: = byte (s [n]); button1.caption: = INTOSTR (Length (ba2)); if regkeyexists (HKEY_CURRENT_USER, ' Software / My Company / Test / foo ') then if RegValueExists (HKEY_CURRENT_USER,' Software / My Company / Test / foo / bar / TestBinary ') then MessageBox (GetActiveWindow,' OK ',' OK ', MB_OK); RegDelValue (HKEY_CURRENT_USER , 'Software / My Company / Test / foo / bar / TestString'); RegDelKey (HKEY_CURRENT_USER, 'Software / My Company / Test / foo / bar'); RegDelKey (HKEY_CURRENT_USER, 'Software / My Company / Test / foo') ; RegDelKey (HKEY_CURRENT_USER, 'Software / My Company / Test'); RegDelKey (HKEY_CURRENT_USER, 'Software / My Company'); if RegEnumKeys (HKEY_CURRENT_USER, 'Software / My Company', s) then ListBox1.Text: = s; if RegenumValues ​​(HKEY_CU RRENT_USER, 'Software / My Company', s) then ListBox1.Text: = s; if RegConnect ( '// server1', HKEY_LOCAL_MACHINE, RemoteKey) then begin RegGetString (RemoteKey, 'Software / My Company / Test / foo / bar / Teststring ', s); regdisconnect (transotekey); end; end; -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- --------------} Interface Uses Windows; Function RegsetString (Rootkey: HKey; Name: String; Value: String): Boolean; Function RegsetMultiTRING (rootkey: hkey; name): String; value: hkey; name: string; value: String): boolean;

function RegSetExpandString (RootKey: HKEY; Name: String; Value: String): boolean; function RegSetDWORD (RootKey: HKEY; Name: String; Value: Cardinal): boolean; function RegSetBinary (RootKey: HKEY; Name: String; Value: Array of Byte): boolean; function RegGetString (RootKey: HKEY; Name: String; Var Value: String): boolean; function RegGetMultiString (RootKey: HKEY; Name: String; Var Value: String): boolean; function RegGetExpandString (RootKey: HKEY ; Name: String; Var Value: String): boolean; function RegGetAnyString (RootKey: HKEY; Name: String; Var Value: String; Var ValueType: Cardinal): boolean; function RegSetAnyString (RootKey: HKEY; Name: String; Value: String; ValueType: Cardinal): boolean; function RegGetDWORD (RootKey: HKEY; Name: String; Var Value: Cardinal): boolean; function RegGetBinary (RootKey: HKEY; Name: String; Var Value: String): boolean; function RegGetValueType ( Rootkey: hkey; name: string; var value: cardinal: boolean; function RegValueExists (RootKey: HKEY; Name: String): boolean; function RegKeyExists (RootKey: HKEY; Name: String): boolean; function RegDelValue (RootKey: HKEY; Name: String): boolean; function RegDelKey (RootKey: HKEY; Name: String): boolean; function RegDelKeyEx (RootKey: HKEY; Name: String; WithSubKeys: Boolean = True): boolean; function RegConnect (MachineName: String; RootKey: HKEY; var RemoteKey: HKEY): boolean; function RegDisconnect (RemoteKey: HKEY ): boolean; function RegEnumKeys (RootKey: HKEY; Name: String; var KeyList: String): boolean; function RegEnumValues ​​(RootKey: HKEY; Name: String; var ValueList: String): boolean; implementation function LastPos (Needle: Char;

Haystack: String): integer; begin for Result: = Length (Haystack) downto 1 do if Haystack [Result] = Needle then Break; end; function RegConnect (MachineName: String; RootKey: HKEY; var RemoteKey: HKEY): boolean; begin Result: = (RegConnectRegistry (PChar (MachineName), RootKey, RemoteKey) = ERROR_SUCCESS); end; function RegDisconnect (RemoteKey: HKEY): boolean; begin Result: = (RegCloseKey (RemoteKey) = ERROR_SUCCESS); end; function RegSetValue ( RootKey: hkey; value: cardinal: boolean; var subkey: string; n: = false; begin results; htemp: hkey; begin result: = false; n: = LastPos ('/', Name); if n> 0 Then Begin Subkey: = COPY (Name, 1, N - 1); if RegcreateKeyex (RootKey, Pchar (Subkey), 0, NIL, REG_OPTION_NON_VOLATILE, Key_Write, NIL, HTEMP, @dispo) = error_success the beginning of subsser: = copy (name, n 1, l ENGTH (NAME) - N); if Subkey = '' Then Result: = (HTEMP, NIL, 0, VALTYPE, PVAL, VALSIZE) = Error_Success) Else Result: = (RegSetValueex (htemp, pchar (Subkey), 0 , ValType, pVal, ValSize) = ERROR_SUCCESS); RegCloseKey (hTemp); end; end; end; function RegGetValue (RootKey: HKEY; Name: String; ValType: Cardinal; var pVal: Pointer; var ValSize: Cardinal): boolean; Var Subkey: String; N: Integer; htemp: hkey; buf: PoInter; buffsize: cardinal; pkey: pchar; sult: = false; n: = lastpos ('/', name);

IF N> 0 THEN BEGIN Subkey: = Copy (Name, 1, N - 1); if RegopenKeyex (RootKey, Pchar (Subkey), 0, Key_Read, HTEMP = Error_Success Then Begin Subkey: = Copy (Name, N 1 Length (name) - n); if Subkey = '' Then Pkey: = nil else pkey: = pchar (subkey); if RegQueryValueex (htemp, pkey, nil, @MYVALTYPE, NIL, @Bufsize) = Error_Success The Begin getMem (Buf, BufSize); if RegQueryValueEx (hTemp, PKey, nil, @MyValType, Buf, @BufSize) = ERROR_SUCCESS then begin if ValType = MyValType then begin pVal: = Buf; ValSize: = BufSize; Result: = True; end else begin FreeMem (Buf); end; end else begin FreeMem (Buf); end; end; RegCloseKey (hTemp); end; end; end; function RegSetAnyString (RootKey: HKEY; Name: String; Value: String; ValueType: Cardinal) : Boolean; Begin Case Valuetype of Reg_SZ, REG_EXPAND_SZ: Result: = RegSetValue (ROO TKEY, NAME, VALUETYPE, PCHAR (Value # 0), Length (Value) 1); REG_MULTI_SZ: Result: = RegSetValue (rootkey, name, valueetype, pchar (value # 0 # 0), Length (Value) 2); Else Result: = FALSE; End; End; Function RegsetString (rootkey: hkey; name: string; value: string): boolean; begin result: = regSetValue (rootkey, name, reg_sz, pchar (value # 0) Length (value) 1); end; function regsetMultiTRING (rootkey: hkey; name: string; value: string): boolean; begin result: = regSetValue (rootkey, name, reg_multi_sz, pchar (value # 0 # 0) , Length (Value)

2); End; function regseTexpandstring (rootkey: hkey; name: string; value: string): boolean; begin result: = regSetValue (rotkey, name, reg_expand_sz, pchar (value # 0), Length (Value) 1) ; end; function RegSetDword (RootKey: HKEY; Name: String; Value: Cardinal): boolean; begin Result: = RegSetValue (RootKey, Name, REG_DWORD, @Value, SizeOf (Cardinal)); end; function RegSetBinary (RootKey: HKEY Name: String; Value: Array Of Byte): Boolean; Begin Result: = RegSetValue (Rootkey, Name, Reg_binary, @Value [Low (Value)], Length (Value)); End; Function ReggetString (Rootkey: HKey; Name: string; var value: string: boolean; var buf: Pointer; buffsize: cardinal; begin result: = false; value: = '; if reggetvalue (rootkey, name, regg_sz, buf, bufsize) THEN BEGIN DEC ( BUFSIZE); setlength (value, bufsize); if bufsize> 0 Then Move (buf ^, value [1], bufsize); FreeMem (BUF); Result: = true; end; end; function; name: string; var value: string: boolean; var buf: Pointer; buffsize: cardinal; begin result: = false; value: = '; if ReggetValue (RootKey, Name, REG_MULTI_SZ, BUF, BUFSIZE) THEN Begin Dec (BufSize); SetLength (Value, BufSize); if Bufsize> 0 Then Move (buf ^, value [1], bufsize; FreeMem (BUF); Result : = True; end; end; function reggetexpandstring (rootkey: hkey; name: string; var value: string): boolean; var buf: Pointer; buffsize: cardinal; begin result: = false

Value: = ''; if ReggetValue (RootKey, Name, REG_EXPAND_SZ, BUF, BUFSIZE) THEN DEC (BUFSIZE); SetLength (value, bufsize); if bufsize> 0 Then Move (buf ^, value [1], bufsize) FreeMem (buf); result: = true; end; end; function reggetanyString (rootkey: hkey; name: string; var value: string; var valueety: cardinal: boolean; var buf: Pointer; bufsize: cardinal; Bok: boolean; begin Result: = False; Value: = ''; if RegGetValueType (Rootkey, Name, ValueType) then begin case ValueType of REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ: bOK: = RegGetValue (RootKey, Name, ValueType, Buf, BufSize); Else Bok: = false; End; if Bok Then Begin Dec (BufSize); SetLength (Value, BufSize); if Bufsize> 0 Then Move (buf ^, value [1], bufsize); FreeMem (BUF); Result: = True; end; end; end; function reggetdword (rootkey: hkey; name: stri Ng; var value: cardinal: boolean; var buf: pointer; bufsize: cardinal; begin result: = false; value: = 0; if ReggetValue (rootkey, name, reg_dword, buf, bufsize) thr, buf, bufsize). BUF) ^; FreeMem (BUF); Result: = true; end; end; function reggetbinary (rootkey: hkey; name: string; var value: string): boolean; var buf: Pointer; buffsize: cardinal; begin result: = False; value: = '; if ReggetValue (RootKey, Name, REG_BINARY, BUF, BUFSIZE) THEN BEGIN SETLENGTH (Value, BufSize); Move (BUF ^, Value [1], BUFSIZE); FreeMem (BUF);

Result: = true; End; End; Function Regvalueexists: boolean; var subkey: string; n: integer; htemp: hkey; begin result: = false; n: = lastpos ('/' , Name); if n> 0 Then Begin Subkey: = COPY (Name, 1, N - 1); if RegopenKeyex (RootKey, Pchar (Subkey), 0, Key_Read, HTEMP) = Error_suCcess Then Begin Subkey: = COPY (Name , N 1, Length (Name) - N); Result: = (RegQueryValueex (HTEMP, PCHAR (SUBKEY), NIL, NIL, NIL, NIL) = Error_Success); RegcloseKey (HTEMP); End; End; End; Function ReggetvalueType (RootKey: HKey; Name: bolean; var subkey: string; n: integer; htemp: hkey; value ;:; ('/', Name); if n> 0 Then Begin Subkey: = Copy (Name, 1, N - 1); IF (RegopenKeyex (RootKeyex (RootKeyex (Rootkey, Pchar (Subkey), 0, Key_Read, HTEMP) = ER Ror_success) THEN BEGIN Subkey: = COPY (Name, N 1, Length (Name) - N); if Subkey = '' Then Result: = (RegQueryValueex (HTEMP, NIL, NIL, @valtype, nil, nil) = error_success ) else Result: = (RegQueryValueEx (hTemp, PChar (SubKey), nil, @ValType, nil, nil) = ERROR_SUCCESS); if Result then Value: = ValType; RegCloseKey (hTemp); end; end; end; function RegKeyExists ( Rootkey: hkey; name: string): boolean; var htemp: hkey; begin result: = false; if regopenkeyex (rootkey, pchar (name), 0, key_read, htemp) =

ERROR_SUCCESS then begin Result: = True; RegCloseKey (hTemp); end; end; function RegDelValue (RootKey: HKEY; Name: String): boolean; var SubKey: String; n: integer; hTemp: HKEY; begin Result: = False; N: = LastPos ('/', name); if n> 0 Then Begin Subkey: = Copy (Name, 1, N - 1); if RegopenKeyex (RootKey, Pchar (Subkey), 0, Key_Write, HTEMP = Error_Success THEN BEGIN Subkey: = COPY (Name, N 1, Length (Name) - N); Result: = (HTEMP, PCHAR (Subkey)) = Error_Success); RegcloseKey (HTEMP); end; end; end; function Regdelkey: boolean; var subkey: string; n: integer; htemp: hkey; begin result: = false; n: = lastpos ('/', name); if n> 0 THEN BEGIN Subkey: = COPY (Name, 1, N - 1); if RegopenKeyex (RootKey, Pchar (Subkey), 0, Key_Write, HTEMP = Error_Success Ten Begin Subke Y: = COPY (Name, N 1, Length (Name) - N); Result: = (HTEMP, PCHAR (Subkey)) = Error_Success); RegCloseKey (HTEMP); End; End; End; Function RegdelKeyex RootKey: hkey; boolean; const maxbufsize: cardinal = 1024; var Ires: integer; htemp: hkey; buf: string; buffsize: cardinal; begin result: = false; // no Root Keys ... if POS ('/', name) <> 0 the begin Ires: = regopenkeyex (rootkey, pchar (name), 0, key_enumerate_sub_keys or key_write, htemp);

if WithSubKeys then begin while iRes = ERROR_SUCCESS do begin BufSize: = MaxBufSize; SetLength (Buf, BufSize); iRes: = RegEnumKeyEx (hTemp, 0, @Buf [1], BufSize, nil, nil, nil, nil); if iRes = ERROR_NO_MORE_ITEMS then begin RegCloseKey (hTemp); Result: = (RegDeleteKey (RootKey, PChar (Name)) = ERROR_SUCCESS); end else begin if iRes = ERROR_SUCCESS then begin SetLength (Buf, BufSize); if RegDelKeyEx (RootKey, Concat (Name , '/', Buf), WithSubKeys) then iRes: = ERROR_SUCCESS else iRES: = ERROR_BADKEY; end; end; end; end else begin RegCloseKey (hTemp); Result: = (RegDeleteKey (RootKey, PChar (Name)) = ERROR_SUCCESS End; end; end; function refenum (rootkey: hkey; name: string; var Resultlist: string; const dokeys: boolean: boolean; var i: integer; Ires: integer; s: string; htemp: hkey; buf : Pointer; BUFSIZE: Cardinal Begin Result: = false; resultlist: = '; if regopenkeyex (Rootkey, Pchame), 0, KEY_READ, HTEMP) = ERROR_SUCCESS THEN BEGIN RESULT: = true; buffsize: = 1024; GetMem (buf, bufsize); i: = 0; Ires: = error_suCcess; while Ires = error_suCcess do begin bufsize: = 1024; if dokeys the Ires: = RegenumKeyex (HTEMP, I, BUF, BUFSIZE, NIL, NIL, NIL, NIL) ELSE IRES: = RegenValue (HTEMP, I, BUF, BUFSIZE, NIL, NIL, NIL, NIL); if Ires = Error_Success Then Begin SetLENGTH (S, BUFSIZE); MOVE (BUF ^, S [1], BUFSIZE); if Resultlist =

转载请注明原文地址:https://www.9cbs.com/read-86313.html

New Post(0)