`
阿尔萨斯
  • 浏览: 4175271 次
社区版块
存档分类
最新评论

SMS脚本节选一:连接到SMS Provider

 
阅读更多

Before connecting to the SMS Provider for a local or remote SMS site server, you first need to locate the SMS Provider for the site server. The SMS Provider can be either local or remote to the SMS site server you are using. The WMI class SMS_ProviderLocation is present on all SMS site servers, and one instance will contain the location for the SMS site server you are using.

You can connect to the SMS Provider on an SMS site server by using the WMI <linktext xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"></linktext>SWBemLocator object or by using the Windows Script Host GetObject method. Both approaches work equally well on local or remote connections, with the following limitations:

  • You must use SWbemLocator if you need to pass user credentials to a remote computer.

  • You cannot use SWBemLocator to explicitly pass user credentials to a local computer.

There are several different syntaxes that you can use to make the connection, depending on whether the connection is local or remote. The following procedures provide two common variations. After you are connected to the SMS Provider, you will have an <linktext xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"></linktext>SWBemServices object that you use to access SMS objects.

To connect to an SMS Provider by using SWbemLocator

  1. <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"></content>

    Connect to the local SWbemLocator object:

    set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
  2. <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"></content>

    Connect to a known SMS site server. If the computer name is a remote computer, you can pass the user name and password. Alternatively, you can authenticate using the current user's credentials by removing the user name and password parameters. If the computer name is the local computer, you must remove the user name and password because these will not be accepted. You can also change the computer name to "." if you want to connect to the local computer.

    set objSWbemServices= objSWbemLocator.ConnectServer _    ("ComputerName", "root/sms","username","password")
  3. <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"></content>

    Locate the SMS Provider for the SMS site by inspecting the SMS_ProviderLocation WMI class. For the SMS_ProviderLocation instance where the ProviderForLocalSite property is true, the object's Machine and SiteCode properties give the location of the SMS Provider for the SMS site server you are connected to. If the account running the script on the local computer has appropriate privileges, the user name and password parameters can be omitted.

    Set ProviderLoc = objSWbemServices.InstancesOf("SMS_ProviderLocation")For Each Location In ProviderLoc        If Location.ProviderForLocalSite = True Then            Set objSWbemServices = objSWbemLocator.ConnectServer _                 (Location.Machine, "root/sms/site_" + Location.SiteCode,"username","password")        End IfNext
  4. <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"></content>

    Continue using the objSWbemServices object to access SMS objects.

To connect to a remote SMS Provider by using the GetObject method

  1. <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"></content>

    Connect to a known SMS site server by using GetObject. In this example, authentication is set to impersonate. If you are connecting to the local computer, you can change SERVERNAME to ".".

    Set objSWbemServices = GetObject("winmgmts:{impersonationLevel=impersonate}!//SERVERNAME/root/sms/site_SITECODE")if err.number0 then    wscript.echo "WBemServices connection failed"    wscript.quitend if
  2. <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"></content>

    Continue using the objSWbemServices object to access SMS objects.

Security

<content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"></content>

Using script to pass the user name and password is a security risk and should be avoided where possible.




<iframe align="center" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog.html" frameborder="0" width="728" scrolling="no" height="90"></iframe>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics