你必须先net use //218.17.xx.xx,然后才可以.
有一些功能在DOS下十分方便,Delphi却不知怎么办,不如直接按DOS方式执行:
createAndRunBat('net use //218.17.xx.xx /user:用户名 口令'#13#10+'net time //218.17.xxx.xxx',true,'0.$$$');
应该可以.
function createAndRunBat(ss:String;killBat:boolean;resultFileName:String):boolean; //建立并且运行批处理文件
var
BatFile: TFileStream;
batFileName,tmpS:String;
ProcessInfo: TProcessInformation;
StartUpInfo: TStartupInfo;
ExitCode
WORD;
begin
batFileName:=ExtractFilePath(ParamStr(0)) + '$$a$$.bat';
BatFile := TFileStream.create(batFileName,fmCreate);
ss:=ss+#13#10;
BatFile.Write(ss[1],length(ss));
if killBat then
begin
tmpS:='@del %0'+#13#10+'@cls'+#13#10+'@exit';
batFile.Write(tmpS[1],length(tmpS));
end;
BatFile.Free;
FillChar(StartUpInfo, SizeOf(StartUpInfo), $00);
StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
StartUpInfo.wShowWindow := SW_Hide;
if resultFileName<>'' then batFileName:=batFileName+' >'+resultFileName;
result:=CreateProcess(nil, PChar(BatFileName), nil, nil,False, IDLE_PRIORITY_CLASS, nil, nil, StartUpInfo,ProcessInfo);
//CheckResult(result);
WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
//
if result then
begin
WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess,ExitCode);
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
end;
end;