Sign in to follow this  
Followers 0
caramen

Gerating bat file ?

6 posts in this topic

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

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

I ll try in the afternoon and i ll post what i did

Share this post


Link to post
Share on other sites

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 )

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

ok i got it i post the code if that can help someone else:

#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, ':--------------------------------------')

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
Sign in to follow this  
Followers 0