请教下各位前辈,如何判断注册表中的某个键值存在,如果不存在就建立一个???拿这个注册表为例子:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters]
"AutoShareServer"=dword:00000000
"AutoSharewks"=dword:00000000
利用winexec调用CMD来执行命令,如何让结果显示在MEMO1上?
如,NET USER 所返回的用户的结果显示在MEMO1请教前辈了....谢谢
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters]
"AutoShareServer"=dword:00000000
"AutoSharewks"=dword:00000000
利用winexec调用CMD来执行命令,如何让结果显示在MEMO1上?
如,NET USER 所返回的用户的结果显示在MEMO1请教前辈了....谢谢
解决方案 »
- delphi 如何取出注册表的值
- 怎么判断TreeView前面加的复选框是否处于选中状态?
- 请教tsc 243(E)条码打印编程小问题,高手请进,在线急等…………
- 转贴水贴
- Double在内存中占8个字节,已知8个字节的值如何求出Double值?
- 请问怎样才能知道DBGRIDEH的选中一行的某一例的值?
- record类型用什么来产生实例
- 将ComboBox的Style设为csDropDownList后如何显示其Text
- 便宜分 怎么样在delphi上用OpenDialog和按钮来打开一个文档
- Delphi6 大bug呀,气死了!!
- 怎样获得鼠标在windows下任意位置的点击事件?
- 请教高手 用PageControl还是用MDI窗体?
reg:TRegistry;
begin
reg:=TRegistry.Create;
reg.RootKey:=HKEY_LOCAL_MACHINE;
if reg.OpenKey('SOFTWARE\ODBC\ODBCINST.INI\Sybase System 11\',false) then
begin
str:=reg.ReadString('Driver');
end
else
begin
result:=false;
reg.Free;
exit;
end;reg.CloseKey;
end;
Reg.RootKey :=HKEY_LOCAL_MACHINE;
if Reg.OpenKey('SYSTEM\CurrentControlSet\Services\lanmanserver\parameters',True) then
begin
Reg.WriteInteger('AutoShareServer',00000000);
Reg.WriteInteger('AutoSharewks',00000000);
end;
finally
Reg.CloseKey;
Reg.Free;
end;
但是楼上两位都只是判断,而不存在就建立的操作偶杂没看到......
还有关于调用CMD显示在MEMO的期待高手回答...100分~~~如果都回答的这么好,就平均了......期待更好的
下面会列出所有的方法,比如createkey,也有例子可以参考
var
SA: TSecurityAttributes;
SI: TStartupInfo;
PI: TProcessInformation;
StdOutPipeRead, StdOutPipeWrite: THandle;
WasOK: Boolean;
Buffer: array[0..255] of Char;
BytesRead: Cardinal;
WorkDir, Line: String;
begin
with SA do
begin
nLength := SizeOf(SA);
bInheritHandle := True;
lpSecurityDescriptor := nil;
end;
// create pipe for standard output redirection
CreatePipe(StdOutPipeRead, // read handle
StdOutPipeWrite, // write handle
@SA, // security attributes
0 // number of bytes reserved for pipe - 0 default
);
try
// Make child process use StdOutPipeWrite as standard out,
// and make sure it does not show on screen.
with SI do
begin
FillChar(SI, SizeOf(SI), 0);
cb := SizeOf(SI);
dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
wShowWindow := SW_HIDE;
hStdInput := GetStdHandle(STD_INPUT_HANDLE); // don't redirect stdinput
hStdOutput := StdOutPipeWrite;
hStdError := StdOutPipeWrite;
end;
// launch the command line compiler
WorkDir := AWorkDir;
WasOK := CreateProcess(nil, PChar(ACommandLine), nil, nil, True, 0, nil,
nil, SI, PI);
// Now that the handle has been inherited, close write to be safe.
// We don't want to read or write to it accidentally.
CloseHandle(StdOutPipeWrite);
// if process could be created then handle its output
if not WasOK then
raise Exception.Create('Could not execute command line!')
else
try
// get all output until dos app finishes
Line := '';
repeat
// read block of characters (might contain carriage returns and line feeds)
WasOK := ReadFile(StdOutPipeRead, Buffer, 255, BytesRead, nil); // has anything been read?
if BytesRead > 0 then
begin
// finish buffer to PChar
Buffer[BytesRead] := #0;
// combine the buffer with the rest of the last run
Line := Line + Buffer;
end;
until not WasOK or (BytesRead = 0);
// wait for console app to finish (should be already at this point)
WaitForSingleObject(PI.hProcess, INFINITE);
finally
// Close all remaining handles
CloseHandle(PI.hThread);
CloseHandle(PI.hProcess);
end;
finally
Result := Line;
CloseHandle(StdOutPipeRead);
end;
end;
调用时procedure FillMemo;
var
Command: string;
begin
Command := 'Net User';
Memo1.text := GetDosOutput(Command, '');
end;
var
regTemp: TRegistry;
begin
regTemp := TRegistry.Create;
with regTemp do
begin
RootKey := HKEY_LOCAL_MACHINE;
if not OpenKey('SYSTEM\CurrentControlSet\Services\lanmanserver\parameters', False) then
begin
CloseKey;
if CreateKey('\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters') then
begin
CloseKey;
if OpenKey('SYSTEM\CurrentControlSet\Services\lanmanserver\parameters', True) then
begin
Reg.WriteInteger('AutoShareServer',00000000);
Reg.WriteInteger('AutoSharewks',00000000);
CloseKey;
end;
end;
end;
end;
regTemp.Free;
end;
Lz可以用看看幫助的啊,就很清楚了