After experiencing a lot of down time, We decided to move this site to CrystalTech.com. CrystalTech.com is powered by only the finest Windows servers providing the best performance, reliability, and value anywhere.

 Wshshell.run "cmd.exe" doesn?t work in scheduler

Author Message
Chencho
  • Total Posts : 1
  • Scores: 0
  • Reward points : 0
  • Joined: 6/17/2004
  • Location:
Wshshell.run "cmd.exe" doesn?t work in scheduler - Thursday, June 17, 2004 8:30 PM
0
Hi , everybody.

I?m new in the world of vbs, and I need big help for a script in Windows 2000 Advanced Server and Windows 2000 Professional.

This script works perfectly when I do double click on it, but when I try to program a task with the scheduler (AT and Task Scheduler of Windows), Windows says that it?s running, and when the task is finalized, there is only the file that is before WshShell.Run "cmd.exe". The name of the file is num2.txt, that is created, but not edited.

That means that the script do the first orders, but when it arrives to this point, it doesn?t continues with the next instructions.

I tried to manipulate the style of window, but how the script uses keystrokes, only works to me with style 9.

This is the code:

Arxiu = "IP.txt"
xml = "user.xml"

Set filesys = CreateObject("Scripting.FileSystemObject")

if filesys.FileExists(Arxiu) then
Const ForReading = 1
Dim f, ip

Set f = filesys.OpenTextFile(Arxiu, ForReading)
Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run "cmd.exe", 9

Do Until f.AtEndOfStream

ip = f.ReadLine

Wscript.Sleep 1600

Set aux= filesys.CreateTextFile("num2.txt", True)

aux.WriteLine (vbcrlf + vbcrlf + ip)
aux.WriteLine (Date + Time)
aux.Close
Wscript.Sleep 1000
WshShell.SendKeys "cpqlocfg -s " + ip + " -l " + ip + ".log -f " + xml + " > Resultat" + ip + ".txt -v" + "{Enter}"
Wscript.Sleep 10000
WshShell.SendKeys "copy num2.txt {+} Resultat" + ip + ".txt num.txt" + "{Enter}"
Wscript.Sleep 1000
WshShell.SendKeys "type num.txt >> Log" + Arxiu + "{Enter}"
Wscript.Sleep 1600
WshShell.SendKeys "del num.txt num2.txt" + "{Enter}"
Wscript.Sleep 1000


if ip = NULL then
Exit Do
End if

Loop

else

WshShell.SendKeys "Incorrect File"
Wscript.Sleep 1000

End If

WshShell.SendKeys "exit" + "{Enter}"
Set WshShell = nothing


The program calls another program (CPQLOCFG), and it sends to it the parameters to execute. These parameters are included inside the file IP.txt (it?s full with ip address). the script is full of redirections for save all the events.

Thanks for your help, and sorry by my poor level of english.

evildad
  • Total Posts : 5
  • Scores: 0
  • Reward points : 0
  • Joined: 5/25/2004
  • Location: United Kingdom
Re: Wshshell.run "cmd.exe" doesn?t work in scheduler - Thursday, June 17, 2004 9:44 PM
0
Chencho,

A stab in the dark here, but have you tried "cmd.exe /c"

evildad.

Paul F

mbouchard
  • Total Posts : 2110
  • Scores: 27
  • Reward points : 0
  • Joined: 5/15/2003
  • Location: USA
Re: Wshshell.run "cmd.exe" doesn?t work in scheduler - Friday, June 18, 2004 7:29 AM
0
Chencho,

Is the computer locked / Logged off when you are running this via scheduler? If so, I do not think it will work as SendKeys will not work when the PC is locked.

I was wondering why you were using sendkeys to send commands via a CMD window?

Mike