Newsgroup: it.comp.lang.visual-basic
Titolo: Chiudere un programma

Ragazzi ho bisogno del vostro aiuto,
ho bisogno di creare un file che:
1) apra automaticamente un determinato programma
2) dopo un determinato periodo (che indicherò io) si dovrà chiudere
3) una volta chiuso si deve riaprire dopo un tot di minuti
Premetto che non sono molto esperto col codice, quindi chiedo il vostro
aiuto.
In internet sono riuscito a trovare questo codice salvato con
l'estensione .vbs
'Start code
set WshShell = CreateObject("WScript.Shell")
WshShell.run"Notepad"
WScript.Sleep 2000
WshShell.SendKeys"%fe"
'End code
Questo codice funziona, soltanto che il programma non ha la barra dei
menù e quindi non posso chiuderlo con la stringa
WshShell.SendKeys"%fe"
C'è un'altro modo per chiudere il programma?
Grazie anticipatamente per il vostro aiuto

 C'è un'altro modo per chiudere il programma?
Sempre in vbs  (PS: ci sono NG piu adatti per questo next time ...)
Dim WShell, oExec
set WShell = WScript.CreateObject("WScript.Shell")
set oExec = WShell.Exec("calc")
WScript.Sleep 100
WScript.Echo "Chiudero la calc tra 3 secondi"
'WScript.Echo "status" &">>>>" & oExec.Status
WScript.Sleep 3000 ' in millisecondi
oExec.Terminate()
' tot secondi riapri la calcolatrice
'WScript.Sleep 100000
'set oExec = WShell.Exec("calc")
'ecc
--
Fosco

Fosco ha scritto:

grazie Fosco il tuo codice funziona benissimo mi hai risorto un
problema che per me era grandissimo.
Non mi sono alcune cose:
che significa in termini semplici la stringa 'WScript.Echo "status"
&">>>>" & oExec.Status ?
Tu hai betto prima che ci sono NG più adatti, me ne sapresti dire
qualcuno?
Grazie anticipatamente per il tuo aiuto e per la tua risposta
Bixio

qualcuno?
c'e' quello italiano ma e' poco frequemtato ti do i 2 microsoft che sono
in Inglese ed un paio di link sparsi :
news:microsoft.public.scripting.vbscript        (microsoft.public.scripting.vbscript)
news:microsoft.public.scripting.wsh         (microsoft.public.scripting.wsh)
Questo sotto e' l'help del WSH con numerosi esempi ( sopra il mega)
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
http://download.microsoft.com/download/winscript56/Install/5.6/W982KMeXP/EN-US/scrdoc56en.exe
Download and install WSH 5.6 from here:
http://msdn.microsoft.com/downloads/list/webdev.asp
Scripts Ufficiale
http://www.microsoft.com/italy/scripting/
http://msdn.microsoft.com/scripting/
http://www.w3schools.com/
Basics
http://www.microsoft.com/technet/scriptcenter/learnit.mspx
http://www.microsoft.com/technet/scriptcenter/scripts/default.mspx
InIzio wsh ( samples)
http://www.jsware.net/jsware/scripts.php3#msiprog
http://www.robvanderwoude.com/robnav.html
Windows VBScript Utilities » 
www.billsway.com/vbspage/
Windows Tweaks & Tips » 
www.billsway.com/notes_public/
T Lavedas' WSH Scripts
 
http://www.pressroom.com/~tglbatch/wshindex.html
http://www.foxitaly.com/risorsetecniche/ShellApplication.htm
http://www.activexperts.com/activmonitor/windowsmanagement/
CLR SCRIPT
http://www.clrsoftware.com/clrscript/
AutoItX
http://www.hiddensoft.com/AutoIt/
AutoItX solo dll
http://www.hiddensoft.com/cgi-bin/countdown.pl?AutoIt/AutoItX.zip
negli esempi cambia "Untitled - Notepad" in "Senza nome - Blocco note"
e "Calculator" in "Calcolatrice"
--
Fosco

&">>>>" & oExec.Status ?
Exec Method
WshScriptExec Object
Language
VBScript
Runs an application in a child command-shell, providing access to the
StdIn/StdOut/StdErr streams.
object.Exec(strCommand)
strCommand
String value indicating the command line used to run the script. The command line should appear exactly as it would if
you typed it at the command prompt.
Remarks
The Exec method returns a WshScriptExec object, which provides status and error information about a script run with Exec
along with access to the StdIn, StdOut, and StdErr channels. [1]The Exec method allows the execution of command line
applications only. [1]The Exec method cannot be used to run remote scripts. Do not confuse the Exec method with the
Execute method (of the WshRemote object).
Example
The following example demonstrates the basics of the Exec method.
'[VBScript]
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("calc")
Do While oExec.Status = 0
     WScript.Sleep 100
Loop
WScript.Echo oExec.Status
'[1]
'la nota dolente e' che NON si puo' interagire per esempio cosi ' :
set oShell = CreateObject("WScript.Shell")
oShell.run"notepad",3
WScript.Sleep 500
oShell.run"Clipbrd",2
'Run Method
object.Run(strCommand, [intWindowStyle], [bWaitOnReturn])
pero' e' interessante e sfruttabile il :
bWaitOnReturn
Optional. Boolean value indicating whether the script should wait for the program to finish executing before continuing
to the next statement in your script. If set to true, script execution halts until the program finishes, and Run returns
any error code returned by the program. If set to false (the default), the Run method returns immediately after starting
the program, automatically returning 0 (not to be interpreted as an error code).
intWindowStyle :
intWindowStyle Description
0 Hides the window and activates another window.
1 Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size
and position. An application should specify this flag when displaying the window for the first time.
2 Activates the window and displays it as a minimized window.
3 Activates the window and displays it as a maximized window.
4 Displays a window in its most recent size and position. The active window remains active.
5 Activates the window and displays it in its current size and position.
6 Minimizes the specified window and activates the next top-level window in the Z order.
7 Displays the window as a minimized window. The active window remains active.
8 Displays the window in its current state. The active window remains active.
9 Activates and displays the window. If the window is minimized or maximized, the system restores it to its original
size and position. An application should specify this flag when restoring a minimized window.
10 Sets the show-state based on the state of the program that started the application.
--
Fosco

 finish executing before continuing  to the next statement in your script.
ahh ecco l'esempio pratico :
set oShell = CreateObject("WScript.Shell")
oShell.run"notepad",3,true
WScript.Sleep 500
oShell.run"Clipbrd"
--
Fosco

Fosco ha scritto:

Grazie mille Fosco mi hai aiutato tantissimo Grazie ancora
Bixio