16,749
社区成员
发帖
与我相关
我的任务
分享
//*************************给runas启用管理员的cmd**************************
WinExec('runas /user:administrator cmd',SW_HIDE);
h:=FindWindow('ConsoleWindowClass','C:\Windows\system32\runas.exe');
Delay(100);
while h=0 do
begin
h:=FindWindow('ConsoleWindowClass','C:\Windows\system32\runas.exe');
end;
SendMessageToCMD(h,mystring);//mystring是密码
postmessage(h,WM_keydown,13,0);
Delay(100);
SendMessage(h,WM_CLOSE,0,0);//关闭隐藏的CMD窗口 }
//close;
//*************************给runas启用管理员的cmd**************************
h:=FindWindow('ConsoleWindowClass','管理员: cmd (作为 XX-PC\administrator 运行)');
while h=0 do
begin
h:=FindWindow('ConsoleWindowClass','管理员: cmd (作为 XX-PC\administrator 运行)');
end;
Delay(100);
mystring:=mypath;
SendMessageToCMD(h,mystring);
postmessage(h,WM_keydown,13,0);
SendMessage(h,WM_CLOSE,0,0);//关闭隐藏的CMD窗口 }
procedure TForm1.SendMessageToCMD(hwd:hwnd ;str:string);
var
i:integer;
ch: byte;
begin
i := 1;
while i <= Length(str) do
//该过程发送指定字符串(中英文皆可以)
begin
Delay(500);
ch := byte(str[ i ]);
if Windows.IsDBCSLeadByte(ch) then
begin
Inc(i);
SendMessage(hwd, WM_IME_CHAR, MakeWord(byte(str[ i ]), ch), 0);
end
else
begin
SendMessage(hwd, WM_IME_CHAR, word(ch), 0);
end;
Inc(i);
end;
end;
//*************************给runas启用管理员的cmd**************************
WinExec('runas /user:administrator cmd',SW_HIDE);
h:=FindWindow('ConsoleWindowClass','C:\Windows\system32\runas.exe');
Delay(100);
while h=0 do
begin
h:=FindWindow('ConsoleWindowClass','C:\Windows\system32\runas.exe');
end;
SendMessageToCMD(h,mystring);
postmessage(h,WM_keydown,13,0);
Delay(100);
SendMessage(h,WM_CLOSE,0,0);//关闭隐藏的CMD窗口 }
//close;
//*************************给runas启用管理员的cmd**************************