T
tswhq
Unregistered / Unconfirmed
GUEST, unregistred user!
program Map;<br><br>{$APPTYPE CONSOLE}<br><br>uses<br> SysUtils,<br> Windows;<br>var<br> i :integer;<br> Para :Array[1..10] of String;<br> NetRes :TNetResource;<br>begin<br> if (ParamCount=0) or (ParamCount>10) then<br> begin<br> WriteLn('参数错误...');<br> Exit;<br> end;<br> for i:=1 to ParamCount do<br> begin<br> Para:=UpperCase(ParamStr(i));<br> end;<br> if Para[1]='/ADD' then<br> begin<br> if ParamCount<5 then Para[5]:='';<br> if ParamCount<4 then Para[4]:='';<br> if ParamCount<3 then<br> begin<br> WriteLn('创建映射参数错误:/ADD 盘符 //服务器/目录(卷) 用户名 密码');<br> Exit;<br> end;<br> //NetRes.dwDisplayType := RESOURCEDISPLAYTYPE_SERVER;<br> //NetRes.dwScope := RESOURCE_CONNECTED;<br> NetRes.dwType := RESOURCETYPE_ANY;<br> NetRes.lpRemoteName := PChar(Para[3]);<br> NetRes.dwUsage := RESOURCEUSAGE_CONNECTABLE;<br> NetRes.lpLocalName := '';<br> NetRes.lpProvider := '';<br> if WNetAddConnection2(NetRes,PAnsiChar(ParamStr(5)),PAnsiChar(ParamStr(4)),0)=0 then<br> Writeln('创建映射成功...')<br> else<br> Writeln('创建映射失败...');<br> Exit;<br> end;<br> if Para[1]='/DELETE' then<br> begin<br> if ParamCount<>2 then<br> begin<br> WriteLn('删除映射参数错误:/Delete 盘符');<br> Exit;<br> end;<br> if WNetCancelConnection2(PAnsiChar(Para[2]),1,True)=0 then<br> Writeln('删除映射成功...')<br> else<br> Writeln('删除映射失败...');<br> Exit;<br> end;<br>end.<br><br>运行程序<br>map /add p: //tshylwpz/d guest<br>提示映射成功<br>但无法转到P:<br>查看net use状态<br>ok (此处无盘符) //tshylwpz/d<br><br>为何?