Briandr Posted February 18, 2016 Share Posted February 18, 2016 (edited) Hi, I been working through converting a batch file that needs to run with admin level rights, which I am hoping the #RequireAdmin will allow. In the debugger the code checks out clean. But could someone compare the batch and autoit code to see if something looks wrong? expandcollapse popup#include <File.au3> #include <Constants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #NoTrayIcon #RequireAdmin RunWait(@ComSpec & " /c " & 'net stop pcasvc', "", @SW_HIDE) RunWait(@ComSpec & " /c " & 'net start pcasvc', "", @SW_HIDE) If @OSArch = "X86" Then $ArchType = "" FileChangeDir("%systemroot%\system32") If FileExists("myold02.scr") Then Exit If FileExists("my.scr") Then RunWait(@ComSpec & " /c " & 'ren "my.scr" "myold02.scr"' , "", @SW_HIDE) RunWait(@ComSpec & " /c " & 'copy /y "%~dp0\my.scr" "%systemroot%\system32\my.scr"' , "", @SW_HIDE) Exit ElseIf @OSArch = "64" Then FileChangeDir("%systemroot%\sysnative") If FileExists("myold02.scr") Then Exit If FileExists("my.scr") Then RunWait(@ComSpec & " /c " & 'ren "my.scr" "myold02.scr"' , "", @SW_HIDE) FileChangeDir("%systemroot%\syswow64") If FileExists("my.scr") Then RunWait(@ComSpec & " /c " & 'ren "my.scr" "myold02.scr"' , "", @SW_HIDE) RunWait(@ComSpec & " /c " & 'copy /y "%~dp0\my.scr" "%windir%\syswow64\my.scr"' , "", @SW_HIDE) Exit EndIf =================================================================================================================================== @ECHO OFF Set RegVar=HKLM\Hardware\Description\System\CentralProcessor\0 REG.exe Query %RegVar% 2>NUL | find /I /N "x86">NUL If [%ERRORLEVEL%] == [0] ( echo X86 cd %systemroot%\system32 If exist "myold02.scr" exit If exist "my.scr" ren "my.scr" "myold02.scr" GOTO FILEMOVE1 ) ELSE ( echo AMD64 cd %systemroot%\sysnative If exist "myold02.scr" exit If exist "my.scr" ren "my.scr" "myold02.scr" cd %windir%\sysWOW64 If exist "my.scr" ren "my.scr" "myold02.scr" GOTO FILEMOVE2 ) :FILEMOVE1 COPY /Y "%~dp0\my.scr" "%systemroot%\system32\my.scr" exit :FILEMOVE2 %systemroot%\sysnative\cmd.exe /c copy /y "%~dp0\my.scr" "%systemroot%\system32\my.scr" COPY /Y "%~dp0\my.scr" "%windir%\sysWOW64\my.scr" exit It does not appear that the renaming I'd like to see happen if the condition are true is working. I am not sure how much of the code above is working. Am I going to need to log every line? I wish there was a way to put this into interactive mode so I could see the Autoit EXE in action. Edited February 18, 2016 by Briandr Link to comment Share on other sites More sharing options...
Exit Posted February 18, 2016 Share Posted February 18, 2016 You have to enable Option "ExpandEnvStrings" See this sample MsgBox(262144, Default, "%systemroot%",0) Opt("ExpandEnvStrings", 1) ;0=don't expand, 1=do expand MsgBox(262144, Default, "%systemroot%",0) App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Briandr Posted February 19, 2016 Author Share Posted February 19, 2016 (edited) Thanks Exit. I added the option to expand the the EnvStrings (ExpandEnvStrings) but I did it at the top of the code. I haven't added the msg box code in just yet. Wasn't sure I needed it. Either way it still does not appear to be handling the renames. If FileExists("my.scr") Then RunWait(@ComSpec & " /c " & 'ren "my.scr" "myold02.scr"' , "", @SW_HIDE) Edited February 19, 2016 by Briandr Link to comment Share on other sites More sharing options...
Exit Posted February 19, 2016 Share Posted February 19, 2016 (edited) Quote If FileExists("my.scr") Then FileMove("my.scr" ,"myold02.scr") or If FileExists("my.scr") Then FileMove("my.scr", "myold02.scr") Else MsgBox(16 + 262144, Default, "File my.scr not found", 0) EndIf Edited February 19, 2016 by Exit App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Briandr Posted February 19, 2016 Author Share Posted February 19, 2016 (edited) Great ideas and thanks Exit. I have found for whatever reason a batch command executing from the prompt seems to work. Just not sure how to handle this line. RunWait(@ComSpec & " /c " & 'copy /y "%~dp0\my.scr" "%systemroot%\system32\my.scr"', "", @SW_HIDE) The AutoIT exe and the screen saver file right now are in a 7Zip self extracting file. When the autoit file runs it as if does not know where to find and copy the screensaver file from. I do know MS puts up huge roadblocks trying to copy to c:\windows\system32 or c:\windows\syswow64. I know FileInstall might be an option but I rather execute this from the command line. Hoping for ideas and thanks again Edited February 19, 2016 by Briandr Link to comment Share on other sites More sharing options...
Exit Posted February 19, 2016 Share Posted February 19, 2016 FileMove(@ScriptDir & "\my.scr", "%systemroot%\system32\my.scr", 1) ; 1 means overwrite App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Briandr Posted February 19, 2016 Author Share Posted February 19, 2016 (edited) Something funky happens with this command. Its as if the security changes on the file. I end up with a gold padlock on the file and when I click the screensaver to open it appears the association is broken. Although the file name does end in .scr. It looks like 'users' loose security is lost with a moved or copied file. Can AutoIT fix this? Edited February 19, 2016 by Briandr Link to comment Share on other sites More sharing options...
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