Davidowicza Posted February 25, 2019 Posted February 25, 2019 Hey all, My office will soon be upgrading our machines from Windows 7 to Windows 10. So as I am going through all of my scripts that I have made, to make sure they work on the new OS, I have come across a simple one that for the life of me can't figure out how to fix. It is a simple script that grabs the time off of one of our servers and changes the computer time to it on startup. Our users do not have access to changing time for obvious reasons. Works great on Windows 7, but not working for Windows 10. Script: #include <AutoItConstants.au3> #include <Constants.au3> #include <Date.au3> #include <File.au3> $DirCmd = Run(@ComSpec & " /c net time \\whopper", "C:\", @SW_HIDE, $STDOUT_CHILD+$STDERR_CHILD) Local $ResponseText While 1 $ResponseText &= StdoutRead($DirCmd) If @error Then ExitLoop Wend $check = StringMid($ResponseText, 31, 1) $check2 = StringMid($ResponseText, 33, 1) $check3 = StringMid($ResponseText, 32, 1) $check4 = StringMid($ResponseText, 34, 1) If $check = "/" and $check2 = "/" Then $time = StringLeft($ResponseText, 50) $time = StringRight($time, 12) ElseIf $check = "/" and $check2 <> "/" Then $time = StringLeft($ResponseText, 51) $time = StringRight($time, 12) ElseIf $check3 = "/" and $check4 = "/" Then $time = StringLeft($ResponseText, 51) $time = StringRight($time, 12) ElseIf $check3 = "/" and $check4 <> "/" Then $time = StringLeft($ResponseText, 52) $time = StringRight($time, 12) EndIf RunAs("Administrator", @computerName, "****", 1, @ComSpec & " /c time "&$time) (Don't mind the string grabs... not good with Regex ) Basically when I run this code in Windows 10 the command line for some reason does not get elevated properly. It keeps saying that "A required privilege is not held by the client". Does anyone know why this is? I have been searching google and forums without much success to my issue. The only way that I have managed to get this to work is to add #requireadmin to the script and just do a Run() but since I just want to stick it into the startup folder for all of my users, it's not really what I want. Hopefully I am just overthinking this and missing something obvious. Thanks for any help!
BrewManNH Posted February 25, 2019 Posted February 25, 2019 If these computers are joined to a domain, why do you need to set the time and date? The DC should handle all of that. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Davidowicza Posted February 25, 2019 Author Posted February 25, 2019 Long story short, I work for our local government, half of our computers are owned by the state. There are some dumb processes on the state's computers that we cannot change, like where those computer sync their time on boot. The server that it syncs time with happens to be 7 minutes faster than the actual time, which makes about 110 of our machines 7 minutes faster than the others. I would run that script after log-in so it sets those computers that are state owned to the correct time of our office. I know it seems dumb, because it is. But we need to have all machines at the same time since if a worker forgets their swipe in badge, they can email our payroll clerk which will have their timestamp on the email. That 7 minute discrepancy caused many issues... and is causing me even more haha
TheXman Posted February 25, 2019 Posted February 25, 2019 There are ways to self-elevate the script to execute with the appropriate privileges. However, discussion of that topic has been deemed off limits. To find out more about ways to self-elevate, you can try to search this forum for previous discussions and/or search the 'net for other related discussions. With that being said, there's a much better solution available. Instead of running the script from the startup folder, why not you just set up the script to be executed as a scheduled task, at logon, with the appropriate security options? CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
genius257 Posted February 25, 2019 Posted February 25, 2019 (edited) Hi @Davidowicza. Have you looked at _Date_Time_SetSystemTime? Also: How to Allow a Standard Windows 10 User to Change the Time and Date I hope some of this helps Edit: or maybe run it via the Task Scheduler, you can set privilege and set it to run on user login. Edited February 25, 2019 by genius257 To show your appreciation My highlighted topics: AutoIt Package Manager, AutoItObject Pure AutoIt, AutoIt extension for Visual Studio Code Github: AutoIt HTTP Server, AutoIt HTML Parser
Davidowicza Posted February 25, 2019 Author Posted February 25, 2019 @TheXman Yeah I was trying that off limits topic but ran into an issue and I know I am on my own with that issue if I try to continue that direction. Task Scheduler could be my safety blanket for this, it just ran so nicely on Win 7 was hoping for an easy conversion to 10 but I guess that's Microsoft for ya. Thanks. @genius257 Thanks for that information but _Date_Time_* functions would still need me to elevate the script and for the second link we do not want the users to be able to change the date/time of their machines.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now