win98 下映射盘符的问题 ( 积分: 50 )

  • 主题发起人 主题发起人 tswhq
  • 开始时间 开始时间
T

tswhq

Unregistered / Unconfirmed
GUEST, unregistred user!
program Map;<br><br>{$APPTYPE CONSOLE}<br><br>uses<br> &nbsp;SysUtils,<br> &nbsp;Windows;<br>var<br> &nbsp;i &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :integer;<br> &nbsp;Para &nbsp; &nbsp; &nbsp; &nbsp;:Array[1..10] of String;<br> &nbsp;NetRes &nbsp; &nbsp; &nbsp;:TNetResource;<br>begin<br> &nbsp;if (ParamCount=0) or (ParamCount&gt;10) then<br> &nbsp;begin<br> &nbsp; &nbsp;WriteLn('参数错误...');<br> &nbsp; &nbsp;Exit;<br> &nbsp;end;<br> &nbsp;for i:=1 to ParamCount do<br> &nbsp;begin<br> &nbsp; &nbsp;Para:=UpperCase(ParamStr(i));<br> &nbsp;end;<br> &nbsp;if Para[1]='/ADD' then<br> &nbsp;begin<br> &nbsp; &nbsp;if ParamCount&lt;5 then Para[5]:='';<br> &nbsp; &nbsp;if ParamCount&lt;4 then Para[4]:='';<br> &nbsp; &nbsp;if ParamCount&lt;3 then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;WriteLn('创建映射参数错误:/ADD &nbsp;盘符 &nbsp;//服务器/目录(卷) &nbsp;用户名 &nbsp;密码');<br> &nbsp; &nbsp; &nbsp;Exit;<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;//NetRes.dwDisplayType := RESOURCEDISPLAYTYPE_SERVER;<br> &nbsp; &nbsp;//NetRes.dwScope := RESOURCE_CONNECTED;<br> &nbsp; &nbsp;NetRes.dwType := RESOURCETYPE_ANY;<br> &nbsp; &nbsp;NetRes.lpRemoteName := PChar(Para[3]);<br> &nbsp; &nbsp;NetRes.dwUsage := RESOURCEUSAGE_CONNECTABLE;<br> &nbsp; &nbsp;NetRes.lpLocalName := '';<br> &nbsp; &nbsp;NetRes.lpProvider := '';<br> &nbsp; &nbsp;if WNetAddConnection2(NetRes,PAnsiChar(ParamStr(5)),PAnsiChar(ParamStr(4)),0)=0 then<br> &nbsp; &nbsp; &nbsp;Writeln('创建映射成功...')<br> &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp;Writeln('创建映射失败...');<br> &nbsp; &nbsp;Exit;<br> &nbsp;end;<br> &nbsp;if Para[1]='/DELETE' then<br> &nbsp;begin<br> &nbsp; &nbsp;if ParamCount&lt;&gt;2 then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;WriteLn('删除映射参数错误:/Delete &nbsp;盘符');<br> &nbsp; &nbsp; &nbsp;Exit;<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;if WNetCancelConnection2(PAnsiChar(Para[2]),1,True)=0 then<br> &nbsp; &nbsp; &nbsp;Writeln('删除映射成功...')<br> &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp;Writeln('删除映射失败...');<br> &nbsp; &nbsp;Exit;<br> &nbsp;end;<br>end.<br><br>运行程序<br>map &nbsp;/add &nbsp;p: &nbsp;//tshylwpz/d &nbsp;guest<br>提示映射成功<br>但无法转到P:<br>查看net use状态<br>ok &nbsp; &nbsp;(此处无盘符) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//tshylwpz/d<br><br>为何?
 
program Map;<br><br>{$APPTYPE CONSOLE}<br><br>uses<br> &nbsp;SysUtils,<br> &nbsp;Windows;<br>var<br> &nbsp;i &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :integer;<br> &nbsp;Para &nbsp; &nbsp; &nbsp; &nbsp;:Array[1..10] of String;<br> &nbsp;NetRes &nbsp; &nbsp; &nbsp;:TNetResource;<br>begin<br> &nbsp;if (ParamCount=0) or (ParamCount&gt;10) then<br> &nbsp;begin<br> &nbsp; &nbsp;WriteLn('参数错误...');<br> &nbsp; &nbsp;Exit;<br> &nbsp;end;<br> &nbsp;for i:=1 to ParamCount do<br> &nbsp;begin<br> &nbsp; &nbsp;Para:=UpperCase(ParamStr(i));<br> &nbsp;end;<br> &nbsp;if Para[1]='/ADD' then<br> &nbsp;begin<br> &nbsp; &nbsp;if ParamCount&lt;5 then Para[5]:='';<br> &nbsp; &nbsp;if ParamCount&lt;4 then Para[4]:='';<br> &nbsp; &nbsp;if ParamCount&lt;3 then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;WriteLn('创建映射参数错误:/ADD &nbsp;盘符 &nbsp;//服务器/目录(卷) &nbsp;用户名 &nbsp;密码');<br> &nbsp; &nbsp; &nbsp;Exit;<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;//NetRes.dwDisplayType := RESOURCEDISPLAYTYPE_SERVER;<br> &nbsp; &nbsp;//NetRes.dwScope := RESOURCE_CONNECTED;<br> &nbsp; &nbsp;NetRes.dwType := RESOURCETYPE_ANY;<br> &nbsp; &nbsp;NetRes.lpRemoteName := PChar(Para[3]);<br> &nbsp; &nbsp;NetRes.dwUsage := RESOURCEUSAGE_CONNECTABLE;<br> &nbsp; &nbsp;NetRes.lpLocalName := '';<br> &nbsp; &nbsp;NetRes.lpProvider := '';<br> &nbsp; &nbsp;if WNetAddConnection2(NetRes,PAnsiChar(ParamStr(5)),PAnsiChar(ParamStr(4)),0)=0 then<br> &nbsp; &nbsp; &nbsp;Writeln('创建映射成功...')<br> &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp;Writeln('创建映射失败...');<br> &nbsp; &nbsp;Exit;<br> &nbsp;end;<br> &nbsp;if Para[1]='/DELETE' then<br> &nbsp;begin<br> &nbsp; &nbsp;if ParamCount&lt;&gt;2 then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;WriteLn('删除映射参数错误:/Delete &nbsp;盘符');<br> &nbsp; &nbsp; &nbsp;Exit;<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;if WNetCancelConnection2(PAnsiChar(Para[2]),1,True)=0 then<br> &nbsp; &nbsp; &nbsp;Writeln('删除映射成功...')<br> &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp;Writeln('删除映射失败...');<br> &nbsp; &nbsp;Exit;<br> &nbsp;end;<br>end.<br><br>运行程序<br>map &nbsp;/add &nbsp;p: &nbsp;//tshylwpz/d &nbsp;guest<br>提示映射成功<br>但无法转到P:<br>查看net use状态<br>ok &nbsp; &nbsp;(此处无盘符) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//tshylwpz/d<br><br>为何?
 
看你这里 NetRes.lpLocalName := ''; 当然没盘符了<br>看你程序的意思,这里应该是 NetRes.lpLocalName := pchar(para[2]);
 
呵呵!看来还是我"迷糊"呀~!
 
接受答案了.
 
后退
顶部