Getting the Script's Account

In some cases, the actions performed by a script will require privileges associated with a specific Windows User account. To avoid errors, the script should verify the account name it is using before attempting to access any protected resources.

Scripts run using the MOM service's account. You can determine the account details with the WshNetwork object. The WshNetwork object is part of the Windows Scripting Technologies, but it can be use outside of the Windows Script Host environment.

The following sample demonstrates how to check whether the script is running as the local system account:


Function IsUsingSystemAccount
    Dim oNet
    Dim strCurrentUserDomain, strCurrentUserName
    Dim strLocalComputer
    Dim bIsSystem

    bIsSystem = False

    Set oNet = CreateObject("WScript.Network")

    strCurrentUserDomain = oNet.UserDomain
    strCurrentUserName = oNet.UserName
    strLocalComputer = oNet.ComputerName

    If ((strCurrentUserDomain = strLocalComputer) And _
        (strCurrentUserName = SYSTEM_ACCOUNT_NAME)) Then

        bIsSystem = True
    End If

    IsUsingSystemAccount = bIsSystem
End Function