Close down apps script
Windows Server Forum Index Windows Server
Server discussion on Windows platform.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web winserverhelp.com
Close down apps script

 
Post new topic   Reply to topic    Windows Server Forum Index -> Programming
Author Message
Maurice1972
Guest





Posted: Fri Jan 07, 2005 9:31 pm    Post subject: Close down apps script Reply with quote

I'm writing a script that will prompt the user to close down an application.
As it's written now it works but only when they click on OK. If they click
on cancel or escape it gives an error. I'm pretty sure that it's because of
the way I'm closing the app (using a loop to cancel the process by name).
Does anyone have any suggestions on a way to tighten or rewrite this script?
==
strComputer= "."
Dim MyVar
MyVar = MsgBox ("In order to begin the installation, Notepad will be closed.
Click OK to close notepad now or cancel to delay the installation.", 65,
"Cancel process example")
' MyVar contains either 1 or 2, depending on which button is clicked.
If MyVar = 1 then Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'notepad.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
If MyVar = 0 then msgbox "Delaying installation"
Back to top
Torgeir Bakken (MVP)
Guest





Posted: Fri Jan 07, 2005 10:02 pm    Post subject: Re: Close down apps script Reply with quote

Maurice1972 wrote:

Quote:
I'm writing a script that will prompt the user to close down an application.
As it's written now it works but only when they click on OK. If they click
on cancel or escape it gives an error. I'm pretty sure that it's because of
the way I'm closing the app (using a loop to cancel the process by name).
Does anyone have any suggestions on a way to tighten or rewrite this script?
Hi


'--------------------8<----------------------
strComputer= "."
Dim MyVar
MyVar = MsgBox("In order to begin the installation, Notepad will be closed." _
& vbCrLf & vbCrLf _
& "Click OK to close notepad now or cancel to delay the installation.", _
65, "Cancel process example")

' MyVar contains either 1 or 2, depending on which button is clicked.
If MyVar = 1 Then
Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'notepad.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next

Else
msgbox "Delaying installation"
End If
'--------------------8<----------------------


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx
Back to top
SubnetJO
Guest





Posted: Fri Jan 07, 2005 10:47 pm    Post subject: RE: Close down apps script Reply with quote

I often have the same problem with "msgbox".
When I use the "Browse for Folder" dialog box, for example.
If the user click "cancel", he get an error.

I used an awful workaround.
But works...
I put "on error resume next" before the msgbox line in the code.

You may want to create a "subroutine" containing only the msgbox an the
related code, to apply the "on error resume netx" option only to this portion
of the script.

I hope this can help.
SubnetJO
Italy
Back to top
Maurice1972
Guest





Posted: Sat Jan 08, 2005 2:01 am    Post subject: RE: Close down apps script Reply with quote

Thanks for all the help guys! Here's the script as it stands now:
==<>==

' *** Define computer as local machine ***
strComputer= "."

' *** Set variable MyVar ***
Dim MyVar

' *** Dialog box text defined and button responses are pased to the MyVar
variable ****
MyVar = MsgBox ("Adobe Acrobat Standard is about to be installed."& vbCrLf &
"Is it OK to close all Adobe products now and begin the installation?" _
& vbCrLf & vbCrLf _
& "PLEASE SAVE ALL WORK BEFORE CLICKING YES." _
& vbCrLf & vbCrLf _
& "Click YES to close all apps now or NO to delay the
installation.", 4, "Adobe Acrobat installation notice")
' MyVar contains either 6 or 0, depending on which button is clicked.

' *** If MyVar = 6 (or YES) then close the defined processes
If MyVar = 6 Then

' *** First process defined and closed ***
Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'acrobat.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next

' *** Second process defined and closed ***
Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'acrodist.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next

' *** Third process defined and closed ***
Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'acrotray.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
' *** If the result is other than 6 show message ***
Else msgbox "Delaying installation."

' *** Return code of 1 if the user clicked on No
Wscript.Quit(1)
End If
==<>==

Subroutines are something I haven't worked with much, so any advice would be
welcome.

"SubnetJO" wrote:

Quote:
I often have the same problem with "msgbox".
When I use the "Browse for Folder" dialog box, for example.
If the user click "cancel", he get an error.

I used an awful workaround.
But works...
I put "on error resume next" before the msgbox line in the code.

You may want to create a "subroutine" containing only the msgbox an the
related code, to apply the "on error resume netx" option only to this portion
of the script.

I hope this can help.
SubnetJO
Italy
Back to top
 
Post new topic   Reply to topic    Windows Server Forum Index -> Programming All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




New Topics Powered by phpBB