DaLiMan Posted September 27, 2004 Share Posted September 27, 2004 Hi there, I have this script which works fine, but I think it can be improved. Has anybody a good suggestion. AutoItSetOption("SendKeyDelay", 100) $Today = @MDAY & "-" & @MON & "-0" & (@YEAR-2000) Run ("Cmd.exe","", @SW_HIDE) WinWait("C:\WINNT\System32\Cmd.exe", "") ControlSend("C:\WINNT\System32\Cmd.exe","","","date") ControlSend("C:\WINNT\System32\Cmd.exe","","","{ENTER}") ControlSend("C:\WINNT\System32\Cmd.exe","","","31-08-04") ControlSend("C:\WINNT\System32\Cmd.exe","","","{ENTER}") Run ("C:\SomeProgram.exe") Sleep(5000) ControlSend("C:\WINNT\System32\Cmd.exe","","","date") ControlSend("C:\WINNT\System32\Cmd.exe","","","{ENTER}") ControlSend("C:\WINNT\System32\Cmd.exe","","",$Today) ControlSend("C:\WINNT\System32\Cmd.exe","","","{ENTER}") ControlSend("C:\WINNT\System32\Cmd.exe","","","exit") ControlSend("C:\WINNT\System32\Cmd.exe","","","{ENTER}") Link to comment Share on other sites More sharing options...
this-is-me Posted September 27, 2004 Share Posted September 27, 2004 add $ttl = "C:\WINNT\System32\Cmd.exe" to the top of the script and replace "C:\WINNT\System32\Cmd.exe" with $ttl. Who else would I be? Link to comment Share on other sites More sharing options...
ZeDMIN Posted September 27, 2004 Share Posted September 27, 2004 i tried only a part of it, but it seems to work too: AutoItSetOption("SendKeyDelay", 100) $Today = @MDAY & "-" & @MON & "-0" & (@YEAR-2000) $cmd = "C:\WINNT\System32\Cmd.exe" Run ($cmd,"", @SW_HIDE) WinWait($cmd, "") ControlSend($cmd,"","","date{ENTER}31-08-04{ENTER}") Run ("C:\SomeProgram.exe") Sleep(5000) ControlSend($cmd,"","","date{ENTER}" & $Today & "{ENTER}exit{ENTER}") A bit shorter Greetings, ZeD Link to comment Share on other sites More sharing options...
sugi Posted September 27, 2004 Share Posted September 27, 2004 Since you asked for it I'd like to point a logical error out. But the error wont show up within the next 5 years so I guess you can just ignore it for now. $Today = @MDAY & "-" & @MON & "-0" & (@YEAR-2000) This line has one of the typical Y2k errors, it does not use the last two digits of the year but simply substracts 2000 from it. Theoretically, what would happen in the year 2153? $Today would be set to "27-09-0153" which is just wrong. The error will already show in the year 2010. $Today would be set to "27-09-010" which just looks a bit strange. As I said: It's a typical Y2k error which should be avoided. But since I'm pretty sure this script wont be needed in 2010 you can ignore the problem in this script. Just remember it when you're writing other scripts. Link to comment Share on other sites More sharing options...
DaLiMan Posted September 27, 2004 Author Share Posted September 27, 2004 As I said: It's a typical Y2k error which should be avoided. But since I'm pretty sure this script wont be needed in 2010 you can ignore the problem in this script. Just remember it when you're writing other scripts. <{POST_SNAPBACK}>I see what you mean, but how do you avoid this? Can you give me an example to create a 2 digit year in Auto-It? Link to comment Share on other sites More sharing options...
sugi Posted September 27, 2004 Share Posted September 27, 2004 I see what you mean, but how do you avoid this? Can you give me an example to create a 2 digit year in Auto-It? <{POST_SNAPBACK}>StringRight(@Year, 2) Link to comment Share on other sites More sharing options...
DaLiMan Posted September 27, 2004 Author Share Posted September 27, 2004 StringRight(@Year, 2) <{POST_SNAPBACK}>Sorry, should have thought of that....so simple... :"> Link to comment Share on other sites More sharing options...
ZeDMIN Posted September 27, 2004 Share Posted September 27, 2004 umm, why do you cut the year at all? i know it SAYS "dd-mm-yy" but i think you can use 4-digit years as well. can anyone try this? i dont have the priviledge to change the date Greetings, ZeD Link to comment Share on other sites More sharing options...
Valik Posted September 27, 2004 Share Posted September 27, 2004 (edited) Is there a particular reason you don't just do:$Today = @MDAY & "-" & @MON & "-" & @YEAR RunWait(@ComSpec & " /c date " & $Today, "", @SW_HIDE)Edit: There isn't any need to use 2 digit year, so code changed.Edit 2: Fixed typo which caused a syntax error. Edited September 27, 2004 by Valik Link to comment Share on other sites More sharing options...
JSThePatriot Posted September 27, 2004 Share Posted September 27, 2004 In Windows XP Pro, it can be done with a four digit year. I would assume the same is with WINNT. What windows version do you have DaLi? Also it accepts "/" or "-". Let me know if anyone else has something different. It seems to accept any standard date format. I hope this helps someone. JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
DaLiMan Posted September 27, 2004 Author Share Posted September 27, 2004 Is there a particular reason you don't just do: $Today = @MDAY & "-" & @MON & "-" & @YEAR RunWait(@ComSpec & " /c date " & $Today), "", @SW_HIDE) Edit: There isn't any need to use 2 digit year, so code changed. <{POST_SNAPBACK}>I copied and tried it out, but I get an "UNKNOWN MACRO" error from auto-it.3 Something wrong here??? Link to comment Share on other sites More sharing options...
ZeDMIN Posted September 27, 2004 Share Posted September 27, 2004 I copied and tried it out, but I get an "UNKNOWN MACRO" error from auto-it.3 Something wrong here??? <{POST_SNAPBACK}>theres one ) too much, try this: $Today = @MDAY & "-" & @MON & "-" & @YEAR RunWait(@ComSpec & " /c date " & $Today, "", @SW_HIDE) Greetings, ZeD Link to comment Share on other sites More sharing options...
DaLiMan Posted September 27, 2004 Author Share Posted September 27, 2004 @JSThePatriot I have WinXP pro. I changed my script in a four digit year. like ZeDMIN & Valik also suggested. Just as simple and works fine also. Thanx anyhow... Link to comment Share on other sites More sharing options...
JSThePatriot Posted September 27, 2004 Share Posted September 27, 2004 Excellent glad you got it all figured out! Enjoy, JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
DaLiMan Posted September 28, 2004 Author Share Posted September 28, 2004 @ZeD OK, works fine now. @Everybody Script is now very short and simple.... $Date = "31-08-2004" $Today = @MDAY & "-" & @MON & "-" & @Year RunWait(@ComSpec & " /c date " & $Date, "", @SW_HIDE) Run ("someprogram.exe") WinWait("someprogram", "") RunWait(@ComSpec & " /c date " & $Today, "", @SW_HIDE) hmmm, might consider GUI for this for use with different programs..... Thanx y'all. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now