将凭据传递给VBScript中的WMI调用 [英] Pass Credentials to WMI Call in VBScript

查看:131
本文介绍了将凭据传递给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调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆