I need help with two scripts which i am trying to roll out via SCCM

Scenario 1

I am trying to start a windows service which gets stopped after a SCCM roll out. I created another package which would use a vbs to restart the service and then reboot (using configmgr restarts computer).However the vbscript after successfully executing enabling the service does not end. It goes on for 120 minutes before giving an error that it could not be completed.I just need the program to end. Also the service should be enabled if it is stopped and then just skip if it is already enabled

attached in the below script

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name = '******'")
If  colListOfServices.Count = 0 Then
    Wscript.echo "Service ****** does not exists."
 For Each objService in colListOfServices
  strServiceStatus = objService.State
  If  strServiceStatus = "Stopped" Then
   If  Err.Number = 0 Then
    Wscript.echo "Service ****** has been started & configuted to Automatic state."
    Wscript.echo "Service ****** not started coz error " & Err.Number & ":" & Err.Description & " has occured."
   End If
   Wscript.echo "Service ****** already in running state."
  End If
End If

Scenario 2

In this i am trying to block a package from running on a VM and to be installed only on desktops.When i run this the pop up comes stating that the software should not be installed but SCCM anyway goes ahead and installs it. Can the script be adjusted so that after the pop up it fails in execution on Vm machine but if it is run on desktops then successfully executed

On Error Resume Next

Function Checkifvm

Checkifvm = False
Set objWMIService = GetObject("winmgmts:" _
                                                   & "{impersonationLevel=impersonate}!\\.\root\cimv2")
                                               Set colManu = objWMIService.ExecQuery("Select * from Win32_Computersystem")
                                                               For Each objItem in colManu
                                                                              If Instr(1, UCase(objItem.Manufacturer), "VMWARE", 1) Then
                                                                                              Checkifvm = True
                                                                              End If
End Function  'Checkifvm
Set objShell = CreateObject("Wscript.Shell") If Checkifvm Then
wscript.echo "This software should not be installed"
   'Start command is machine is NOT vmware virtual machine
  exexstr = "msiexec /i *****.msi /qb-!"
  strError = objShell.Run (exexstr, 1, True) End If 'WScript.echo "Exit Code = " & strError




2 Comments   [ - ] Hide Comments


  • S1, the script must be stuck in the 'For Each...Next' loop so build in a timer for any response that *might* take longer than a few seconds and add an explicit 'Exit For' for successful completion.

    S2, you have no exit code for when it detects a VM. Add in a 'WScript.Quit(intExitCode)' after your pop-up (which you will of course remove for live deployment) where 'intExitCode' is whatever you want to be returned to SCCM. Maybe 1603?
  • Hi vbscab, i got S2 to work by making change to the command line and checking 'interact' option in SCCM. S1 not working yet
Please log in to comment

Answer this question or Comment on this question for clarity



I  added a force reboot and it worked

Answered 08/30/2013 by: ninjaguy
Senior Yellow Belt

Please log in to comment