WinBatch Script

Started by JanHolland, April 17, 2014, 01:46:22 AM

Previous topic - Next topic

JanHolland

Hello,

I'm "brand new" on this forum and a brand new user of WinBatch. We purchased WinBatch and the Compiler early this month.
We tried a WinBatch-script on a WindowsXP environment and it works perfectly. The same script doesn't work on a Windows7 pc.

Does anyone see where the mistake is made?
This script has to do:
1. A Restart of the PC at 04:00AM (there's an autologin configured and it starts this EXE at the start of the PC)

2. Start a program at 04:50AM

The script is like this:

:begin
a=timeymdhms()
nu=strsub(a,10,5)

a=("04:00")
c=("10:24")

Restart=strsub(a,1,5)
Nachtprocedure=strsub(c,1,5)

if Restart == nu
   IntControl (67,0,0,0,0)
endif

if Nachtprocedure == nu

   runwait("h:\apotheek_tabellen\nachtprocedure\progs\update-1.exe", " ")

endif

goto begin

Is there anyone who can help? What I want to achieve is the performance of a WinBatch exe at a certain time. Is my script adequate for a Win7...why doesn't it perform?

Thanks,

Jan Stegeman
The Netherlands

JTaylor

I think the problem (at least one problem) is that

    nu=strsub(a,10,5)

should be

   nu=strsub(a,12,5)


Jim

JTaylor

Also, a couple of general suggestions that aren't specific to this script.

Perhaps consider using a While loop instead of GoTo.  GoTo's have their place but generally good to not get in the habit of using them as they can create problems in certain situations.  Not an issue in this script but just a general thing to avoid when possible.

Using a TimeDelay() is also something to consider in this situation.  Currently your script is going to run through that loop constantly.   This, of course, means that everything else will have to vie with it for resources.  Since you have a 60 second window a TimeDelay(30) would lessen the load on your system.

Jim

snowsnowsnow

The core problem in this thread is that the script is so rife with semantic and style errors that it is hard to accept the fundamental premise of the thread: that it works fine under XP.  I.e., that the crux of the problem is the move to Windows 7.

It'd be good to find out in what sense it "works" under XP.

Deana

I suspect the RunWait could be having a problem on Windows 7 (UAC on). Is the H: drive a mapped drive? If so you will need to use the correct Manifest for your script or use a UNC path instead ( i.e \\{Server}\{share}\apotheek_tabellen\nachtprocedure\progs\update-1.exe ).

Reference: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/UAC+Mapped~Drives~Issue~with~UAC.txt

If this does not resolve the issue, please explain in detail how the autologin is configured that starts this EXE at the start of the PC on Windows 7?

Lastly, here is some revised code with comments and some error checking:
Code (winbatch) Select

updatefilename = '\\{server}\{share}\apotheek_tabellen\nachtprocedure\progs\update-1.exe' ; MODIFY TO FIT YOUR NEEDS!!!!!!!
restart_time = "04:00" ; Time to restart
nacht_time = "10:24" ; Time to launch update-1.exe

; Check if updatefilename exists
If !FileExist( updatefilename )
   Pause('Notice','Unable to locate ':updatefilename)
   Exit
Endif

While @True  ;Infinite loop
now = TimeYMDHMS() ; Get current YMDHMS
time = StrSub( now, 12, 5 ) ; Parse out hour and minute

; Reboot (Note: This function is not supported when run as a service. )
If time == restart_time then IntControl( 67, 0, 0, 0, 0 )

; Launch update
If time == nacht_time then ShellExecute( updatefilename, '', '', @NORMAL, '')

TimeDelay(60) ; Delay to ensure the tasks don't get executed twice
EndWhile
Exit
Deana F.
Technical Support
Wilson WindowWare Inc.

JTaylor

Oh...and welcome to WinBatch...it is awesome....just like the WinBatch Support folks  :)

Jim

td

Quote from: Deana on April 17, 2014, 08:09:34 AM
I suspect the RunWait could be having a problem on Windows 7 (UAC on). Is the H: drive a mapped drive? If so you will need to use the correct Manifest for your script or use a UNC path instead ( i.e \\{Server}\{share}\apotheek_tabellen\nachtprocedure\progs\update-1.exe ).

The network drive issue certainly looks like the prime candidate. Another less likely possible explanation might be that the exe 'update-1.exe' is manifested to run with a full admin access token and the script is running with a restricted admin or standard user token.  Of course this would depend on whether or not UAC is enabled.   
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

JanHolland

Thank you all for your remarks. I'm sorry but I just started with this and have no experience with programming whatsoever. So the remark: "the script is so rife with semantic and style errors that it is hard to accept the fundamental premise of the thread" is usefull but I'm aware of the sometime "crappy semantics" . Doing my best here, and trying to pickup your knowledge.

A remark to SnowSnowSnow: "What this program DOES is Restarting Windows (I have an autologin), so user loggs in, and Windows waits till it's (in this case) 10:24am to start the program" That 'works', the XP-computer does what I expect.

I'll try to built in all other suggestions. Thanx again.....

JanHolland
the Netherlands




JanHolland

Deana,

Thank so much for your help in rewriting my crappy script. Your solution works fine and gave me a good push to write more scripts like yours.
Thanx for that....and also the other reply-ers.

Do I need to put status of this topic to "resolved" ?

JanHolland.
The Netherlands.

Deana

Quote from: JanHolland on May 14, 2014, 05:12:08 AM
Deana,

Thank so much for your help in rewriting my crappy script. Your solution works fine and gave me a good push to write more scripts like yours.
Thanx for that....and also the other reply-ers.

Do I need to put status of this topic to "resolved" ?

JanHolland.
The Netherlands.

No need to put a status of resolved. However I am happy to hear the code I posted helped.
Deana F.
Technical Support
Wilson WindowWare Inc.

MW4

One minor suggestion from me:

I have been in the habit lately (through growing pains) of changing hard coded Drive letters like c:\... to \\server\Share.

Been thinking about creating a master file of drive mappings that other scripts could query, so that if you have to change a path, you don't have a ton to change, just one line in one master file.

The waiting until it breaks method is a pain, LOL