Sign in to follow this  
Followers 0
DaLiMan

In need of Positive Criticism

15 posts in this topic

Hi there,

I have this script which works fine, but I think it can be improved.

Has anybody a good suggestion. :ph34r:

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}")

Share this post


Link to post
Share on other sites



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?

Share this post


Link to post
Share on other sites

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 :ph34r:

Greetings,

ZeD

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

StringRight(@Year, 2)

<{POST_SNAPBACK}>

Sorry, should have thought of that....so simple... :">

Share this post


Link to post
Share on other sites

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 :ph34r:

Greetings,

ZeD

Share this post


Link to post
Share on other sites

#9 ·  Posted (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 by Valik

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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???

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

@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...

Share this post


Link to post
Share on other sites

Excellent glad you got it all figured out! :ph34r:

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)

Share this post


Link to post
Share on other sites

@ZeD

OK, works fine now. :ph34r:

@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. :lol:

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0