AnsweredAssumed Answered

SA Task Editor, Auto Launch SCCM with Defined PC

Question asked by jordanreich on Feb 27, 2018
Latest reply on Mar 2, 2018 by Raghu.Rudraraju

Hey all,

 

I'm attempting to create a new VBSCRIPT within the SA Task Editor for Support Automation.

 

I have the following script to obtain the computer name (and individually it works):

Function Execute()
AddBasicSystemInfo
End Function

Sub AddBasicSystemInfo
Dim OSObj, CSObj, tmp
Set OSObj = WMIObjects.GetOperatingSystemObject()
Set CSObj = WMIObjects.GetComputerSystemObject()
Set objNetwork = CreateObject("Wscript.Network")

AppendDataItem "basicData", "", CSObj.Name, True
End Sub

Sub AppendDataItem(dataStoreName, name, value, logit)
Dim strToAppend, origValue
strToAppend = name & "||" & value & "^^"

origValue = Task.GetNamedDataItem(dataStoreName)
If IsNull(origValue) Then
origValue = ""
End If

Task.SetNamedDataItem dataStoreName, origValue & strToAppend

If logit = True Then
WScript.Echo name & "" & value
End If
End Sub

I have the following script to launch SCCM and it works on the PC itself:

Option Explicit 

Dim bPrompt, s32bitCCMViewerEXE, s64bitCCMViewerEXE, sErrMsg, WshShell
Dim CCMViewerEXE, sSiteCode, sServer, objShell, sComputer
Dim objArgs, objFile, objFS

s64bitCCMViewerEXE = "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\i386\CmRcViewer.exe"
s32bitCCMViewerEXE = "C:\Program Files\Microsoft Configuration Manager\AdminConsole\bin\i386\CmRcViewer.exe"

'If we can't find an instances of the CmRcViewer.exe somewhere in our
' defined paths, then quit.
If CheckEXE(s32bitCCMViewerEXE) = false and CheckEXE(s64bitCCMViewerEXE) = false then
sErrMsg = "Could not find the SCCM remote command exe (CmRcViewer.exe). Please install the SCCM Administrator Console."
msgbox sErrMsg,48,"Could not find CmRcViewer.exe"
wscript.quit
End If

Set WshShell = CreateObject("WScript.Shell")
'Get our command-line argument
Set objArgs = WScript.Arguments


If objArgs.count = 0 then

On Error Resume Next
sServer = "INSERTSERVERNAME"
sSiteCode = "INSERTSITECODE"
sComputer = "INSERTCOMPUTERNAME"

Else
'If there is only one argument, we'll assume it
' is for the host you are trying to connect to
sComputer = objArgs(0)
End if

'If ping fails, then say so and exit the script.
If PingHost(sComputer) = false then
msgbox sComputer & " is not responding to pings. Aborting.",64,"Cannot communicate with host."
wscript.quit
'If ping succeeds, then move on.
Else
WshShell.run chr(34) & CCMViewerEXE & chr(34) & " " & sComputer & " \\" & sSiteCode ,1,false
End If

'Function to ping a computer name, returns 'true' or 'false.'
Function PingHost(sComputer)

Dim objExecResults, sResults

Set WshShell = CreateObject("WScript.Shell")
Set objExecResults = WshShell.Exec("ping.exe -n 1 " & sComputer)

sResults = objExecResults.StdOut.ReadAll

If instr(sResults, "Bad IP address") > 0 then
PingHost = false
End if

If instr(sResults, "Reply from") > 0 then
PingHost = true
End if
End Function 'Pinghost

Function CheckEXE(sFile)
On Error Resume Next
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFile = objFS.getFile(sFile)

If err.number <> 0 then
CheckEXE = false
Else
CCMViewerEXE = sFile
CheckEXE = sFile
End if
Set objFile = nothing

On error goto 0
End Function

 

The problem is that I'm having issues combining them. Using the task editor. Do you know how or if it is possible to take the computer name returned from TASK1 and pass it to TASK2, to launch SCCM with the computer name.

 

We are trying to avoid using the OOTB remote control software. The VBSCRIPT shown in TASK2 does not work within the task editor. Although it does work perfectly when ran on the PC.

 

Thoughts?

 

Thanks!

Outcomes