Sign in to follow this  
Followers 0
Reinman

Noob needs help scripting a compiled runas DST fix (.reg & .vbs)

52 posts in this topic

Due to the 2007 daylight saving time adjustments, I'm attempting to deliver some registry changes then run a vbs script to a number of Windows 2000 systems. I'd like it to be in a single encrypted exe which includes admin credentials. That way I can distribute via email or add to the login script.

I need guidance to:

1 - Determine the best way to code it (call the reg file or build the file locally run it then remove it).

2 - Create the code itself. (syntax eats my lunch)

Any assistance is appreciated.

Share this post


Link to post
Share on other sites



ehh? most windows systems auto-update for daylight savings...no need to manually do it usually....

Share this post


Link to post
Share on other sites

sounds troublesome...

looks like you can just have the users run the reg file they provide though no?

if you wanan deploy from an autoit script id say do what you said and do a fileinstall, run(regedit.exe /s thefile),filedelete

maybe do some runasset if you got permission issues

Share this post


Link to post
Share on other sites

I've been working on the same thing. i have some code written up for this already. For certain businesses, just letting the user run it isn't going to work. We have several different OS's here, from NT to Server 2003. There needs to be a way to make things happy right! I am currently working on something as we speak! :-D, I will let you know when I get a little further on it, so I can show something!

Share this post


Link to post
Share on other sites

K, this is what I have so far. You will have to make a few changes to accommodate your network setup. But the jist of it is there. What do ya think!? Yes, I am also a n00b, but I'm trying to learn!

Change attached files to .reg, put them in your location of choice. Modify Variable paths.

If you need to run this as a Service Account Just create a wrapper.

That is what I call, all it does is doing a "run as" on the file below.

I know it isn't pretty. But it is just a start!

#cs
    Daylight Savings Time Fix 2007
    
    Author: Kevin Sanders
    
    Description:
    The purpose of this script is to apply a "House Wide" fix for the Daylight Savings Time change. The script will begin by checking the OS version.
    .reg import based on the version of OS it found. We will be accounting for the following versions of OS. XP, 2000, NT.
    It will then modify DST registry settings to account for new DST. It writes to a text file that is in a location of your choosing andd logs it's computer name along with any logs
    during the scripting process.
    
    License:  This script can be freely copied and distributed, as long as it is not
    sold for ANY fee (including "distribution" costs.)  Any modification to
    this script must be submitted to the original author if the modified script
    is distributed in any manner.  Any modification must include this header
    information with this licence, disclaimer and original author information in tact.
    
    Disclaimer: The author is not responsible for any damage or harm caused by this
    script.  USE AT YOUR OWN RISK.  There is no warranty, express or implied.
#CE
    
#include <process.au3>
    
;-----------
; Variables
;-----------
Dim $arrTZSubKeys[75]
Global $Label
Global $szTzKey
$count = 0
$RootPath = ''change to your location" ;Example (C:\DST\)
$LogPath = $RootPath & 'logs\'
$LogFile = $LogPath & @ComputerName & '.txt'
$FilePath = $RootPath & 'files\'


;==========================================;
;--------Importing Registry File-----------;
;==========================================;
;Need to change the File "test.reg" and "testNT.reg" to the real file when it is "GO" time!
;These .reg files needed can be found attached to this post
Select 
    Case @OSVersion == 'WIN_XP' or 'WIN_2000'
    _RunDOS('regedit /s ' & $FilePath & 'test.reg')
    
    Case @OSVersion == 'WIN_NT4'
    _RunDOS('regedit /s ' & $FilePath & 'testNT.reg)
EndSelect
Exit
;==================================;
;------End Registry Import---------;
;==================================;
    

;-----------------------------------------------------------------------;
; Translating Jason .vbs file into AutoIT
;   File is to be run last, refreshes the Time/Date and Zone Information
;-----------------------------------------------------------------------;

;Get the StandardName key of the current time zone
$szStandardName = RegRead('HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\','StandardName')
WriteLog('Getting "Standard Name" from "HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\StandardName')
WriteLog('"Standard Name" is: '  & $szStandardName)
ConsoleWrite('$szStandardName = ' & $szStandardName)

;Enumerate the subkeys in the time zone database
$szTZsKeyPath = 'HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\'
ConsoleWrite('$szTZsKeypath = ' & $szTZsKeyPath)

;Right here he is stepping through each subkey inside of $szTZsKeyPath to find $szStandardName
SearchReg($szTZsKeyPath, $szStandardName)

;Error checking
    If $szTzKey == '' Then
        MsgBox(0,'','Error: 2007 Registry Update and Refresh failed to execute on this computer.  Time zones failed to enumerate properly or matching time zone not found.')
        Exit
    EndIf

;Launch control.exe to refresh time zone information using the TZ key name
_RunDOS('control.exe timedate.cpl,,/Z' & $szTzKey)
WriteLog('Executing: control.exe timedate.cpl,,/Z' & $szTzKey)

;Get current display name of refreshed time zone
$szCurrDispName = RegRead($szTZsKeypath & $szTzKey & '\','Display')
ConsoleWrite($szCurrDispName)

;Log update completed successfully

;===================;
;-----Functions-----;
;===================;

Func SearchReg($searchpath, $standardname)
    For $i= 1 to 10000
        $currentkey = RegEnumKey($searchpath, $i)
            If @error <> 0 then ExitLoop
        ConsoleWrite($currentkey & @CRLF)
        $arrTZSubKeys[$count]=$currentkey
            If $currentkey == $standardname Then
                $szTzKey = $currentkey          
            EndIf
        ConsoleWrite('$arrTZSubKeys[' & $count & ']:' & $arrTZSubKeys[$count])
        $count = $count + 1
    Next
EndFunc

Func _FileWriteLog($sLogPath, $sLogMsg)
    ;==============================================
    ; Local Constant/Variable Declaration Section
    ;==============================================
    Local $sDateNow
    Local $sTimeNow
    Local $sMsg
    Local $hOpenFile
    Local $hWriteFile

    $sDateNow = @YEAR & "-" & @MON & "-" & @MDAY
    $sTimeNow = @HOUR & ":" & @MIN & ":" & @SEC
    $sMsg = $sDateNow & " " & $sTimeNow & " : " & $sLogMsg

    $hOpenFile = FileOpen($sLogPath, 1)

    If $hOpenFile = -1 Then
        SetError(1)
        Return 0
    EndIf

    $hWriteFile = FileWriteLine($hOpenFile, $sMsg)

    If $hWriteFile = -1 Then
        SetError(2)
        Return 0
    EndIf

    FileClose($hOpenFile)
    Return 1
EndFunc

Func WriteLog($message)
    _FileWriteLog($LogFile, $message)
    GUICtrlSetData($Label,$message)
EndFunc

TZupdate.txt

TZupdate_NT.txt

Share this post


Link to post
Share on other sites

Hi all, I just thought I would let you know I have already done this. I wrote a program that can update every computer on your network (regardless of Windows version) at once, remotely, with a report at the end. You just have to be an admin on all those machines, and have remote registry enabled. Check it out and let me know what you think. You can also download the AutoIT source. http://johnny5source.googlepages.com/daysaver

Share this post


Link to post
Share on other sites

cannot get to the page. Can u attach the source here on the forum.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Weird, not sure why it didn't work for you. Here are the download links. (hosted on Sourceforge)

Day Saver Source

Day Saver No Install

Day Saver Setup

Sorry there are no comments in the source. I have a bad habit of putting comments in after I write code. I just haven't had the chance to put them in. But I think I write my code fairly easy to read.

-ReverendJ1

Edited by ReverendJ1

Share this post


Link to post
Share on other sites

I just took a look at it last night right before I went home from work. I have a question. Are you "refreshing" the Time/Date and Zone information after making these changes?

Share this post


Link to post
Share on other sites

Thank you all for your input so far.

Since all my clients are not accessing the same server or even on the same network, I'm taking a different approach. I'm attempting to bundle a single EXE that makes the registry changes AND performs a Time Zone refresh. Once complete, I can distribute it to any system on my network with any number of delivery mechanisms.

Has anyone already completed work on something like this?

Share this post


Link to post
Share on other sites

It sounds like you are looking for something with no GUI or anything. An .exe that you can send to all clients, via group policy or just, go here "\\asdfa\" something like that. The code I provided will work for that. You will just have to tweak it slightly for your setup.

Share this post


Link to post
Share on other sites

@Dufran3 - Crap. I thought it didn't need to be refreshed if the computer was restarted. Apparently not the case. I guess I will have to add PSExec to remotely open the control panel.

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

yeh, restart doesn't refresh it. No biggy though.

First I will show u the exact .vbs script that microsoft gives to refresh it. I translated it into AutoIt. Maybe you can add something like this to it.

==============

----Microsoft VBS----

==============

Set objSh = CreateObject("WScript.Shell")

'Get the StandardName key of the current time zone
szStandardName = objSh.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\StandardName")

'Enumerate the subkeys in the time zone database
const HKEY_LOCAL_MACHINE = &H80000002
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
szTzsKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones"
objReg.EnumKey HKEY_LOCAL_MACHINE, szTzsKeyPath, arrTzSubKeys

'Step through the time zones to find the matching Standard Name
szTzKey = "<Unknown>"
For Each subkey In arrTzSubKeys
    If (objSh.RegRead("HKLM\" & szTzsKeyPath & "\" & subkey & "\Std") = szStandardName) Then
        'Found matching StandardName, now store this time zone key name
        szTzKey = subkey
    End If
Next 

If szTzKey = "<Unknown>" Then
       'Write entry to the Application event log stating that the update has failed to execute
       objSh.LogEvent 1, "DST 2007 Registry Update and Refresh failed to execute on this computer.  Time zones failed to enumerate properly or matching time zone not found."
       Wscript.Quit 0
End If

'Launch control.exe to refresh time zone information using the TZ key name obtained above 
objSh.Run "control.exe timedate.cpl,,/Z" & szTzKey

'Get current display name of refreshed time zone
szCurrDispName = objSh.RegRead("HKLM\" & szTzsKeyPath & "\" & szTzKey & "\Display")

'Write entry to the Application event log stating that the update has executed
objSh.LogEvent 4, "DST 2007 Registry Update and Refresh has been executed on this computer." & chr(13) & chr(10) & chr(13) & chr(10) & "Current time zone is: " & szCurrDispName & "."

================

---End of Microsoft VBS--

================

================

---Auto IT Translation---

================

;Get the StandardName key of the current time zone
$szStandardName = RegRead('HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\','StandardName')
WriteLog('Getting "Standard Name" from "HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\StandardName')
WriteLog('"Standard Name" is: '  & $szStandardName)
ConsoleWrite('$szStandardName = ' & $szStandardName)

;Enumerate the subkeys in the time zone database
$szTZsKeyPath = 'HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\'
ConsoleWrite('$szTZsKeypath = ' & $szTZsKeyPath)

;Right here he is stepping through each subkey inside of $szTZsKeyPath to find $szStandardName
SearchReg($szTZsKeyPath, $szStandardName)

;Error checking
    If $szTzKey == '' Then
        MsgBox(0,'','Error: 2007 Registry Update and Refresh failed to execute on this computer.  Time zones failed to enumerate properly or matching time zone not found.')
        Exit
    EndIf

;Launch control.exe to refresh time zone information using the TZ key name
_RunDOS('control.exe timedate.cpl,,/Z' & $szTzKey)
WriteLog('Executing: control.exe timedate.cpl,,/Z' & $szTzKey)

;Get current display name of refreshed time zone
$szCurrDispName = RegRead($szTZsKeypath & $szTzKey & '\','Display')
ConsoleWrite($szCurrDispName)

=================

---End of Translation------

=================

Edited by dufran3

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

My code is almost complete but I'm running into a problem.

When I execute this line:

_RunDOS('control.exe timedate.cpl,,/Z' & $szTzKey)

I receive this error:

C:\Program Files\AutoIt3\Include\Process.au3 (104) : ==> Unable to execute the external program.:

Return RunWait(@ComSpec & " /C " & $sCommand, "", @SW_HIDE)

The directory name is invalid

.

I have included the line "#include <Process.au3>"

What can I try to resolve this?

Edited by Reinman

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

I looked at it, and can't figure out why it is doing that. Below is the line from the .vbs that Microsoft Supplied.

'Launch control.exe to refresh time zone information using the TZ key name obtained above 
objSh.Run "control.exe timedate.cpl,,/Z" & szTzKey

Maybe it doesn't like the _RunDOS. Have u tried using @ComSpec?

Maybe some of the veterans can help out here. As I always say, I'm a n00b, and continually learn.

Edited by dufran3

Share this post


Link to post
Share on other sites

I looked at it, and can't figure out why it is doing that. Below is the line from the .vbs that Microsoft Supplied.

'Launch control.exe to refresh time zone information using the TZ key name obtained above 
objSh.Run "control.exe timedate.cpl,,/Z" & szTzKey

Maybe it doesn't like the _RunDOS. Have u tried using @ComSpec?

Maybe some of the veterans can help out here. As I always say, I'm a n00b, and continually learn.

Yes, I've tried all 3 (the MS code, the @ComSpec and my example).

I need to pass credentials with elevated privileges in order to run this refresh and I can't get any of the 3 figured out. Do you know which of the 3 support RunAsSet or similar?

I appreciate your help!

Share this post


Link to post
Share on other sites

?? ShellExecute()


Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

I found a snippet of code from another project I did about a month back. I was able to use RunAsSet. Here is the piece of code, maybe this will help you.

RunAsSet('username','domain','password',1)
RunWait(@ComSpec & " /c rmdir /s /q c:\temp\folder")
oÝ÷ Ø¥²¬yØ­~Úr©ê¢Ø^®ØbGÅç.)àj{§{-jYl¶¸§ú+jv©¦Xjب«­¢+Ø(ÀÌØíU¹¥¹Íѱ±MÑÉ¥¹ôÌäí5Í¥á¹á½aìÙÑÀáÀ´ÉÈÜ´Ñŵ  
Ô´ÄÍÜØÔÄäÜÍÉôÌäì)IÕ¹ÍMÐ ÀÌØíIÕ¹ÍUÍÈ°ÀÌØíIչͽ´°ÀÌØíIÕ¹ÍAḬ́Ĥ)IÕ¹]¥Ð ÀÌØíU¹¥¹Íѱ±MÑÉ¥¹µÀìÌäìµÌäì¤

I think that you can just use a Run, or RunWait when assigning the RunAsSet. See if that will work for you. However, are you positive that this requires admin rights? I didn't think it did.

Edited by dufran3

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