利用这个方法,稍做修改。
// copy file to 网路芳邻
function XCopyFile(const ExistFile, NewFile: string;
const isOverWrite: Boolean; const password: string=''): Boolean;
function XCopyFile(const ExistFile, NewFile: string;
const isOverWrite: Boolean; const password: string=''): Boolean;
const
comm:string = 'Net use %s %s';
var
str: string;
bFlag: Boolean;
lpSInfo: TStartupInfo;
lpPInfo: TProcessInformation;
mCode:Cardinal;
begin
bFlag:= not isOverWrite;
if (Copy(NewFile,1,2) = '//') then
begin // 填入 StartupInfo
FillChar(lpSInfo, Sizeof(TStartupInfo), #0);
lpSInfo.cb := Sizeof(TStartupInfo);
lpSInfo.dwFlags := STARTF_USESHOWWINDOW;
lpSInfo.wShowWindow :=SW_Show;
str:= Format(comm,[ExtractFileDir(NewFile), password]);
if CreateProcess(nil, PChar(str),nil, nil, True, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil, lpSInfo, lpPinfo) then
begin
WaitForSingleObject(lpPinfo.hProcess,3000);// 最多等叁秒(INFINITE)
if GetExitCodeProcess(lpPinfo.hProcess,mCode) then
TerminateProcess(lpPinfo.hProcess,mCode);
if CopyFile(PChar(ExistFile),PChar(NewFile),bFlag) then Result:= True
else Result:= False;
--------------------------------------------------------------------
->>>> Shelexecute. .....
end
else Result:= False;
end;
end;