Jump to content
Sign in to follow this  
Reinman

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

Recommended Posts

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.

You are right, it doesn't normally require admin rights. However, I'm in a locked down environment where local policy prevents most users from accessing the date/time function.

I've tried the ShellExecute approach and can't get it to pass the necessary, temporary, elevated credentials to allow it to work. I'm using RunAsSet but I don't think it passes through to ShellExecute.

The problem is two-fold, first I must pass the credentials and second I must pass parameters with the command.

If I can get some help on the syntax for RunWait, I think I can make it work. Here is the basic command that I need help on now:

RunWait ('"control.exe timedate.cpl,,/Z" & "$szTzKey"', "@SystemDir", @SW_HIDE)

I think its a syntax issue but not sure. It gives me: C:\Temp\DST\DSTFix.au3 (599) : ==> Unable to execute the external program.:

RunWait ('"control.exe timedate.cpl,,/Z" & "$szTzKey"', "@SystemDir", @SW_HIDE)

The system cannot find the file specified.

Edited by Reinman

Share this post


Link to post
Share on other sites

Well this was used in another post

Run("control.exe """ & @SystemDir & "\desk.cpl""")

How can I include the additional parameters to the above command?

I need to include: /Z & $szTzKey

Share this post


Link to post
Share on other sites

Run("control.exe """ & @SystemDir & "\timedate.cpl,,/Z & "$szTzKey"""")

Generates:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Temp\DST\DSTFix.au3"

C:\Temp\DST\DSTFix.au3 (600) : ==> Error in expression.:

Run("control.exe """ & @SystemDir & "\timedate.cpl,,/Z & "$szTzKey"""")

Run(^ ERROR

>Exit code: 0 Time: 0.565

Share this post


Link to post
Share on other sites

Wrong syntax you can see it when you paste it in Scite

Run("control.exe """ & @SystemDir & "\timedate.cpl,,/Z " & $szTzKey & """")

The best is to always do a MsgBox(0,0,"control.exe """ & @SystemDir & "\timedate.cpl,,/Z " & $szTzKey & """")

The you can check what the run - is running :whistle:

Edited by Shevilie

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

There are way too many quotes, and in wrong places. This is what you want.

Run("control.exe " & @SystemDir & "\timedate.cpl,,/Z" & $szTzKey)
Shevilie - Thanks for your input, I'll try the MsgBox.

ReverendJ1 - Thanks for jumping in, I admire your work and appreciate the help.

Using the syntax that you supplied now generates:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Temp\DST\DSTFix.au3"

C:\Temp\DST\DSTFix.au3 (600) : ==> Unable to execute the external program.:

Run("control.exe " & @SystemDir & "\timedate.cpl,,/Z" & $szTzKey)

The directory name is invalid.

Both control.exe and timedate.cpl can be found in the C:\WinNT\System32 directory. Any suggestions on what I'm missing?

Share this post


Link to post
Share on other sites

Thanks for the praise. :-) I'm just trying to help out. Try this.

Run("control.exe " & @SystemDir & "\timedate.cpl,,/Z")oÝ÷ Ù8^«-½ªâi¹^Ó~¬Í

I *believe* that opens up the Time Zone applet to the correct time zone, but you just need to open the applet and close it. It will automatically default to your time zone when it opens. At any rate, the first code I posted on this reply works fine.

Edited by ReverendJ1

Share this post


Link to post
Share on other sites

Did you try this

Run("control.exe """ & @SystemDir & "\timedate.cpl,,/Z " & $szTzKey & """")

That command returns:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Temp\DST\DSTFix.au3"

C:\Temp\DST\DSTFix.au3 (599) : ==> Unable to execute the external program.:

Run("control.exe """ & @SystemDir & "\timedate.cpl,,/Z " & $szTzKey & """")

The directory name is invalid.

I'll post all the code just in case you guys can spot something.

CODE

;--------------------------------

; Variables

;--------------------------------

Dim $arrTZSubKeys[100]

Global $Label

Global $szTzKey

$count = 0

$objSh = ObjCreate("WScript.Shell")

;--------------------------------

; Refresh Time Zone

;--------------------------------

;Get the StandardName key of the current time zone

$szStandardName = RegRead('HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\','StandardName')

;Enumerate the subkeys in the time zone database

$szTZsKeyPath = 'HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\'

;Step 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

Run("control.exe """ & @SystemDir & "\timedate.cpl,,/Z " & $szTzKey & """")

;Get current display name of refreshed time zone

$szCurrDispName = RegRead($szTZsKeypath & $szTzKey & '\','Display')

;--------------------------------

; Functions

;--------------------------------

Func SearchReg($searchpath, $standardname)

For $i= 1 to 10000

$currentkey = RegEnumKey($searchpath, $i)

If @error <> 0 then ExitLoop

$arrTZSubKeys[$count]=$currentkey

If $currentkey == $standardname Then

$szTzKey = $currentkey

EndIf

$count = $count + 1

Next

EndFunc

Share this post


Link to post
Share on other sites

Thanks for the praise. :-) I'm just trying to help out. Try this.

Run("control.exe " & @SystemDir & "\timedate.cpl,,/Z")oÝ÷ Ù8^«-½ªâi¹^Ó~¬Í

I posted the entire code in a previous post that might lead to the resolution.

Thanks again for your time and patience with a rookie such as myself.

Edited by Reinman

Share this post


Link to post
Share on other sites

What do you get when you just run

msgbox(0, "", @SystemDir)

If you go to start run and enter control.exe, does the control panel dialog box open?

Share this post


Link to post
Share on other sites

What do you get when you just run

msgbox(0, "", @SystemDir)

If you go to start run and enter control.exe, does the control panel dialog box open?

Yes it does....

And the code that you provided, opens a message box containing C:\winnt\system32 which is the folder containing control.exe AND timedate.cpl.

Edited by Reinman

Share this post


Link to post
Share on other sites

I see. You are using Windows 2000 right? I should have noticed when you said your windows folder was c:\winnt. I am not sure if this will work on Windows 2000 either, I don't have a Win 2K machine handy (I'm actually building a virtual machine now, so I will soon though.), but it seems like it would. I am assuming control.exe is a WinXP only command, but who knows.....

Run("rundll32.exe shell32.dll,Control_RunDLL timedate.cpl,,/Z")oÝ÷ ØÖ¨¹Ú'¢ÙÞyÛajÙZ²ÛÚ®&í7êÌÓ̧²jËÖÞ~Þ"¯z׬µçbµ§íz·!jx"ax4wèÂ+a*k¢
Ú¶Ø^
$í¡ÈZ¥jËf¢{a¶§v'(f§th²×«-jëh×6Run("control.exe " & @SystemDir & "\timedate.cpl,,/Z")
and it changed the time fine. Edited by ReverendJ1

Share this post


Link to post
Share on other sites

Yes, I'm on Windows 2000 and yes control.exe is supported.

FWIW, the following command works but I can't pass the elevated privileges with it:

$objSh.Run ("control.exe timedate.cpl,,/Z" & $szTzKey)

Many thanks!

Share this post


Link to post
Share on other sites

I just tried it on the Win2K Virtual Machine I made and it works fine, although I don't see anywhere in your code where you actually update the DST info, or did you just not get to that part yet? PS You shouldn't need to use WScript/VBScript or whatever anywhere for this.

Share this post


Link to post
Share on other sites

I have another mechanism updating the registry changes prior to launching this code.

I am using RunAsSet as you suggested, (I just cut it out of my example code). However, running this:

RunAsSet ( "user", "domain", "password" )
Run("control.exe " & @SystemDir & "\timedate.cpl,,/Z")

Still produces the directory name is invalid message:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Temp\DST\DSTFix.au3"

C:\Temp\DST\DSTFix.au3 (602) : ==> Unable to execute the external program.:

Run("control.exe " & @SystemDir & "\timedate.cpl,,/Z")

The directory name is invalid.

Should I be defining a local directory to run from?

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  

×
×
  • Create New...