停用/启用本地连接的问题(200分)

  • 主题发起人 主题发起人 dawnsoft
  • 开始时间 开始时间
D

dawnsoft

Unregistered / Unconfirmed
GUEST, unregistred user!
请问在XP的网络连接中如何停用/启用一个本地连接,如果不止一个的本地连接,可以通过指定名称停用/启用某个连接吗?多谢。
 
下面是一段枚举本地连接的VBScript。可以复制到一个*.vbs文件中执行。<br>可以枚举出所有连接,但是必须xp以上<br>////////////////////////////////<br>strComputer = &quot;.&quot;<br>Set objWMIService = GetObject(&quot;winmgmts://&quot; & strComputer & &quot;/root/microsoft/homenet&quot;)<br>Set colItems = objWMIService.ExecQuery(&quot;Select * from HNet_Connection&quot;)<br>For Each objItem in colItems<br> &nbsp; &nbsp;Wscript.Echo &quot;GUID: &quot; & objItem.GUID<br> &nbsp; &nbsp;Wscript.Echo &quot;Is LAN Connection: &quot; & objItem.IsLANConnection<br> &nbsp; &nbsp;Wscript.Echo &quot;Name: &quot; & objItem.Name<br> &nbsp; &nbsp;Wscript.Echo &quot;Phone Book Path: &quot; & objItem.PhoneBookPath<br>Next<br>//////////////////////////////////////////<br>有了这一步,下一步就简单了
 
转换了一个Delphi版本的:<br>uses WbemScripting_TLB; ////其中,WbemScripting_TLB.pas可从<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;///http://www.truth4all.org/WbemScripting_TLB.pas下载<br>function ADsEnumerateNext(pEnumVariant: IEnumVARIANT; cElements: ULONG;<br>var pvar: OleVARIANT; var pcElementsFetched: ULONG): HRESULT; safecall; external 'activeds.dll';<br><br>procedure TForm1.Button3Click(Sender: TObject);<br>var<br> &nbsp;Locator: ISWbemLocator;<br> &nbsp;oService: ISWbemServices;<br> &nbsp;oObjs: ISWbemObjectSet;<br> &nbsp;Enum: IEnumVARIANT;<br> &nbsp;varArr: OleVariant;<br> &nbsp;lNumElements: ULong;<br> &nbsp;AName: array[0..255] of Char;<br> &nbsp;ASize: DWORD;<br> &nbsp;Server: string;<br>begin<br> &nbsp;Server := '';<br> &nbsp;ASize := SizeOf(AName) - 1;<br> &nbsp;if GetComputerName(@AName, ASize) then Server := AName;<br><br> &nbsp;Locator := CoSWbemLocator.Create; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 'root/cimv2'<br> &nbsp;oService := Locator.ConnectServer(Server, 'root/microsoft/homenet', '',<br> &nbsp; &nbsp;'', '', '', 0, nil);<br> &nbsp;oObjs := oService.ExecQuery('Select * from HNet_Connection', 'WQL',<br> &nbsp; &nbsp;wbemFlagBidirectional, nil);<br> &nbsp;Enum := oObjs._NewEnum as IEnumVariant;<br> &nbsp;while (Succeeded(ADsEnumerateNext(Enum, 1, varArr, lNumElements))) and<br> &nbsp;(lNumElements &gt; 0) do<br> &nbsp;begin<br> &nbsp; &nbsp;ShowMessage((IUnknown(varArr) as SWBemObject).GetObjectText_(0));<br> &nbsp;end;<br>end;<br>大家共同学习:)
 
IEnumVARIANT这个是什么????
 
xiammy大侠能否做个例子出来。多谢。<br>dawnsoft@163.com
 
IEnumVARIANT是用来枚举在VB中支持Foreach的接口。Delphi中没有对应语法,只好这样做了。
 
晕,各位高手还有什么办法吗?
 
推荐使用 setupapi,这个 jcl 有 pas 定义单元。而且他的网站上有 demo
 
有demo吗?google查不到……
 
自己搞掂。
 
后退
顶部