急急急!大侠们救命啊!关于delphi对wmi管理规范程序的编程!(200)

  • 主题发起人 主题发起人 暴暴蓝
  • 开始时间 开始时间

暴暴蓝

Unregistered / Unconfirmed
GUEST, unregistred user!
请问如何利用delphi对wmi的编程,获得计算机的当前会话,得到远程机器的机器名和用户.(计算机管理(本地)--共享文件夹--会话)下的计算机和用户列表.
 
这是我查找的相关资料··是用C#写的,哪位高手帮忙翻成delphi的,感谢啊!使用了WMI ( Windows Management Instrumentation ) 和 MQL ( Management Query Lanagauge)得到系统的信息。主要的文件是:System.management.dll读取当前会话的用户名的程序:private void Read_Shared_Folder() { int cnt = 0; try { // MQL for Shaer Information ManagementObjectSearcher searcher = new ManagementObjectSearcher("root//CIMV2","SELECT * FROM Win32_Share"); foreach (ManagementObject queryObj in searcher.Get()) { RDirPath = queryObj["Path"].ToString(); if (!RDirPath.Equals("") || RDirPath.Equals("IPC$") || RDirPath.Equals("ADMIN$") ) { File_Watcher(RDirPath); } load_Shared_Item(cnt, queryObj["Name"].ToString(), queryObj["Path"].ToString(), queryObj["Description"].ToString(), queryObj["Status"].ToString() ); cnt=cnt+1; } }catch (ManagementException e) { MessageBox.Show("An error occurred while querying for WMI data: " + e.Message); } } 读取当前会话的用户名的程序: private void Read_Current_Session() { int counter = 0; int ActiveTime; int itime; string sharename; try { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root//CIMV2", "SELECT * FROM Win32_ServerConnection"); ManagementObjectSearcher searcher2 = new ManagementObjectSearcher("root//CIMV2", "SELECT * FROM Win32_ServerSession"); // Read the object foreach (ManagementObject ServerQobj in searcher2.Get()) { RemoteOS = ServerQobj["ClientType"].ToString(); IDealTime = ServerQobj["IdleTime"].ToString(); itime = Int32.Parse(IDealTime) / 60; IDealTime = itime.ToString(); } foreach (ManagementObject queryObj in searcher.Get()) { RemoteIPAddress = queryObj["ComputerName"].ToString(); RemoteUserName = queryObj["UserName"].ToString(); RemoteActiveTime = queryObj["ActiveTime"].ToString(); ActiveTime = (Int32.Parse(RemoteActiveTime)) / 60; RemoteActiveTime = ActiveTime.ToString(); sharename = queryObj["ShareName"].ToString(); if (!sharename.Equals("IPC$")) { Load_Current_Session(counter, RemoteIPAddress, RemoteUserName, RemoteActiveTime,IDealTime,RemoteOS); load_Access_folder(counter, RemoteUserName, sharename); counter += 1; } } } catch (ManagementException e) { MessageBox.Show("An error occurred while querying for WMI data: " + e.Message); } }
 
发错了··前面那一段是获得共享文件夹的。下面一段才是获得当前会话的!
 
参考下面的代码uses ComObj, ActiveX;procedure TForm1.Button1Click(Sender: TObject);var Locator: OleVariant; WMI: OleVariant; RET: OleVariant; Enum: IEnumVariant; Tmp: OleVariant; Value: Cardinal;begin Locator := CreateOleObject('WbemScripting.SWbemLocator'); WMI := Locator.ConnectServer('.', '', '', ''); Ret := WMI.ExecQuery('SELECT * FROM MSAcpi_ThermalZoneTemperature'); Enum:= IUnknown(RET._NewEnum) as IEnumVariant; while (Enum.Next(1, Tmp, Value) = S_OK) do begin if not varisNull(Tmp.CurrentTemperature) then Memo1.Lines.Add(Format('%6.2f', [(Tmp.CurrentTemperature - 2732) / 10])); end;end;
 
非常感谢! tseug我刚学delphi快一年了,都是做数据库方面的,看了很久了大富翁离线资料。经常看你回答的问题和相关帖子!牛人啊!
 
请问 tseug: 我测试了下,本地测试,没有得到相关信息啊!(访问自己的共享文件夹)
 
up!很急啊··对系统相关操作所知甚少啊,大虾们帮帮忙!谢谢了!注:局域网内对方访问本机时,利用wmi得到当前会话,获得用户和计算机这两个参数列表。
 
去这里看看,有源码http://blog.ednchina.com/shaoziyang/214107/message.aspx
 
后退
顶部