我試圖執行一個外部程序,當某些條件滿足時使用一些變量。據我所知,命令不是試圖運行。我試過只使用notepad
,或者只是使用opcmon
命令本身,這應該會產生一個用法消息。外部命令不能從VBScript運行
我得到的唯一結果是從Echo
,看起來格式正確。例如。
Microsoft (R) Windows Script Host Version 5.812 Copyright (C) Microsoft Corporation. All rights reserved. opcmon.exe "TEST-Goober"=151 -object "C:\Tools"
' Script Name: FileCount.vbs
' Purpose: This script will send a message to OM with the number
' of files which exist in a given directory.
' Usage: cscript.exe FileCount.vbs [oMPolicyName] [pathToFiles]
' [oMPolicyName] is the name of the HPOM Policy
' [pathToFiles] is Local or UNC Path
Option Explicit
On Error Resume Next
Dim lstArgs, policy, path, fso, objDir, objFiles, strCommand, hr
Set WshShell = CreateObject("WScript.Shell")
Set lstArgs = WScript.Arguments
If lstArgs.Count = 2 Then
policy = Trim(lstArgs(0))
path = Trim(lstArgs(1))
Else
WScript.Echo "Usage: cscript.exe filecount.vbs [oMPolicyName] [pathToFiles]" &vbCrLf &"[oMPolicyName] HPOM Policy name" & vbCrLf &"[pathToFiles] Local or UNC Path"
WScript.Quit(1)
End If
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(path) Then
Set objDir = fso.GetFolder(path)
If (IsEmpty(objDir) = True) Then
WScript.Echo "OBJECT NOT INITIALIZED"
WScript.Quit(1)
End If
Set objFiles = objDir.Files
strCommand = "opcmon.exe """ & policy & """=" & objFiles.Count & " -object """ & path & """"
WScript.Echo strCommand
Call WshShell.Run(strCommand, 1, True)
WScript.Quit(0)
Else
WScript.Echo("FOLDER NOT FOUND")
WScript.Quit(1)
End If
謝謝你的信息!那樣做了 –