![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #11 (permalink) |
| | Re: Script works well, but not as scheduled tasks ? Pegasus [MVP] wrote: Quote: > "francois" <francois@newsgroup> wrote in message > news:OzCRoeRTKHA.504@newsgroup Quote: > > Todd Vargo a écrit : > > Quote: > >>> To make sure, that there is no ambiguity left, I'm going to explain Quote: Quote: Quote: > >>> I exactly did. But, before that, I'd like to ask you why it works with > >>> the .Exec method and why it doesn't with the .Run method ? Sorry, but Quote: Quote: Quote: > >>> like understanding what I do. :-) > >> > >> Read my first post again for explanation. > > I have seen already: :-) > > - .run method creates a new seperate process > > - .exec is a child of the current process > > > > But, it is forbidden to create a new separate process in a scheduled Quote: Quote: > > ? Why ? > > -- > > François Lafont > It is perfectly OK to use the Run method under a scheduled task. Scheduled > tasks behave in exactly the same way as foreground tasks. It's only that Quote: > cannot capture the console output from a Run command. > > When trying to solve a problem, it often helps to simplify things. In Quote: > to prove that the Run method works when scheduled, I created the following > simple script: > > Set oWshShell = CreateObject("WScript.Shell") > sCmd = oWshShell.ExpandEnvironmentStrings("%comspec% /c dir c:\ > > c:\test.txt") > oWshShell.Run sCmd > > I then ran it under the Task Scheduler and it worked exactly as I Quote: > creating some output lines in c:\test.txt. The scheduled task looked like > so: > > cscript c:\test.vbs > > In an earlier reply I recommended that you should capture the output from > the Exec method. I did not respond to my suggestion. What did you see? was not inheriting the admin rights. Someone will have to verify as I don't have XP available. -- Todd Vargo (Post questions to group only. Remove "z" to email personal messages) |
My System Specs![]() |
| | #12 (permalink) |
| | Re: Script works well, but not as scheduled tasks ? "Todd Vargo" <tlvargo@newsgroup> wrote in message news:uvZ9udUTKHA.3404@newsgroup Quote: > Pegasus [MVP] wrote: Quote: >> "francois" <francois@newsgroup> wrote in message >> news:OzCRoeRTKHA.504@newsgroup Quote: >> > Todd Vargo a écrit : >> > >> >>> To make sure, that there is no ambiguity left, I'm going to explain Quote: Quote: >> >>> I exactly did. But, before that, I'd like to ask you why it works >> >>> with >> >>> the .Exec method and why it doesn't with the .Run method ? Sorry, but Quote: Quote: >> >>> like understanding what I do. :-) >> >> >> >> Read my first post again for explanation. >> > >> > I have seen already: :-) >> > - .run method creates a new seperate process >> > - .exec is a child of the current process >> > >> > But, it is forbidden to create a new separate process in a scheduled Quote: Quote: >> > ? Why ? >> > -- >> > François Lafont >> It is perfectly OK to use the Run method under a scheduled task. >> Scheduled >> tasks behave in exactly the same way as foreground tasks. It's only that Quote: >> cannot capture the console output from a Run command. >> >> When trying to solve a problem, it often helps to simplify things. In Quote: >> to prove that the Run method works when scheduled, I created the >> following >> simple script: >> >> Set oWshShell = CreateObject("WScript.Shell") >> sCmd = oWshShell.ExpandEnvironmentStrings("%comspec% /c dir c:\ > >> c:\test.txt") >> oWshShell.Run sCmd >> >> I then ran it under the Task Scheduler and it worked exactly as I Quote: >> creating some output lines in c:\test.txt. The scheduled task looked like >> so: >> >> cscript c:\test.vbs >> >> In an earlier reply I recommended that you should capture the output from >> the Exec method. I did not respond to my suggestion. What did you see? > Did your test include the RunAs requirement? I suspect the OP's new > process > was not inheriting the admin rights. Someone will have to verify as I > don't > have XP available. > > -- > Todd Vargo > (Post questions to group only. Remove "z" to email personal messages) > |
My System Specs![]() |
| | #13 (permalink) |
| | Re: Script works well, but not as scheduled tasks ? Pegasus [MVP] wrote: Quote: > Todd Vargo wrote: Quote: Quote: Quote: > >> In an earlier reply I recommended that you should capture the output Quote: Quote: Quote: > >> the Exec method. I did not respond to my suggestion. What did you see? > > Did your test include the RunAs requirement? I suspect the OP's new > > process > > was not inheriting the admin rights. Someone will have to verify as I > > don't > > have XP available. > Where exactly do you suggest I look? the exact same scheduled task/RunAs admin scenario as presented by the OP to perform your testing? From the command line that you posted, it appears that your testing was performed while logged into an admin account. -- Todd Vargo (Post questions to group only. Remove "z" to email personal messages) |
My System Specs![]() |
| | #14 (permalink) |
| | Re: Script works well, but not as scheduled tasks ? "francois" <francois@newsgroup> wrote in message news:%237KbAwgTKHA.5004@newsgroup Quote: > Pegasus [MVP] a écrit : > Quote: >> In an earlier reply I recommended that you should capture the output from >> the Exec method. I did not respond to my suggestion. What did you see? > Ok, I'm going to try to answer your question. I think I have progress a > little (see at the end of the message). > > Here is Run_shutdown.bat file: > > --------------------------------- > @echo off > echo %date% %time% %UserName% >> c:\test.txt > cscript //nologo shutdown.vbs 1>> c:\test.txt 2>>&1 > echo %date% %time% >> c:\test.txt > --------------------------------- > > In the *same* directory, there is shutdown.vbs file: > > --------------------------------- > ldap_adress = _ > "LDAP://OU=Ordinateurs, DC=yourcenar, DC=local" > '<<<<<<<<<< > Set objConnection = Wscript.createObject("ADODB.Connection") > Call objConnection.open ("Provider=ADsDSOObject;") > Set objCommand = Wscript.createObject("ADODB.Command") > objCommand.activeConnection = objConnection > objCommand.commandText = _ > "<" & ldap_adress & ">;" & _ > "(ObjectCategory=computer);" & _ > "name;" & _ > "subtree" > Set objRecord = objCommand.execute > objRecord.MoveFirst > '<<<<<<<<<< > > Set oShell = WScript.CreateObject ("WSCript.shell") > > Do Until objRecord.EOF > > name = objRecord.Fields("name").Value > name = UCase(Trim(name)) > > '######################################## > 'It's just for testing the script only on > '7 PC. If I remove this "If", the script > 'try to shutdown 226 PC and it's very long... > '######################################## > If Left(name, 3) = "SDP" Then > commande = "shutdown -r -m \\" & name & " -t 01" > Wscript.Echo name > Set oExec = oShell.Exec(commande) > While oExec.Status = 0 > WScript.Sleep 500 > Wend > While Not oExec.StdOut.AtEndOfStream > WScript.Echo oExec.StdOut.ReadLine > Wend > End If > > objRecord.MoveNext > > Loop > --------------------------------- > > I run this scheduled task : > - Run : C:\Run_shutdown.bat > - Run as : administrateur (administrator in french, it's the domain's > administrator account) > > The script is slow but works well. > Here is c:\test.txt : > > --------------------------------- > ven. 16/10/2009 3:31:31,35 Administrateur > SDP-HPS-01 > SDP-HPS-02 > Le chemin reseau n'a pas ete trouve. > # I translate in english : "the network path not found" > SDP-HPS-03 > SDP-LB-01 > SDP-LB-03 > SDP-LB-02 > SDP-DOS-01 > ven. 16/10/2009 3:32:43,29 > --------------------------------- > > The message is logical because the "SDP-HPS-02" PC is already shutdown. > > It's very strange, I show you another interesting test. > I keep the same Run_shutdown.bat file but I just change shutdown.vbs file. > > I try the script for all PC in my OU (226 PC!) but I remove this : > > -------------------------------------------- > Set oExec = oShell.Exec(commande) > While oExec.Status = 0 > WScript.Sleep 500 > Wend > While Not oExec.StdOut.AtEndOfStream > WScript.Echo oExec.StdOut.ReadLine > Wend > -------------------------------------------- > > If I don't remove this, with 226 PC, the script is too long (if a PC is > already shutdown, boum!, it is necessary to wait 3 minutes and if there > are already 100 shutdown PC...) > > Here is shutdown.vbs : > > --------------------------------- > ldap_adress = _ > "LDAP://OU=Ordinateurs, DC=yourcenar, DC=local" > '<<<<<<<<<< > Set objConnection = Wscript.createObject("ADODB.Connection") > Call objConnection.open ("Provider=ADsDSOObject;") > Set objCommand = Wscript.createObject("ADODB.Command") > objCommand.activeConnection = objConnection > objCommand.commandText = _ > "<" & ldap_adress & ">;" & _ > "(ObjectCategory=computer);" & _ > "name;" & _ > "subtree" > Set objRecord = objCommand.execute > objRecord.MoveFirst > '<<<<<<<<<< > > Set oShell = WScript.CreateObject ("WSCript.shell") > > Do Until objRecord.EOF > > name = objRecord.Fields("name").Value > name = UCase(Trim(name)) > > '################################## > 'No test, shutdown for ALL PC (226) > '################################## > commande = "shutdown -r -m \\" & name & " -t 01" > Wscript.Echo name > Set oExec = oShell.Exec(commande) > > objRecord.MoveNext > > Loop > --------------------------------- > > then, I have an error in the c:\test.txt file: > > --------------------------------- > ven. 16/10/2009 4:17:54,46 Administrateur > CDI-NEC-D > S129-PROF > S129-POSTE02 > S129-POSTE01 > S129-POSTE03 > > [snip] > > S115-LB-P > S115-LB-20 > S113-DOT-P > S130-LB-P > S130-DOC-05 > SADM-LS-ADJ > S117-LS-P > C:\shutdows.vbs(27, 9) WshShell.Exec: Un peripherique attache au systeme > ne fonctionne pas correctement. > --------------------------------- > > I translate : "a peripheral attached on the system doesn't work well". > > I notice that the message occurs every time about the PC 200 and it is not > the same PC every time. > > Interesting, but I have no explanation!? > -- > François Lafont with your script or with the scheduled task. In other words, if you created yourself a batch file like the one below then you would get the same error, regardless of you running it from the Command Prompt or as a scheduled task. @echo off echo %date% %time% > c:\Log.txt for /F %%a in (c:\PCs.txt) do shutdown -r -m \\%%a -t 01 1>>c:\Log.txt 2>>&1 PCs.txt ====== SDP-HPS-01 SDP-HPS-02 SDP-HPS-03 SDP-LB-01 SDP-LB-03 SDP-LB-02 SDP-DOS-01 |
My System Specs![]() |
| | #15 (permalink) |
| | Re: Script works well, but not as scheduled tasks ? "francois" <francois@newsgroup> wrote in message news:ub1QJdFUKHA.3404@newsgroup Quote: > Pegasus [MVP] a écrit : > Quote: >> You will probably find that the intermittent error message has nothing to >> do with your script or with the scheduled task. > Damn it. If I have to choose, I would prefer a script's problem. :-) > Quote: >> In other words, if you created yourself a batch file like the one below >> then you would get the same error, regardless of you running it from the >> Command Prompt or as a scheduled task. > Yes indeed! I did your test with the Command Prompt and I had problem. > There were lots of opened windows (1 "shutdown" command = 1 opened window) > and I had windows which display this message: "L'application n'a pas > reussi a s'initialiser correctement (0xc0000142). Cliquez sur OK pour > arreter l'application". I translate: "The application did not succeed has > to initialiser correctly. Click on OK to stop it". > > It's the "shutdown" command which has a problem and it's my fault. Indeed, > my server is Win2000 server which has no "shutdown" command natively. I > copied the shutdown.exe file of a Windows XP and put it in system32 > directoy of my Win2000 server: it was a bad idea, I'm sorry. the > "Shutdown.exe" file is available on the Microsoft Windows 2000 Resource > Kit only and the "Shutdown.exe" file of this kit is different of the the > "Shutdown.exe" file of Windows XP, the syntax is different: > > XP --> shutdown -r -m \\computername -t 30 > Win2000 --> shutdown \\computername /r /t:30 > > Then, in the system32 directory of my Win2000 server, I removed the > "Shutdown.exe" file which I copied and I copied the "Shutdown.exe" file of > the Microsoft Windows 2000 Resource Kit. > > That's better now and I have the impression that I am close to purpose, > but there a thing that I can't understand. I'm going to explain. > > I tried this .vbs script : test.vbs > > -------------------------------------------- > 'The beginning is the same as the earlier message > '[snip] > > Set oShell = WScript.CreateObject ("WSCript.shell") > > Do Until objRecord.EOF > > name = objRecord.Fields("name").Value > name = UCase(Trim(name)) > > 'The syntax is different > commande = "Shutdown.exe \\" & name & " /R /T:01" > > Set oExec = oShell.Exec(commande) > > objRecord.MoveNext > Loop > -------------------------------------------- > > with this .bat file : run_test.bat > > -------------------------------------------- > @echo off > cscript //nologo test.vbs > -------------------------------------------- > > It seems to work well > - with the Command Prompt > - as scheduled task > I tested this remotly a few times. Really, It seems to be OK. > > But, I tried this too (I removed the .Exec method and I tried the .Run > method) : > > -------------------------------------------- > 'The beginning is the same as the earlier message > '[snip] > > Set oShell = WScript.CreateObject ("WSCript.shell") > > Do Until objRecord.EOF > > name = objRecord.Fields("name").Value > name = UCase(Trim(name)) > > 'The syntax is different > commande = "Shutdown.exe \\" & name & " /R /T:01" > > '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< > Call oShell.Run(commande, 0, False) > '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< > > objRecord.MoveNext > Loop > -------------------------------------------- > > It seems to work well with the Command Prompt, but I doesn't work as > scheduled task. Why? > > Thank you for your help Pegasus, I think I'm making progress in my > problem. > > > -- > François Lafont simplify it until it works or until the cause of the failure becomes obvious. This technique allowed you to determine that it was *not* your script that caused the problem with shutdown.exe and it was *not* the Task Scheduler but it was shutdown.exe itself. Now apply the same technique to your exec/run methods. I previously recommended that you could use something simple such as commande = "c:\Windows\System32\cmd.exe /c dir c:\ > c:\test.txt" Give it a try! |
My System Specs![]() |
| | #16 (permalink) |
| | Re: Script works well, but not as scheduled tasks ? "francois" <francois@newsgroup> wrote in message news:#CSwDrQUKHA.4000@newsgroup Quote: > Pegasus [MVP] a écrit : > Quote: >> As I said before, if you have a problem with some complex code, try to >> simplify it until it works or until the cause of the failure becomes >> obvious. This technique allowed you to determine that it was *not* your >> script that caused the problem with shutdown.exe and it was *not* the >> Task Scheduler but it was shutdown.exe itself. > Do you think my shutdown.exe file has a problem? > Quote: >> Now apply the same technique to your exec/run methods. > Ok, you are right. Then, I wanted to test this : (test.bat) > > ------------------------------------------ > @echo off > echo %date% %time% > c:\Log.txt > for /F %%a in (c:\PCs.txt) do shutdown \\%%a /T:01 1>>c:\Log.txt 2>>&1 > ------------------------------------------ > > With PC.txt like this : > > ------------------------------------------ > CDI-LS-02 > CDI-LS-03 > CDI-LS-07 > ... > ------------------------------------------ > > Like your example in earlier reply, but with the "good" shutdown command. > It's a simple script, doesn't it ? can go wrong... ;-) Quote: > All the shutdown commands were started sequentialy but with waiting for > the end of the previous shutdown command. Then, the script is very long > (if a PC is already shutdown, just one shutdown command can take 5 > minutes, and I have 226 PCs). > > Is it possible to change the test.bat file so that the shutdown commands > start sequentialy but without waiting for the end of the previous command? ------------------------------------------ @echo off echo %date% %time% > c:\Log.txt for /F %%a in (c:\PCs.txt) do START "" shutdown \\%%a /T:01 1>>c:\Log.txt 2>>&1 ------------------------------------------ If not, the start command may need some tweaking. But note that the output collected in log.txt will be that of the START command, not the command it starts. You cannot have asynchronously started tasks sending their output syunchronously into one text file. If you really need to collect that info, you could launch a shutdownbatch file that uses a log file whose name is based on the computer being shutdown, and then concatenate them for review when everything is finished. /Al |
My System Specs![]() |
| | #17 (permalink) |
| | Re: Script works well, but not as scheduled tasks ? "francois" <francois@newsgroup> wrote in message news:#4Dslm1VKHA.4416@newsgroup Quote: > Sorry for my late answer. > > Al Dunbar a écrit : > Quote: Quote: >>> All the shutdown commands were started sequentialy but with waiting for >>> the end of the previous shutdown command. Then, the script is very long >>> (if a PC is already shutdown, just one shutdown command can take 5 >>> minutes, and I have 226 PCs). >>> >>> Is it possible to change the test.bat file so that the shutdown commands >>> start sequentialy but without waiting for the end of the previous >>> command? >> This might do the trick: >> >> ------------------------------------------ >> @echo off >> echo %date% %time% > c:\Log.txt >> for /F %%a in (c:\PCs.txt) do START "" shutdown \\%%a /T:01 1>>c:\Log.txt >> 2>>&1 >> ------------------------------------------ >> >> If not, the start command may need some tweaking. >> >> But note that the output collected in log.txt will be that of the START >> command, not the command it starts. You cannot have asynchronously >> started tasks sending their output syunchronously into one text file. If >> you really need to collect that info, you could launch a shutdownbatch >> file that uses a log file whose name is based on the computer being >> shutdown, and then concatenate them for review when everything is >> finished. > Ok, I have used your remarks and I have tested this : > > Here is Run.bat file : > --------------------------- > @echo off > for /F %%a in (PCs.txt) do START "" /B cmd.exe /C shutdown.bat %%a > 1>>LogStart\Log%%a.txt 2>>&1 > --------------------------- > > Where PCs.txt and shutdown.bat are in the same folder as Run.bat. it needs to know it is in the same folder. Names such as "shutdown.bat" or "logstart\log%%a.txt" are relative to the current folder, which may not necessarily be the folder containing the batch file. This has the expected effect when you double-click a batch file in windows explorer, but this is not guaranteed for batch files run by other methods. It is always best to provide explicit paths. In a batch file, the folder containing the batch file can be referenced as "%~dp0", so shutdown.bat becomes "%~dp0\shutdown.bat". Quote: > Here is PCs.txt file : > --------------------------- > CDI-DOC-O > CDI-DOS-01 > CDI-DOS-02 > CDI-LB-01 > CDI-LB-02 > ... > ... contains the name of the 226 PCs of the domain > --------------------------- > > Here is shutdown.bat file > --------------------------- > shutdown.exe /R \\%1 /T:01 /Y 1>>LogShutdown\Log%1.txt 2>>&1 > --------------------------- > > If I run the Run.bat file from the Command Prompt, I have absolutely no > problem. > > 1) in the LogStart folder, I have 226 log files of the form of > Log<ComputerName>.txt. > 2) in the LogShutdown folder, I have 226 log files of the form of > Log<ComputerName>.txt too. > > I concatenate them in 2 files : > > 1) LogStart.txt which is as follows : > --------------------------- > C:\XXX>shutdown.exe /R \\S5-LS-03 /T:01 /Y 1>>LogShutdown\LogS5-LS-03.txt > 2>>&1 > > C:\XXX>shutdown.exe /R \\S5-LS-04 /T:01 /Y 1>>LogShutdown\LogS5-LS-03.txt > 2>>&1 > --------------------------- > > 2) LogShutdown.txt which is as follows : > --------------------------- > Shutdown:\\S9-LS-07 > Initiate System Shutdown failed. > # It's ok, the PC was already shutdown > > Shutdown:\\SDP-LB-01 > ... > --------------------------- > > No message error, no problem. > > > Now, I test the same Run.bat script as above, but as a scheduled task. Of > course, it doesn't work, especially for the last 20 PCs of the PCs.txt > list. > > > 1) in the LogStart folder, I have 226 log files of the form of > Log<ComputerName>.txt, but the 20 last ones are empty (the files exist but > their sizes are equal to 0 ko) > 2) in the LogShutdown folder, I have only *206* log files of the form of > Log<ComputerName>.txt. The missing files correspond to those the sizes of > which are equal to 0 ko. > > So, I have no error message, just empty log files or missing log files. suggest that shutdown.bat was not successfully called on those occasions. the startup files have zero length because their output is provided by the shutdown.bat file which did not run. Quote: > Of course, I want to notice that I have really waited for the scheduled > task to be finished (at least 20 minutes). It's strange, isn't it ? Do you > have an idea ? terminates, that may have something to do with it. Quote: > I'm really under the impression that in a scheduled task the number of > created proccessus is limited. Quote: > I notice that with a vbs file like this : > -------------------------------- > ... > commande = _ > "Shutdown.exe \\" & name & " /T:30 " & message & " /Y" > Set oExec = oShell.Exec(commande) > ... > -------------------------------- > > I have absolutely no problem with the Command Prompt *and* as a scheduled > task (I have really tested this a lot of times and It's ok). > > But if I use the .Run method like this : > > -------------------------------- > ... > commande = _ > "Shutdown.exe \\" & name & " /T:30 " & message & " /Y" > Call oShell.Run(commande) > ... > -------------------------------- > > It doesn't work as a scheduled task. I thought my previous test (with the > Run.bat file) was going to give me indications, but finally it didn't. ..run, but I forget the details. Quote: > To sum up, I have a script which works, but there are things that I can't > explain. (and therefore understand everything perfectly) or would you rather have a solution to a specific problem? /Al |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Using PowerShell script to create a list of Scheduled tasks | PowerShell | |||
| Where are kept Scheduled tasks? | Vista General | |||
| scheduled tasks | Vista General | |||
| Scheduled Tasks | Vista General | |||
| scheduled tasks | Vista performance & maintenance | |||