Jump to content

Script Start Time


mjg
 Share

Recommended Posts

Ok, I'm having some issues w/ the logic on this script and I'm unsure if it is even possible.

Here is what I would like to accomplish:

When a user logs in the script starts in the background

The script remain idle until 3:00am EST (some computers will be set to central and mountain time)

Once 3:00am hits the script continues to run.

The biggest problem I'm having is the 3am EST and how to get it to idle and not kill the system resources.

Originally I was going to use scheduled tasks to accomplish this, but this script needs to run inside of a citrix farm. And it only needs to run if the user is logged in, if they logout the script should close out.

Thanks for the help,

-mjg

Link to comment
Share on other sites

Ok, I'm having some issues w/ the logic on this script and I'm unsure if it is even possible.

Here is what I would like to accomplish:

When a user logs in the script starts in the background

The script remain idle until 3:00am EST (some computers will be set to central and mountain time)

Once 3:00am hits the script continues to run.

The biggest problem I'm having is the 3am EST and how to get it to idle and not kill the system resources.

Originally I was going to use scheduled tasks to accomplish this, but this script needs to run inside of a citrix farm. And it only needs to run if the user is logged in, if they logout the script should close out.

Thanks for the help,

-mjg

i belive valuator made one search for script addons.. in excample scripts

Link to comment
Share on other sites

#include <Date.au3>

While 1
    If _NowTime() > "3:00:00 AM" Then
        StartYourScript()
    Else
        Sleep(60*1000)
    EndIf
WEnd

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

#include <Date.au3>

While 1
    If _NowTime() > "3:00:00 AM" Then
        StartYourScript()
    Else
        Sleep(60*1000)
    EndIf
WEnd

......

The script remain idle until 3:00am EST (some computers will be set to central and mountain time)

Once 3:00am hits the script continues to run. .....

@mikehunt114 - doesn't _NowTime pulls the computers regional time? So if a computer has the regional settings of GMT-6:00 (Central Time) and that computer kicks off your code it would actually run the script at 2am eastern not the required 3am eastern. Not to mention the your code doesn't account for daylight savings changes which might not be an issue if each computer running the script has the regional settings set correctly; to adjust automatically.

I'm thinking a small tweak of your code would be what's needed. Perhaps something that would pull the computer's regional time setting and then do a calculation to arrive at the correct 3am eastern time. Or am I completely wrong in my thinking?

--ss3

...

Link to comment
Share on other sites

@mikehunt114 - doesn't _NowTime pulls the computers regional time? So if a computer has the regional settings of GMT-6:00 (Central Time) and that computer kicks off your code it would actually run the script at 2am eastern not the required 3am eastern. Not to mention the your code doesn't account for daylight savings changes which might not be an issue if each computer running the script has the regional settings set correctly; to adjust automatically.

I'm thinking a small tweak of your code would be what's needed. Perhaps something that would pull the computer's regional time setting and then do a calculation to arrive at the correct 3am eastern time. Or am I completely wrong in my thinking?

--ss3

...

Yeah, I just tested it and it does just pull your regional time. I'm trying to figure out if you can specify EST.

Danwilli, how would you suggest pulling the time from a time sync server? We push our time from our servers, but we don't mandate EST and we have offices all over the country.

Link to comment
Share on other sites

@mikehunt114 - doesn't _NowTime pulls the computers regional time? So if a computer has the regional settings of GMT-6:00 (Central Time) and that computer kicks off your code it would actually run the script at 2am eastern not the required 3am eastern. Not to mention the your code doesn't account for daylight savings changes which might not be an issue if each computer running the script has the regional settings set correctly; to adjust automatically.

I'm thinking a small tweak of your code would be what's needed. Perhaps something that would pull the computer's regional time setting and then do a calculation to arrive at the correct 3am eastern time. Or am I completely wrong in my thinking?

--ss3

...

True, it uses your local computer's regional settings. If you know the time zone on the computer on which the script is running, you can manually account for it by subtracting or adding the correct amount of time. If you do not know the time zone, things will be a little trickier as this is not native to AutoIt's current functions. This would be a good place to start. As for the daylight savings time, perhaps ask yourself if that one hour is vitally important? If yes, then I imagine whether DST is in use or not can be determined in more or less the same manner as the time zone. Good luck.

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

Yeah, I just tested it and it does just pull your regional time. I'm trying to figure out if you can specify EST.

Danwilli, how would you suggest pulling the time from a time sync server? We push our time from our servers, but we don't mandate EST and we have offices all over the country.

Though I could be wrong I think you would need to use the Network Time Protocol (NTP, see http://www.ntp.org/) in order to query a time sync server. Unfortunately I'm not a developer or programmer so I don't know how or where to begin with this. And the MSDN article Mike was gracious enough to provide targets the developer/programmer audience.

You could also play around with reading the registry for the regional settings under HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation. Or maybe someone here knows how to pass command line output to an autoit variable? If that's possible you could use the command "w32tm /tz" to capture the information. If you can't directly pipe output to a variable for the script to process, you could always pipe the information to a txt file then have autoit parse the info you need. Just throwing out some ideas for you.

One thing I'm not clear on is why Windows' Scheduled Tasks won't work for you. You mentioned that the script will be running

inside of a citrix farm. And it only needs to run if the user is logged in, if they logout the script should close out.

Does this imply that your citrix farm is scattered across multiple timezones in the US? I'm use to thinking of citrix farms being housed in consolidated or centralized data centers. Perhaps the trigger could be based on the UserID (eg: 3amMaintenance ) instead of a specific time?

If you do find a way to get this working the way you want, hopefully you'll share the code that determines regional settings and kicks the script off based on a specific UTC time.

--ss3

...

Link to comment
Share on other sites

Not to confuse the issue, but I suggest looking into Scheduled tasks again. I would be real uncomfortable running a script for hours and hours just to wait for a magic hour, when Scheduled Tasks is already doing this.

A good test for whether a user is logged on is to look for the shell (explorer.exe) in the process list. For example:

#NoTrayIcon
if ProcessExists("explorer.exe") Then
    FileWriteLine("c:\temp\test.txt", "User logged on")
Else
    FileWriteLine("c:\temp\test.txt", "User not logged on")
EndIf

I'm not real familiar with Citrix, though, so maybe there are other issues that I am not aware of.

Hope this helps,

BlueBearrOddly enough, this is what I do for fun.
Link to comment
Share on other sites

Hey, riffing off of ssubirias' suggestion, I came up with the following script:

Dim $tmzData, $STDOUT_CHILD = 2
$timestuff = run(@SystemDir & "\w32tm.exe /tz", @SystemDir, @SW_MINIMIZE, $STDOUT_CHILD)
While 1
    $tmzData = $tmzData & StdoutRead($timestuff)
    If @error Then ExitLoop
Wend

$aTmz = StringSplit($tmzData, "Bias:", 1)
Dim $iBias = 0
For $i = 1 to $aTmz[0]
    $aTmz[$i] = StringStripWS ( StringLeft($aTmz[$i], StringInStr($aTmz[$i], "min") - 1), 3)
    $iBias += $aTmz[$i]
Next
MsgBox(0, "Time Zone Data", "Your time zone is UTC + " & $iBias & " mins.")

This would be one way to determine the relationship between the current time zone and EST (which is UTC + 300 minutes, I think).

BlueBearrOddly enough, this is what I do for fun.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...