将凭据传递给VBScript中的WMI调用

编程入门 行业动态 更新时间:2024-10-26 02:35:46
本文介绍了将凭据传递给VBScript中的WMI调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在HTA中具有VBScript,可从本地WMI调用获取ping状态。我还具有获取远程PC的最后重新启动时间的功能。

I have VBScript inside a HTA getting the ping status from a local WMI call.. I also have a function to get the last reboot time of the remote pc..

Function GetReboot(strComputer) Set objWMIService = GetObject _ ("winmgmts:\\" & strComputer & "\root\cimv2") Set colOperatingSystems = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem") For Each objOS in colOperatingSystems dtmBootup = objOS.LastBootUpTime dtmLastBootupTime = WMIDateStringToDate(dtmBootup) dtmSystemUptime = DateDiff("h", dtmLastBootUpTime, Now) Wscript.Echo dtmSystemUptime Next GetReboot = dtmLastbootupTime End Function

大致就是这样,显然我声明了变量并具有另一个日期函数,等等。

That is roughly what it is, obviously i declare the variables and have another date function etc..

如果我WMI以本地管理员身份调用 localhost,则此方法有效。将WMI呼叫连接到远程服务器,仅当我使用AD管理员帐户登录到本地计算机时,此方法才有效。

This works if I WMI call "localhost" as I am a local admin.. however when doing the WMI call to a remote server this only works if I am logged in to my local machine with an AD admin account.

有没有一种方法可以提示用户输入用户名和密码,然后将其传递给WMI调用,这样它就可以像任何人一样具有管理员详细信息?

Is there a way I can prompt the user for a username and password and then pass that to the WMI call so it works as anyone just with the admin details?

推荐答案

它看起来 SWbemLocator.ConnectServer 方法使您可以连接到远程计算机时,请指定用户名和密码。看起来您需要使用的语法是相似的,只需要以不同的方式创建 objWMIService 对象即可。

It looks like the SWbemLocator.ConnectServer Method allows you to specify a username and password when connecting to remote computers. It looks like the syntax that you need to use is similar, you just need to create your objWMIService object differently:

Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator") Set objWMIService = objSWbemLocator.ConnectServer("MachineName", "root\cimv2", "Username", "Password")

如果您在Google上搜索 WbemScripting.SWbemLocator,则可以获得更多文档

More documentation is available if you search for "WbemScripting.SWbemLocator" on Google

更多推荐

将凭据传递给VBScript中的WMI调用

本文发布于:2023-11-17 05:54:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609064.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:凭据   VBScript   WMI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!