/build/static/layout/Breadcrumb_cap_w.png

Help need with two vbscripts for roll out via SCCM

Hello,

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."
Else
 For Each objService in colListOfServices
  strServiceStatus = objService.State
  If  strServiceStatus = "Stopped" Then
   objService.ChangeStartMode("Automatic")
   objService.StartService()
   If  Err.Number = 0 Then
    Wscript.echo "Service ****** has been started & configuted to Automatic state."
   Else
    Wscript.echo "Service ****** not started coz error " & Err.Number & ":" & Err.Description & " has occured."
    Err.Clear
   End If
  Else
   Wscript.echo "Service ****** already in running state."
  End If
 Next
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
                                                               Next
End Function  'Checkifvm
Set objShell = CreateObject("Wscript.Shell") If Checkifvm Then
wscript.echo "This software should not be installed"
  
  Else
 
   '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
wscript.Quit(strError)  

 

Regards

NG


2 Comments   [ + ] Show 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? - anonymous_9363 11 years ago
  • Hi vbscab, i got S2 to work by making change to the command line and checking 'interact' option in SCCM. S1 not working yet - ninjaguy 11 years ago

Answers (1)

Posted by: ninjaguy 11 years ago
Senior Yellow Belt
0

I  added a force reboot and it worked

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ