cancel
Showing results for 
Search instead for 
Did you mean: 

Script Event - On Begin Update - How to kill running processes?

Former Member
0 Kudos

Hi everyone,

I wish to use the "On Being Update" script event to kill any running SAP/BW processes to ensure that the SAPGui patching will proceed without any issues on our users PCs.

We can't rely on our users to manually shutdown the SAP Logon Pad or anything else before patching, thus plan to take matters into our own hands.

Has anyone got some code to do this? I'm a little green when it come to this sappy vbscript stuff....

Cheers

Shaun

PS: Running SAPGui 7.10 patch 7 ..... patching to patch 10.

Accepted Solutions (0)

Answers (1)

Answers (1)

Matt_Fraser
Active Contributor
0 Kudos

Did you ever figure out how to do this?  We'd like to do the same with SAPSetup 9.0, SAPGUI 7.30.

Matt_Fraser
Active Contributor
0 Kudos

I'm still working on this problem, but after some searching on MSDN/TechNet and a lot of experimentation, I've come up with the following bit of WMI/VBscript that works... mostly.  I'll explain the 'mostly' in a moment.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")

Set colService = objWMIService.ExecQuery _
    ("Select * from Win32_Service Where Name ='NWSAPAutoWorkstationUpdateSvc'")
For Each objService in colService
    Return = objService.StopService()
    WScript.Echo "RC: " & Return _
    & "Stopped SAPSetup Automatic Workstation Update Service"
Next

Set colProcess = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'saplogon.exe'")
For Each objProcess in colProcess
    Return = objProcess.Terminate()
    WScript.Echo "RC: " & Return _
    & "Stopped SAPLogon and SAPGUI"
Next

On Windows XP machines this seems to work fine at shutting down the 'SAP Automatic Workstation Update Service' and any running SAPLogon processes (including SAPGUI).  I haven't actually adapted this to work inside the NWSapSetup package event script yet, and you can see it's still got some bits for displaying return codes as part of testing and development -- I would probably modify those parts for the final script, as it stops execution until the user hits 'OK' on the popup window.

The problem is that in Windows 7 the first part for stopping the automatic update service runs into roadblocks with UAC (User Account Control).  The second part for shutting down running SAPGUIs works fine.  As written, the script simply fails to shut down the service, and the return code is 2, which equates to "Access Denied," even if the user has local administrator permissions.  I've figured out a way to get the script to run with elevated privileges, though I'm not yet sure how that's going to work if it's part of the package event script for the sapsetup program.  I expect it's probably going to be an issue, so any input from others would be very welcome here!  Also, it still results in the user getting a Windows popup asking if they want to allow the script to run, but at least they can click 'yes' and it will work.  It consists of putting a wrapper around the above script:

If WScript.Arguments.length = 0 Then

  Set objShell = CreateObject("Shell.Application")

  objShell.ShellExecute "wscript.exe", """" & _

  WScript.ScriptFullName & """" &_

  " RunAsAdministrator", , "runas", 1

Else

<<put above script here>>

End If

This basically checks to see if the script was called with any argument, and if not then it recursively calls itself again with an argument, which on this 'inner' execution goes to the 'Else' part except now with 'Run As Administrator' privileges.  This does depend upon the user (or script executor) already having local Administrator rights, but the sapsetup installation server has mechanisms to handle that which work quite well.  Still, though, I'm expecting problems getting a script to recursively call itself from within yet another script, so we'll see what happens.  I don't claim anything about coming up with that idea, by the way -- I found others in the non-SAP Microsoft world who had come up with it and just adapted it to my situation.

Anyone else already solved this UAC issue with a better plan?

Best regards,

Matt