![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Re: Script works well, but not as scheduled tasks ? "francois" <francois@newsgroup> wrote in message news:eVtRfj4SKHA.4028@newsgroup Quote: > Hello everybody, > > I have a vbs script which shutdowns all PC in OU. This script works very > well ! But, when I want to schedule this script with "Scheduled Tasks", it > does'nt work. It's very simple, when I schedule this script, absolutely > nothing takes place ! Yet, the configuration of the scheduled tasks seems > to be correct : > > - Run : C:\xxxxx\script.vbs (it's OK !) > - Run as : SERVER\admin (account and password are OK !) > > Why does'nt it work ? And how to shedule my script ? > I'm on Windows Server 2000, and here is my script : > > '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< > On Error Resume Next > > ldap_adress = _ > "LDAP://OU=MyPC, 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 > '<<<<< > > Set oShell = WScript.CreateObject ("WSCript.shell") > objRecord.MoveFirst > > Do Until objRecord.EOF > > name = objRecord.Fields("name").Value > name = UCase(Trim(name)) > > commande = "shutdown -s -m \\" & name & " -t 30" > Call oShell.run(commande, 0, False) > > objRecord.MoveNext > > Loop > '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< > > Thanks in advance for your help. > > > -- > François Lafont 1. Check the Task Scheduler log file. 2. Instead of invoking the above script directly, invoke the following batch file: @echo off echo %date% %time% %UserName% >> c:\test.txt cscript //nologo c:\françois.vbs 1>> c:\test.txt 2>>&1 echo %date% %time% >> c:\test.txt 3. Remove the line "On error resume next" from your script. It makes debuggin almost impossible. 4. Examine the file c:\test.txt. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Script works well, but not as scheduled tasks ? "francois" <francois@newsgroup> wrote in message news:ekveeE5SKHA.1232@newsgroup Quote: > Thank you for the answer. > > Pegasus [MVP] a écrit : > Quote: >> 2. Instead of invoking the above script directly, invoke the following >> batch file: >> @echo off >> echo %date% %time% %UserName% >> c:\test.txt >> cscript //nologo c:\françois.vbs 1>> c:\test.txt 2>>&1 >> echo %date% %time% >> c:\test.txt >> 3. Remove the line "On error resume next" from your script. It makes >> debuggin almost impossible. >> 4. Examine the file c:\test.txt. > Ok, I have done this. Nothing takes place like with directly the vbs > script. Here is the test.txt file : > > ------------------------------- > mar. 13/10/2009 0:56:39,15 Administrateur > mar. 13/10/2009 0:56:42,65 > ------------------------------- > > Nothing !?! > > It's very curious. When I invoke the script directly, I can see lot of > processes of the "shutdonwn" command in the "Windows Task Manager". It's > logical, 1 PC = 1 process. But as scheduled task, with a .bat file (like > above) or directly with the vbs script (like in my firt message), I don't > see processes of the "shutdonwn" command. It's very strange, does'nt it ? > -- > François Lafont suggested! |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Script works well, but not as scheduled tasks ? *** See below. "francois" <francois@newsgroup> wrote in message news:%23JVQ%235CTKHA.4144@newsgroup Quote: > Pegasus [MVP] a écrit : > Quote: >> Let's have a look at your script and your version of the batch file I >> suggested! > I'm sorry but I don't understand. I have done exactly what you said. I'm > going to show you. *** a certain batch file or script and the OP subsequently *** claimed that it did not work. In most cases the failure *** was caused by a poorly understood modification that *** the OP made. This is why I now always ask for the *** actual script or batch file. Quote: > 1) Here is my vbs script called shutdown.vbs. Notice that I removed the > line "On Error Resume Next" as you said : > > ------------------------------------------- > 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 > '<<<<<< > Set oShell = WScript.CreateObject ("WSCript.shell") > objRecord.MoveFirst > > Do Until objRecord.EOF > name = objRecord.Fields("name").Value > name = UCase(Trim(name)) > commande = "c:\Windows\System32\shutdown.exe -s -m \\" & name & " -t > 5" > Call oShell.run(commande, 0, False) > objRecord.MoveNext > Loop > ------------------------------------------- *** the background. It will be invisible to you. If you *** want to see the output generated by a console *** command then you need to use the Exec method, *** e.g. like so: Set oWshShell = CreateObject("WScript.Shell") commande = "c:\Windows\System32\shutdown.exe -s -m \\" & name & " -t 5" Set oExec = oWshShell.Exec(commande) While oExec.Status = 0 WScript.Sleep 500 Wend While Not oExec.StdOut.AtEndOfStream WScript.Echo oExec.StdOut.ReadLine Wend Quote: > 2) Here is my batch file, called go.bat : > ------------------------------------------- > @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 > ------------------------------------------- > > > 3) I create a schelude task : > > - Run : C:\xxxxx\go.bat (it's OK !) > - Run as : SERVER\admin (account and password are OK !) > > > 4) I start the schelude task. Nothing happens ! The test.txt file is > created. Here is the test.txt file : > > ------------------------------------------- > mar. 13/10/2009 19:42:11,27 admin > mar. 13/10/2009 19:42:14,75 > ------------------------------------------- > > No signalled error ?! > > Yet, the shutdown.vbs script works very well if I run it directly with the > command line : > > ------------------------------------------- > cscript shutdown.vbs (works very well ?) > ------------------------------------------- > > I don't understand. Have I forgotted an instruction that you asked me ? > > François Lafont then you will probably see why the shutdown command does not work. You could also do some experimenting of your own, e.g. like so: commande = "c:\Windows\System32\cmd.exe dir c:\" This should write the output from the "dir" command into your log file c:\test.txt. |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Script works well, but not as scheduled tasks ? francois wrote: Quote: > > 1) Here is my vbs script called shutdown.vbs. Notice that I > removed the line "On Error Resume Next" as you said : > > ------------------------------------------- > 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 > '<<<<<< > Set oShell = WScript.CreateObject ("WSCript.shell") > objRecord.MoveFirst > > Do Until objRecord.EOF > name = objRecord.Fields("name").Value > name = UCase(Trim(name)) > commande = "shutdown -s -m \\" & name & " -t 5" > Call oShell.run(commande, 0, False) > objRecord.MoveNext > Loop > ------------------------------------------- > > > 2) Here is my batch file, called go.bat : > > ------------------------------------------- > @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 > ------------------------------------------- > > > 3) I create a schelude task : > > - Run : C:\xxxxx\go.bat (it's OK !) > - Run as : SERVER\admin (account and password are OK !) > > > 4) I start the schelude task. Nothing happens ! The test.txt > file is created. Here is the test.txt file : > > ------------------------------------------- > mar. 13/10/2009 19:42:11,27 admin > mar. 13/10/2009 19:42:14,75 > ------------------------------------------- > > No signalled error ?! > > Yet, the shutdown.vbs script works very well if I run it > directly with the command line : > > ------------------------------------------- > cscript shutdown.vbs (works very well ?) > ------------------------------------------- Wscript.Echo line near the top and another one at the end so test.txt will reflect that shutdown.vbs is being executed to completion. Wscript.Echo Wscript.ScriptFullName & " started at " & now .... Wscript.Echo Wscript.ScriptFullName & " finished at " & now Once satisfied the script is running, I would try changing .run method to ..exec method. The difference being .run method creates a new seperate process while .exec is a child of the current process. -- Todd Vargo (Post questions to group only. Remove "z" to email personal messages) |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Script works well, but not as scheduled tasks ? "Todd Vargo" <tlvargo@newsgroup> wrote in message news:eE1jXsHTKHA.4360@newsgroup Quote: > francois wrote: Quote: >> >> 1) Here is my vbs script called shutdown.vbs. Notice that I >> removed the line "On Error Resume Next" as you said : >> >> ------------------------------------------- >> 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 >> '<<<<<< >> Set oShell = WScript.CreateObject ("WSCript.shell") >> objRecord.MoveFirst >> >> Do Until objRecord.EOF >> name = objRecord.Fields("name").Value >> name = UCase(Trim(name)) >> commande = "shutdown -s -m \\" & name & " -t 5" >> Call oShell.run(commande, 0, False) >> objRecord.MoveNext >> Loop >> ------------------------------------------- >> >> >> 2) Here is my batch file, called go.bat : >> >> ------------------------------------------- >> @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 >> ------------------------------------------- >> >> >> 3) I create a schelude task : >> >> - Run : C:\xxxxx\go.bat (it's OK !) >> - Run as : SERVER\admin (account and password are OK !) >> >> >> 4) I start the schelude task. Nothing happens ! The test.txt >> file is created. Here is the test.txt file : >> >> ------------------------------------------- >> mar. 13/10/2009 19:42:11,27 admin >> mar. 13/10/2009 19:42:14,75 >> ------------------------------------------- >> >> No signalled error ?! >> >> Yet, the shutdown.vbs script works very well if I run it >> directly with the command line : >> >> ------------------------------------------- >> cscript shutdown.vbs (works very well ?) >> ------------------------------------------- > Your shutdown.vbs does not contain any lines to create output. I would add > a > Wscript.Echo line near the top and another one at the end so test.txt will > reflect that shutdown.vbs is being executed to completion. > > Wscript.Echo Wscript.ScriptFullName & " started at " & now > ... > Wscript.Echo Wscript.ScriptFullName & " finished at " & now > > Once satisfied the script is running, I would try changing .run method to > .exec method. The difference being .run method creates a new seperate > process while .exec is a child of the current process. shutdown.vbs? Is it on the path or in the same directory as go.bat? /Al |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Script works well, but not as scheduled tasks ? "Al Dunbar" <alandrub@newsgroup> wrote in message news:OAsBo7HTKHA.1280@newsgroup Quote: > > "Todd Vargo" <tlvargo@newsgroup> wrote in message > news:eE1jXsHTKHA.4360@newsgroup Quote: >> francois wrote: Quote: >>> >>> 1) Here is my vbs script called shutdown.vbs. Notice that I >>> removed the line "On Error Resume Next" as you said : >>> >>> ------------------------------------------- >>> 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 >>> '<<<<<< >>> Set oShell = WScript.CreateObject ("WSCript.shell") >>> objRecord.MoveFirst >>> >>> Do Until objRecord.EOF >>> name = objRecord.Fields("name").Value >>> name = UCase(Trim(name)) >>> commande = "shutdown -s -m \\" & name & " -t 5" >>> Call oShell.run(commande, 0, False) >>> objRecord.MoveNext >>> Loop >>> ------------------------------------------- >>> >>> >>> 2) Here is my batch file, called go.bat : >>> >>> ------------------------------------------- >>> @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 >>> ------------------------------------------- >>> >>> >>> 3) I create a schelude task : >>> >>> - Run : C:\xxxxx\go.bat (it's OK !) >>> - Run as : SERVER\admin (account and password are OK !) >>> >>> >>> 4) I start the schelude task. Nothing happens ! The test.txt >>> file is created. Here is the test.txt file : >>> >>> ------------------------------------------- >>> mar. 13/10/2009 19:42:11,27 admin >>> mar. 13/10/2009 19:42:14,75 >>> ------------------------------------------- >>> >>> No signalled error ?! >>> >>> Yet, the shutdown.vbs script works very well if I run it >>> directly with the command line : >>> >>> ------------------------------------------- >>> cscript shutdown.vbs (works very well ?) >>> ------------------------------------------- >> Your shutdown.vbs does not contain any lines to create output. I would >> add a >> Wscript.Echo line near the top and another one at the end so test.txt >> will >> reflect that shutdown.vbs is being executed to completion. >> >> Wscript.Echo Wscript.ScriptFullName & " started at " & now >> ... >> Wscript.Echo Wscript.ScriptFullName & " finished at " & now >> >> Once satisfied the script is running, I would try changing .run method to >> .exec method. The difference being .run method creates a new seperate >> process while .exec is a child of the current process. > Has anyone thought to ask if the scheduled batch script is able to find > shutdown.vbs? Is it on the path or in the same directory as go.bat? > > /Al cscript //nologo shutdown.vbs 1>> c:\test.txt 2>>&1 lacks a full path definition for shutdown.vbs, it would still generate the following error message in c:\test.txt: Input Error: Can not find script file "shutdown.vbs". However, there is also a possibility that the OP has more than one file called "shutdown.vbs", which emphasises the point of your argument: When running a scheduled task then *all file names must be fully qualified*. |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Script works well, but not as scheduled tasks ? Pegasus [MVP] wrote: Quote: > "Al Dunbar" <alandrub@newsgroup> wrote in message > news:OAsBo7HTKHA.1280@newsgroup Quote: > > > > "Todd Vargo" <tlvargo@newsgroup> wrote in message Quote: Quote: Quote: > >> Your shutdown.vbs does not contain any lines to create output. I would > >> add a > >> Wscript.Echo line near the top and another one at the end so test.txt > >> will > >> reflect that shutdown.vbs is being executed to completion. > >> > >> Wscript.Echo Wscript.ScriptFullName & " started at " & now > >> ... > >> Wscript.Echo Wscript.ScriptFullName & " finished at " & now > >> > >> Once satisfied the script is running, I would try changing .run method Quote: Quote: Quote: > >> .exec method. The difference being .run method creates a new seperate > >> process while .exec is a child of the current process. > > Has anyone thought to ask if the scheduled batch script is able to find > > shutdown.vbs? Is it on the path or in the same directory as go.bat? > > > > /Al > While it is true that the line > > cscript //nologo shutdown.vbs 1>> c:\test.txt 2>>&1 > > lacks a full path definition for shutdown.vbs, it would still generate the > following error message in c:\test.txt: > > Input Error: Can not find script file "shutdown.vbs". > > However, there is also a possibility that the OP has more than one file > called "shutdown.vbs", which emphasises the point of your argument: When > running a scheduled task then *all file names must be fully qualified*. shutdown.vbs was not being run, but yes, a fully qualified path would remove doubt. -- Todd Vargo (Post questions to group only. Remove "z" to email personal messages) |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Script works well, but not as scheduled tasks ? On Oct 14, 5:43*am, "Todd Vargo" <tlva...@newsgroup> wrote: Quote: > Pegasus [MVP] wrote: Quote: > > "Al Dunbar" <aland...@newsgroup> wrote in message > >news:OAsBo7HTKHA.1280@newsgroup Quote: Quote: > > > "Todd Vargo" <tlva...@newsgroup> wrote in message Quote: Quote: > > >> Your shutdown.vbs does not contain any lines to create output. I would > > >> add a > > >> Wscript.Echo line near the top and another one at the end so test.txt > > >> will > > >> reflect that shutdown.vbs is being executed to completion. Quote: Quote: > > >> Wscript.Echo Wscript.ScriptFullName & " started at " & now > > >> ... > > >> Wscript.Echo Wscript.ScriptFullName & " finished at " & now Quote: Quote: > > >> Once satisfied the script is running, I would try changing .run method Quote: Quote: > > >> .exec method. The difference being .run method creates a new seperate > > >> process while .exec is a child of the current process. Quote: Quote: > > > Has anyone thought to ask if the scheduled batch script is able to find > > > shutdown.vbs? Is it on the path or in the same directory as go.bat? Quote: Quote: > > > /Al Quote: > > While it is true that the line Quote: > > cscript //nologo shutdown.vbs 1>> c:\test.txt 2>>&1 Quote: > > lacks a full path definition for shutdown.vbs, it would still generate the > > following error message in c:\test.txt: Quote: > > Input Error: Can not find script file "shutdown.vbs". Quote: > > However, there is also a possibility that the OP has more than one file > > called "shutdown.vbs", which emphasises the point of your argument: When > > running a scheduled task then *all file names must be fully qualified*. > Adding the lines I suggested would expose the fact that the intended > shutdown.vbs was not being run, but yes, a fully qualified path would remove > doubt. > > -- > Todd Vargo > (Post questions to group only. Remove "z" to email personal messages) cd /d "%~dp0" |
My System Specs![]() |
| | #9 (permalink) |
| | Re: Script works well, but not as scheduled tasks ? francois wrote: Quote: > Firstly, thanks everybody for your answer, which I read > carefully. Quote: > To make sure, that there is no ambiguity left, I'm going to > explain what 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 I like > understanding what I do. :-) -- Todd Vargo (Post questions to group only. Remove "z" to email personal messages) |
My System Specs![]() |
| | #10 (permalink) |
| | Re: Script works well, but not as scheduled tasks ? "francois" <francois@newsgroup> wrote in message news:OzCRoeRTKHA.504@newsgroup Quote: > Todd Vargo a écrit : > Quote: Quote: >>> To make sure, that there is no ambiguity left, I'm going to explain what >>> 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 I >>> 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 task > ? Why ? > -- > François Lafont tasks behave in exactly the same way as foreground tasks. It's only that you cannot capture the console output from a Run command. When trying to solve a problem, it often helps to simplify things. In order 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 expected, 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? |
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 | |||