madasraka Posted January 27, 2011 Share Posted January 27, 2011 OK so i have a script for CMD expandcollapse popupmkdir "saved\reg" mkdir "saved\doc\Guitar Rig 4" mkdir "saved\Program Files\Native Instruments\Controller Editor" mkdir "saved\Program Files\Native Instruments\Service Center" mkdir "saved\Program Files\Common Files\Native Instruments\Controller Editor" mkdir "saved\Program Files\Common Files\Native Instruments\Guitar Rig 4" mkdir "saved\Program Files\Common Files\Native Instruments\Hardware" mkdir "saved\Program Files\Common Files\Native Instruments\Helper" mkdir "saved\Program Files\Common Files\Native Instruments\Service Center" regedit /E saved\reg\local.reg "HKEY_LOCAL_MACHINE\SOFTWARE\Native Instruments" regedit /S saved\reg\local.reg regedit /E saved\reg\current.reg "HKEY_CURRENT_USER\Software\Native Instruments" regedit /S saved\reg\current.reg if exist "%USERPROFILE%\AppData" GOTO :VISTA mkdir "%USERPROFILE%\My Documents\Native Instruments\Guitar Rig 4" xcopy /D/E "%USERPROFILE%\My Documents\Native Instruments\Guitar Rig 4" "saved\doc\Guitar Rig 4" /y xcopy /D/E "saved\doc\Guitar Rig 4" "%USERPROFILE%\My Documents\Native Instruments\Guitar Rig 4" /y GOTO :PR :VISTA mkdir "%USERPROFILE%\Documents\Native Instruments\Guitar Rig 4" xcopy /D/E "%USERPROFILE%\Documents\Native Instruments\Guitar Rig 4" "saved\doc\Guitar Rig 4" /y xcopy /D/E "saved\doc\Guitar Rig 4" "%USERPROFILE%\Documents\Native Instruments\Guitar Rig 4" /y :PR mkdir "%PROGRAMFILES%\Native Instruments\Controller Editor" mkdir "%PROGRAMFILES%\Native Instruments\Service Center" mkdir "%PROGRAMFILES%\Common Files\Native Instruments\Controller Editor" mkdir "%PROGRAMFILES%\Common Files\Native Instruments\Guitar Rig 4" mkdir "%PROGRAMFILES%\Common Files\Native Instruments\Hardware" mkdir "%PROGRAMFILES%\Common Files\Native Instruments\Helper" mkdir "%PROGRAMFILES%\Common Files\Native Instruments\Service Center" xcopy /D/E "%PROGRAMFILES%\Native Instruments\Controller Editor" "saved\Program Files\Native Instruments\Controller Editor" /y xcopy /D/E "%PROGRAMFILES%\Native Instruments\Service Center" "saved\Program Files\Native Instruments\Service Center" /y xcopy /D/E "%PROGRAMFILES%\Common Files\Native Instruments\Controller Editor" "saved\Program Files\Common Files\Native Instruments\Controller Editor" /y xcopy /D/E "%PROGRAMFILES%\Common Files\Native Instruments\Guitar Rig 4" "saved\Program Files\Common Files\Native Instruments\Guitar Rig 4" /y xcopy /D/E "%PROGRAMFILES%\Common Files\Native Instruments\Hardware" "saved\Program Files\Common Files\Native Instruments\Hardware" /y xcopy /D/E "%PROGRAMFILES%\Common Files\Native Instruments\Helper" "saved\Program Files\Common Files\Native Instruments\Helper" /y xcopy /D/E "%PROGRAMFILES%\Common Files\Native Instruments\Service Center" "saved\Program Files\Common Files\Native Instruments\Service Center" /y xcopy /D/E "saved\Program Files\Native Instruments\Controller Editor" "%PROGRAMFILES%\Native Instruments\Controller Editor" /y xcopy /D/E "saved\Program Files\Native Instruments\Service Center" "%PROGRAMFILES%\Native Instruments\Service Center" /y xcopy /D/E "saved\Program Files\Common Files\Native Instruments\Controller Editor" "%PROGRAMFILES%\Common Files\Native Instruments\Controller Editor"/y xcopy /D/E "saved\Program Files\Common Files\Native Instruments\Guitar Rig 4" "%PROGRAMFILES%\Common Files\Native Instruments\Guitar Rig 4" /y xcopy /D/E "saved\Program Files\Common Files\Native Instruments\Hardware" "%PROGRAMFILES%\Common Files\Native Instruments\Hardware" /y xcopy /D/E "saved\Program Files\Common Files\Native Instruments\Helper" "%PROGRAMFILES%\Common Files\Native Instruments\Helper" /y xcopy /D/E "saved\Program Files\Common Files\Native Instruments\Service Center" "%PROGRAMFILES%\Common Files\Native Instruments\Service Center" /y regsvr32 /S "%PROGRAMFILES%\Common Files\Native Instruments\Helper\NIHelperUAC.dll" instsrv.exe "NIHardwareService" "%PROGRAMFILES%\Common Files\Native Instruments\Hardware\NIHardwareService.exe" :Load SC Config "NIHardwareService" start= demand "Guitar Rig 4.exe" net stop "NIHardwareService" if exist "%USERPROFILE%\AppData" GOTO :VistaExit xcopy /D/E "%USERPROFILE%\My Documents\Native Instruments\Guitar Rig 4" "saved\doc\Guitar Rig 4" /y GOTO :exit :VistaExit xcopy /D/E "%USERPROFILE%\Documents\Native Instruments\Guitar Rig 4" "saved\doc\Guitar Rig 4" /y :exit xcopy /D/E "%USERPROFILE%\My Documents\Native Instruments\Guitar Rig 4" "saved\doc\Guitar Rig 4" /y xcopy /D/E "%PROGRAMFILES%\Native Instruments\Controller Editor" "saved\Program Files\Native Instruments\Controller Editor" /y xcopy /D/E "%PROGRAMFILES%\Native Instruments\Service Center" "saved\Program Files\Native Instruments\Service Center" /y xcopy /D/E "%PROGRAMFILES%\Common Files\Native Instruments\Controller Editor" "saved\Program Files\Common Files\Native Instruments\Controller Editor" /y xcopy /D/E "%PROGRAMFILES%\Common Files\Native Instruments\Guitar Rig 4" "saved\Program Files\Common Files\Native Instruments\Guitar Rig 4" /y xcopy /D/E "%PROGRAMFILES%\Common Files\Native Instruments\Hardware" "saved\Program Files\Common Files\Native Instruments\Hardware" /y xcopy /D/E "%PROGRAMFILES%\Common Files\Native Instruments\Helper" "saved\Program Files\Common Files\Native Instruments\Helper" /y xcopy /D/E "%PROGRAMFILES%\Common Files\Native Instruments\Service Center" "saved\Program Files\Common Files\Native Instruments\Service Center" /y regedit /E saved\reg\current.reg "HKEY_CURRENT_USER\Software\Native Instruments" regedit /E saved\reg\local.reg "HKEY_LOCAL_MACHINE\SOFTWARE\Native Instruments" exit When i do Opt ("Wintitlematchmode",2) $Commandline = guictrlread ($Edit) WinActivate ("cmd.exe") Send ($Commandline) what it does is it will type whole script into CMD window and execute each line at the time, or everytime ENTER was pressed for creating new line. Problem with this is that because script is executed as its being typed the:GOTO locations are not yet created, so they cant be accessed till whole script is typed in. So my question is: IS there a way to paste whole script into CMD via Autoit so that it will be executed same way as file.bat ? Link to comment Share on other sites More sharing options...
GEOSoft Posted January 27, 2011 Share Posted January 27, 2011 Look at the Run() function in the help file for examples of using Cmd (Hint: @ComSpec). With a string that long why not just write it to a batch file then use ShellExecuteWait(@ScriptDir & "\mybatch.bat")? Both of the functions I mentioned are under Process Management in the help file. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
JoHanatCent Posted January 28, 2011 Share Posted January 28, 2011 With a string that long why not just write it to a batch file Yes I agree. You can even use AutoIt to do the whole thing. Convert your .bat to a string and run all from within your script. expandcollapse popupdim $ABat createBat() $OutCome = RunWait($ABat,'', @SW_Hide) Func createBat() $ABat = 'mkdir "saved\reg"'& @crlf _ & 'mkdir "saved\doc\Guitar Rig 4"'& @crlf _ & 'mkdir "saved\Program Files\Native Instruments\Controller Editor"'& @crlf _ & 'mkdir "saved\Program Files\Native Instruments\Service Center"'& @crlf _ & 'mkdir "saved\Program Files\Common Files\Native Instruments\Controller Editor"'& @crlf _ & 'mkdir "saved\Program Files\Common Files\Native Instruments\Guitar Rig 4"'& @crlf _ & 'mkdir "saved\Program Files\Common Files\Native Instruments\Hardware"'& @crlf _ & 'mkdir "saved\Program Files\Common Files\Native Instruments\Helper"'& @crlf _ & 'mkdir "saved\Program Files\Common Files\Native Instruments\Service Center"'& @crlf _ & 'regedit /E saved\reg\local.reg "HKEY_LOCAL_MACHINE\SOFTWARE\Native Instruments"'& @crlf _ & 'regedit /S saved\reg\local.reg'& @crlf _ & 'regedit /E saved\reg\current.reg "HKEY_CURRENT_USER\Software\Native Instruments"'& @crlf _ & 'regedit /S saved\reg\current.reg'& @crlf _ & ''& @crlf _ & ''& @crlf _ & 'if exist "%USERPROFILE%\AppData" GOTO :VISTA'& @crlf _ & 'mkdir "%USERPROFILE%\My Documents\Native Instruments\Guitar Rig 4"'& @crlf _ & 'xcopy /D/E "%USERPROFILE%\My Documents\Native Instruments\Guitar Rig 4" "saved\doc\Guitar Rig 4" /y'& @crlf _ & 'xcopy /D/E "saved\doc\Guitar Rig 4" "%USERPROFILE%\My Documents\Native Instruments\Guitar Rig 4" /y'& @crlf _ & 'GOTO :PR'& @crlf _ & ''& @crlf _ & ':VISTA'& @crlf _ & 'mkdir "%USERPROFILE%\Documents\Native Instruments\Guitar Rig 4"'& @crlf _ & 'xcopy /D/E "%USERPROFILE%\Documents\Native Instruments\Guitar Rig 4" "saved\doc\Guitar Rig 4" /y'& @crlf _ & 'xcopy /D/E "saved\doc\Guitar Rig 4" "%USERPROFILE%\Documents\Native Instruments\Guitar Rig 4" /y'& @crlf _ & ''& @crlf _ & ':PR'& @crlf _ & 'mkdir "%PROGRAMFILES%\Native Instruments\Controller Editor"'& @crlf _ & 'mkdir "%PROGRAMFILES%\Native Instruments\Service Center"'& @crlf _ & 'mkdir "%PROGRAMFILES%\Common Files\Native Instruments\Controller Editor"'& @crlf _ & 'mkdir "%PROGRAMFILES%\Common Files\Native Instruments\Guitar Rig 4" '& @crlf _ & 'mkdir "%PROGRAMFILES%\Common Files\Native Instruments\Hardware"'& @crlf _ & 'mkdir "%PROGRAMFILES%\Common Files\Native Instruments\Helper"'& @crlf _ & 'mkdir "%PROGRAMFILES%\Common Files\Native Instruments\Service Center"'& @crlf _ & 'xcopy /D/E "%PROGRAMFILES%\Native Instruments\Controller Editor" "saved\Program Files\Native Instruments\Controller Editor" /y'& @crlf _ & 'xcopy /D/E "%PROGRAMFILES%\Native Instruments\Service Center" "saved\Program Files\Native Instruments\Service Center" /y'& @crlf _ & 'xcopy /D/E "%PROGRAMFILES%\Common Files\Native Instruments\Controller Editor" "saved\Program Files\Common Files\Native Instruments\Controller Editor" /y'& @crlf _ & 'xcopy /D/E "%PROGRAMFILES%\Common Files\Native Instruments\Guitar Rig 4" "saved\Program Files\Common Files\Native Instruments\Guitar Rig 4" /y'& @crlf _ & 'xcopy /D/E "%PROGRAMFILES%\Common Files\Native Instruments\Hardware" "saved\Program Files\Common Files\Native Instruments\Hardware" /y'& @crlf _ & 'xcopy /D/E "%PROGRAMFILES%\Common Files\Native Instruments\Helper" "saved\Program Files\Common Files\Native Instruments\Helper" /y'& @crlf _ & 'xcopy /D/E "%PROGRAMFILES%\Common Files\Native Instruments\Service Center" "saved\Program Files\Common Files\Native Instruments\Service Center" /y'& @crlf _ & ''& @crlf _ & 'xcopy /D/E "saved\Program Files\Native Instruments\Controller Editor" "%PROGRAMFILES%\Native Instruments\Controller Editor" /y'& @crlf _ & 'xcopy /D/E "saved\Program Files\Native Instruments\Service Center" "%PROGRAMFILES%\Native Instruments\Service Center" /y'& @crlf _ & 'xcopy /D/E "saved\Program Files\Common Files\Native Instruments\Controller Editor" "%PROGRAMFILES%\Common Files\Native Instruments\Controller Editor"/y'& @crlf _ & 'xcopy /D/E "saved\Program Files\Common Files\Native Instruments\Guitar Rig 4" "%PROGRAMFILES%\Common Files\Native Instruments\Guitar Rig 4" /y'& @crlf _ & 'xcopy /D/E "saved\Program Files\Common Files\Native Instruments\Hardware" "%PROGRAMFILES%\Common Files\Native Instruments\Hardware" /y'& @crlf _ & 'xcopy /D/E "saved\Program Files\Common Files\Native Instruments\Helper" "%PROGRAMFILES%\Common Files\Native Instruments\Helper" /y'& @crlf _ & 'xcopy /D/E "saved\Program Files\Common Files\Native Instruments\Service Center" "%PROGRAMFILES%\Common Files\Native Instruments\Service Center" /y'& @crlf _ & ''& @crlf _ & 'regsvr32 /S "%PROGRAMFILES%\Common Files\Native Instruments\Helper\NIHelperUAC.dll"'& @crlf _ & 'instsrv.exe "NIHardwareService" "%PROGRAMFILES%\Common Files\Native Instruments\Hardware\NIHardwareService.exe"'& @crlf _ & ''& @crlf _ & ':Load'& @crlf _ & 'SC Config "NIHardwareService" start= demand'& @crlf _ & ''& @crlf _ & '"Guitar Rig 4.exe"'& @crlf _ & 'net stop "NIHardwareService"'& @crlf _ & ''& @crlf _ & 'if exist "%USERPROFILE%\AppData" GOTO :VistaExit'& @crlf _ & 'xcopy /D/E "%USERPROFILE%\My Documents\Native Instruments\Guitar Rig 4" "saved\doc\Guitar Rig 4" /y'& @crlf _ & 'GOTO :exit'& @crlf _ & ''& @crlf _ & ':VistaExit'& @crlf _ & 'xcopy /D/E "%USERPROFILE%\Documents\Native Instruments\Guitar Rig 4" "saved\doc\Guitar Rig 4" /y'& @crlf _ & ''& @crlf _ & ':exit'& @crlf _ & ''& @crlf _ & 'xcopy /D/E "%USERPROFILE%\My Documents\Native Instruments\Guitar Rig 4" "saved\doc\Guitar Rig 4" /y'& @crlf _ & 'xcopy /D/E "%PROGRAMFILES%\Native Instruments\Controller Editor" "saved\Program Files\Native Instruments\Controller Editor" /y'& @crlf _ & 'xcopy /D/E "%PROGRAMFILES%\Native Instruments\Service Center" "saved\Program Files\Native Instruments\Service Center" /y'& @crlf _ & 'xcopy /D/E "%PROGRAMFILES%\Common Files\Native Instruments\Controller Editor" "saved\Program Files\Common Files\Native Instruments\Controller Editor" /y'& @crlf _ & 'xcopy /D/E "%PROGRAMFILES%\Common Files\Native Instruments\Guitar Rig 4" "saved\Program Files\Common Files\Native Instruments\Guitar Rig 4" /y'& @crlf _ & 'xcopy /D/E "%PROGRAMFILES%\Common Files\Native Instruments\Hardware" "saved\Program Files\Common Files\Native Instruments\Hardware" /y'& @crlf _ & 'xcopy /D/E "%PROGRAMFILES%\Common Files\Native Instruments\Helper" "saved\Program Files\Common Files\Native Instruments\Helper" /y'& @crlf _ & 'xcopy /D/E "%PROGRAMFILES%\Common Files\Native Instruments\Service Center" "saved\Program Files\Common Files\Native Instruments\Service Center" /y'& @crlf _ & ''& @crlf _ & ''& @crlf _ & 'regedit /E saved\reg\current.reg "HKEY_CURRENT_USER\Software\Native Instruments"'& @crlf _ & 'regedit /E saved\reg\local.reg "HKEY_LOCAL_MACHINE\SOFTWARE\Native Instruments"'& @crlf _ & 'exit'& @crlf _ & '' if FileExists('Abat.bat') then FileDelete('Abat.bat') FileWrite('Abat.bat', $Abat) sleep(500) EndFunc Link to comment Share on other sites More sharing options...
madasraka Posted January 28, 2011 Author Share Posted January 28, 2011 Well i cant do JoHanatCent's example because this CMD script is something user has to type in instead of me having static function created. I ended up creating commnad.bat and run it. Question now is, does autoit passes users permissions to executed .bat file ? or how does it work ? Also do i need to worry about working directory when executing my .bat file ? caz if i dont, results are strange sometimes. For example folders would be created in system32 folder instead of where .bat was generated (@scriptdir) Link to comment Share on other sites More sharing options...
GEOSoft Posted January 28, 2011 Share Posted January 28, 2011 set the working folder to @System Dir and make sure that you also use @SystemDir when you are creating the folders. Specifying System32 can lead to issues with 64 bit systems. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" 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