Briandr

can someone check conversion from batch to autoit

7 posts in this topic

#1 ·  Posted (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?

#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 by Briandr

Share this post


Link to post
Share on other sites



#3 ·  Posted (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 by Briandr

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by Briandr

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by Briandr

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