现学现卖,昨天我刚问过的问题(Savetofile出错的问题)
用NET USE命令实现
procedure UseShare(ShareName, User, Pwd:string);
var
str:string;
stinfo:TStartUpInfo;
proinfo:TProcessInformation;
proresult:boolean;
begin
str:='net use "'+ShareName+'"';
if not SameText(User,'') then
str:=str+'net use "'+ShareName+'"'+' /user:'+User+' '+Pwd;
FillChar(stinfo, sizeof(TStartupInfo), 0);
proresult:=CreateProcess(nil,pchar(str),nil,nil,false,
DETACHED_PROCESS or CREATE_NO_WINDOW,nil,nil,stinfo,proinfo);
if proresult then
WaitForSingleObject(proinfo.hProcess,INFINITE);
end;