caramen Posted February 5, 2015 Posted February 5, 2015 (edited) i dont know if i whrite it bad becose i already seen topic with batch files generated by autoit .... I mean i tryed to search in help and forum... but i cant found anything... i am sure it s realy easy ... I want to make a simple texte file ... with that code inside it.... :: BatchGotAdmin :------------------------------------- REM --> Check for permissions >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" REM --> If error flag set, we do not have admin. if '%errorlevel%' NEQ '0' ( echo Requesting administrative privileges... goto UACPrompt ) else ( goto gotAdmin ) :UACPrompt echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" set params = %*:"="" echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" exit /B :gotAdmin pushd "%CD%" CD /D "%~dp0" :-------------------------------------- C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKEY_LOCAL_MACHINE\System\ControlSet001\Control\Session Manager\Environnement /v Num_PC /t REG_DWORD /d 0 /f For explain you that code is giving a prompt to use admin right on C:\Windows\System32\cmd.exe /k %windir%System32reg.exe ADD (Very userfull script for disable UAC without probleme with autoit) Why i need to generate this ... ? I need to change the value at the end of the code ... "/d 0" 0 to 112, or 0 to 550 and set it up with an input box How to ask to autoit to make a text file with anykind of text in silent mode? Edited February 5, 2015 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki
orbs Posted February 5, 2015 Posted February 5, 2015 store the entire text, until the change point, as a string variable in your AutoIt script. add the dynamic substring to the end of that string (then optionally add any fixed substring afterwards). then just FileWriteLine() the entire string. Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates WinPose - simultaneous fluent move and resize Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Magic Math - a math puzzle Demos: Title Bar Menu - click the window title to pop-up a menu
caramen Posted February 5, 2015 Author Posted February 5, 2015 I ll try in the afternoon and i ll post what i did My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki
caramen Posted March 26, 2015 Author Posted March 26, 2015 If understand for simplified script that whould give me something like that ? sry i add no time to test before FileWriteLine ( "C:\test.cmd", "the command i want to write in the cdm batch"& $MyVariableAtTheEndOfTheFile ) My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki
caramen Posted March 26, 2015 Author Posted March 26, 2015 (edited) I am gonna do that with an other way... Let me show you my *reg file : Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment] "NUM_PC"="999" If i just want to change the "999" by any other number how can i do that ? Local $MyVariableAtTheEndOfTheFile = '560' FileOpen ("c:\test.reg") FileWriteLine ( "C:\Test.reg", "Windows Registry Editor Version 5.00" & "@CRLF" & "[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]" & "@CRLF" & '"NUM_PC"="' "$MyVariableAtTheEndOfTheFile" & "'" ) FileClose ("c:\test.reg") Edited March 26, 2015 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki
Solution caramen Posted March 26, 2015 Author Solution Posted March 26, 2015 ok i got it i post the code if that can help someone else: expandcollapse popup#include <FileConstants.au3> #include <MsgBoxConstants.au3> ; Script Start - Add your code below here Local $MyVariableAtTheEndOfTheFile = '560' Local Const $sFilePath = "C:\Users\GuemaJo\Desktop\test.cmd" Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.") Return False EndIf FileOpen ($sFilePath) ;~ FileWriteLine ( $sFilePath , "Windows Registry Editor Version 5.00" & @CRLF & "[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]" & @CRLF & '"NUM_PC"="' "$MyVariableAtTheEndOfTheFile" & "'" ) FileWriteLine($hFileOpen, ":: BatchGotAdmin") FileWriteLine($hFileOpen, ":-------------------------------------") FileWriteLine($hFileOpen, '>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"'&@CRLF ) FileWriteLine($hFileOpen,@CRLF) FileWriteLine($hFileOpen, "REM --> If error flag set, we do not have admin.") FileWriteLine($hFileOpen, "if '%errorlevel%' NEQ '0' (") FileWriteLine($hFileOpen, " echo Requesting administrative privileges...") FileWriteLine($hFileOpen, " goto UACPrompt") FileWriteLine($hFileOpen, ") else ( goto gotAdmin )") FileWriteLine($hFileOpen, @CRLF) FileWriteLine($hFileOpen, ":UACPrompt") FileWriteLine($hFileOpen, ' echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"') FileWriteLine($hFileOpen, ' set params = %*:"=""') FileWriteLine($hFileOpen, ' echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"') FileWriteLine($hFileOpen, @CRLF) FileWriteLine($hFileOpen, ' "%temp%\getadmin.vbs"') FileWriteLine($hFileOpen, ' del "%temp%\getadmin.vbs"') FileWriteLine($hFileOpen, ' exit /B') FileWriteLine($hFileOpen, @CRLF) FileWriteLine($hFileOpen, ':gotAdmin') FileWriteLine($hFileOpen, ' pushd "%CD%"') FileWriteLine($hFileOpen, ' CD /D "%~dp0"') FileWriteLine($hFileOpen, ':--------------------------------------') My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki
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