Sign in to follow this  
Followers 0
anwarbham

automated cmd file creator not working

7 posts in this topic

hi i have been trying to create a gui were when u put in the machine ip or machine name in an GuiCtrlCreateInput it then creates and runs a batch file that tells u what server the machine is connected to what apps are on te machine etc and saves the result in a text file then it deletes the batch file..

now my problem is when i press the ok key it does not run the batch file the batch file is created but when i edit the batch file my machine ip has not been inserted in the file can any one help.

code below thanks

#include <GuiConstants.au3>

; Create commands in cmd file

$file = FileOpen(@ScriptDir & "\_LSS.cmd", 2)

;create gui

$box = GuiCreate("asset tool", 400, 400)

GuiSetIcon(@SystemDir & "\mspaint.exe", 0)

; asset inputbox

GuiCtrlCreateLabel("asset Please",40, 20, 40,40)

$input1 = GuiCtrlCreateInput( "",40, 60, 90, 20) ; asset read command

;creates the batch file

FileWriteLine($file, '@echo off')

FileWriteLine($file, 'set check_ws=%'&$input1&'%')

FileWriteLine($file, '')

FileWriteLine($file, 'TYPE \\%'&$input1&'\c$\"PROGRAM FILES"\CA\USD\SD\ASM\CONF\ASM.CNF|FIND "ASMSSLSR =SDCP3CME0">>0%\..\LSS.TMP')

FileWriteLine($file, '')

FileWriteLine($file, 'ping -n 1 %'&$input1&' | find /i "reply">>0%\..\IP.TMP')

FileWriteLine($file, 'ECHO ---------------------------------------------------------->>%0\..rESULT.TXT')

FileWriteLine($file, 'ECHO.>>%0\..rESULT.TXT')

FileWriteLine($file, 'ECHO.>>%0\..rESULT.TXT')

FileWriteLine($file, 'ECHO 1] THE IP ADDRESS FOR \\%'&$input1&' IS>>%0\..\rESULT.TXT')

FileWriteLine($file, 'TYPE IP.TMP>>%0\..\rESULT.TXT')

FileWriteLine($file, 'ECHO 2] THE LMS FOR \\%'&$input1&' IS >>%0\..\rESULT.TXT')

FileWriteLine($file, 'TYPE LSS.TMP>>%0\..\rESULT.TXT')

FileWriteLine($file, 'del %0\..\lss.tmp')

FileWriteLine($file, ' ')

FileWriteLine($file, ' ')

FileWriteLine($file, 'ECHO.>>%0\..rESULT.TXT')

FileWriteLine($file, 'TYPE \\%'&$input1&'c$"PROGRAM FILES"\CA\USD\SD\ASM\CONF\ASM.CNF|FIND "ASMUILSR =">>%0\..\LSS.TMP')

FileWriteLine($file, ' ')

FileWriteLine($file, ' ')

FileWriteLine($file, 'ECHO.>>%0\..rESULT.TXT')

FileWriteLine($file, 'ECHO 3] THE LOCAL LSS FOR \\%'&$input1&' IS >>%0\..\rESULT.TXT')

FileWriteLine($file, 'TYPE %0\..\LSS.TMP>>%0\..\rESULT.TXT')

FileWriteLine($file, 'ECHO.>>%0\..\rESULT.TXT')

FileWriteLine($file, ' ')

FileWriteLine($file, ' ')

FileWriteLine($file, 'del %0\..\lss.tmp')

FileWriteLine($file, 'ECHO **** sOFTWARE INSTALLED ON WORKSTATION ***>>%0\..\rESULT.TXT')

FileWriteLine($file, 'TREE \\%'&$input1&'\c$\"Program Files"\CA\UAM\CLIENTWS\Software /f>>%0\..\LSS.TMP')

FileWriteLine($file, ' ')

FileWriteLine($file, 'TYPE %0\..\LSS.TMP>>%0\..\rESULT.TXT')

FileWriteLine($file, 'echo -----** END WORKSTATION *** -----')

FileWriteLine($file, ' ')

FileWriteLine($file, 'echo %2 ##############')

FileWriteLine($file, 'DEL 0%\..\IP.TMP')

FileWriteLine($file, 'DEL 0%\..\LSS.TMP')

FileWriteLine($file, '@ECHO')

FileWriteLine($file, 'del %0\..\result.txt')

FileWriteLine($file, 'del %0\..\LSS.TMP')

FileWriteLine($file, 'del %0\..\IP.TXT')

FileWriteLine($file, 'ECHO -------------------------------------------')

FileWriteLine($file, 'FOR /f %%a in (%0\..\WS.TXT) do call %0\..\_lss.cmd %%a')

FileWriteLine($file, 'ECHO.')

FileWriteLine($file, 'ECHO.')

FileClose($file);closes the file

$Sendmailbutton = GuiCtrlCreateButton("Send mail", 40, 330, 100, 30)

GUICtrlSetOnEvent(-1, "OKPressed")

Func OKPressed()

RunWait("\_LSS.cmd")

;run the cmd file

; Delete our file once its done

FileDelete("_LSS.cmd")

EndFunc

GuiSetState()

While GuiGetMsg() <> $GUI_EVENT_CLOSE

WEnd

Share this post


Link to post
Share on other sites



no i renamed the cmd in the code still no luck i think its to to with the ok command its not selecting the input text and adding it to the cmd file

and the function is not running the file

Share this post


Link to post
Share on other sites

#include <GuiConstants.au3>
opt("GUIOnEventMode", 1)
; Create commands in cmd file
$file = FileOpen(@ScriptDir & "\_LSS.cmd", 2)

;create gui
$box = GUICreate("asset tool", 400, 400)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetIcon(@SystemDir & "\mspaint.exe", 0)

; asset inputbox
GUICtrlCreateLabel("asset Please", 40, 20, 40, 40)
$input1 = GUICtrlCreateInput("", 40, 60, 90, 20); asset read command

;creates the batch file
FileWriteLine($file, '@echo off')
FileWriteLine($file, 'set check_ws=%' & $input1 & '%')
FileWriteLine($file, '')
FileWriteLine($file, 'TYPE \\%' & $input1 & '\c$\"PROGRAM FILES"\CA\USD\SD\ASM\CONF\ASM.CNF|FIND "ASMSSLSR =SDCP3CME0">>0%\..\LSS.TMP')
FileWriteLine($file, '')
FileWriteLine($file, 'ping -n 1 %' & $input1 & ' | find /i "reply">>0%\..\IP.TMP')
FileWriteLine($file, 'ECHO ---------------------------------------------------------->>%0\..rESULT.TXT')
FileWriteLine($file, 'ECHO.>>%0\..rESULT.TXT')
FileWriteLine($file, 'ECHO.>>%0\..rESULT.TXT')
FileWriteLine($file, 'ECHO 1] THE IP ADDRESS FOR \\%' & $input1 & ' IS>>%0\..\rESULT.TXT')
FileWriteLine($file, 'TYPE IP.TMP>>%0\..\rESULT.TXT')
FileWriteLine($file, 'ECHO 2] THE LMS FOR \\%' & $input1 & ' IS >>%0\..\rESULT.TXT')
FileWriteLine($file, 'TYPE LSS.TMP>>%0\..\rESULT.TXT')
FileWriteLine($file, 'del %0\..\lss.tmp')
FileWriteLine($file, ' ')
FileWriteLine($file, ' ')
FileWriteLine($file, 'ECHO.>>%0\..rESULT.TXT')
FileWriteLine($file, 'TYPE \\%' & $input1 & 'c$"PROGRAM FILES"\CA\USD\SD\ASM\CONF\ASM.CNF|FIND "ASMUILSR =">>%0\..\LSS.TMP')
FileWriteLine($file, ' ')
FileWriteLine($file, ' ')
FileWriteLine($file, 'ECHO.>>%0\..rESULT.TXT')
FileWriteLine($file, 'ECHO 3] THE LOCAL LSS FOR \\%' & $input1 & ' IS >>%0\..\rESULT.TXT')
FileWriteLine($file, 'TYPE %0\..\LSS.TMP>>%0\..\rESULT.TXT')
FileWriteLine($file, 'ECHO.>>%0\..\rESULT.TXT')
FileWriteLine($file, ' ')
FileWriteLine($file, ' ')
FileWriteLine($file, 'del %0\..\lss.tmp')
FileWriteLine($file, 'ECHO **** sOFTWARE INSTALLED ON WORKSTATION ***>>%0\..\rESULT.TXT')
FileWriteLine($file, 'TREE \\%' & $input1 & '\c$\"Program Files"\CA\UAM\CLIENTWS\Software /f>>%0\..\LSS.TMP')
FileWriteLine($file, ' ')
FileWriteLine($file, 'TYPE %0\..\LSS.TMP>>%0\..\rESULT.TXT')
FileWriteLine($file, 'echo -----** END WORKSTATION *** -----')
FileWriteLine($file, ' ')
FileWriteLine($file, 'echo %2 ##############')
FileWriteLine($file, 'DEL 0%\..\IP.TMP')
FileWriteLine($file, 'DEL 0%\..\LSS.TMP')
FileWriteLine($file, '@ECHO')
FileWriteLine($file, 'del %0\..\result.txt')
FileWriteLine($file, 'del %0\..\LSS.TMP')
FileWriteLine($file, 'del %0\..\IP.TXT')
FileWriteLine($file, 'ECHO -------------------------------------------')
FileWriteLine($file, 'FOR /f %%a in (%0\..\WS.TXT) do call %0\..\_lss.cmd %%a')
FileWriteLine($file, 'ECHO.')
FileWriteLine($file, 'ECHO.')

FileClose($file);closes the file

$Sendmailbutton = GUICtrlCreateButton("Send mail", 40, 330, 100, 30)
GUICtrlSetOnEvent(-1, "OKPressed")

GUISetState()
While 1
   Sleep(100)
WEnd

Func OKPressed()
   RunWait("\_LSS.cmd")
  ;run the cmd file
   
  ; Delete our file once its done
   FileDelete("_LSS.cmd")
   
EndFunc  ;==>OKPressed

Func _Exit()
   Exit
EndFunc  ;==>_Exit


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

thanks it ran the code but didint put in the value from the gui input box so i ammended the code by adding an input box before it seem to like that way

cheers code below for any one else

#include <GuiConstants.au3>

opt("GUIOnEventMode", 1)

; Create commands in cmd file

$file = FileOpen(@ScriptDir & "\_LSS.cmd", 2)

;create gui

$box = GUICreate("asset tool", 400, 400)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

GUISetIcon(@SystemDir & "\mspaint.exe", 0)

$input1 = InputBox("asset", "Please Enter machine name")

; asset inputbox

GUICtrlCreateLabel("asset Please", 40, 20, 40, 40)

$input2 = GUICtrlCreateInput($input1, 40, 60, 90, 20); asset read command

$Sendmailbutton = GUICtrlCreateButton("Send mail", 40, 330, 100, 30)

GUICtrlSetOnEvent(-1, "OKPressed")

GUISetState()

While 1

Sleep(100)

WEnd

Func OKPressed()

;creates the batch file

FileWriteLine($file, '@echo off')

FileWriteLine($file, 'set check_ws=%' & $input1 & '%')

FileWriteLine($file, '')

FileWriteLine($file, 'TYPE \\%' & $input1 & '\c$\"PROGRAM FILES"\CA\USD\SD\ASM\CONF\ASM.CNF|FIND "ASMSSLSR =SDCP3CME0">>0%\..\LSS.TMP')

FileWriteLine($file, '')

FileWriteLine($file, 'ping -n 1 %' & $input1 & ' | find /i "reply">>0%\..\IP.TMP')

FileWriteLine($file, 'ECHO ---------------------------------------------------------->>%0\..rESULT.TXT')

FileWriteLine($file, 'ECHO.>>%0\..rESULT.TXT')

FileWriteLine($file, 'ECHO.>>%0\..rESULT.TXT')

FileWriteLine($file, 'ECHO 1] THE IP ADDRESS FOR \\%' & $input1 & ' IS>>%0\..\rESULT.TXT')

FileWriteLine($file, 'TYPE IP.TMP>>%0\..\rESULT.TXT')

FileWriteLine($file, 'ECHO 2] THE LMS FOR \\%' & $input1 & ' IS >>%0\..\rESULT.TXT')

FileWriteLine($file, 'TYPE LSS.TMP>>%0\..\rESULT.TXT')

FileWriteLine($file, 'del %0\..\lss.tmp')

FileWriteLine($file, ' ')

FileWriteLine($file, ' ')

FileWriteLine($file, 'ECHO.>>%0\..rESULT.TXT')

FileWriteLine($file, 'TYPE \\%' & $input1 & 'c$"PROGRAM FILES"\CA\USD\SD\ASM\CONF\ASM.CNF|FIND "ASMUILSR =">>%0\..\LSS.TMP')

FileWriteLine($file, ' ')

FileWriteLine($file, ' ')

FileWriteLine($file, 'ECHO.>>%0\..rESULT.TXT')

FileWriteLine($file, 'ECHO 3] THE LOCAL LSS FOR \\%' & $input1 & ' IS >>%0\..\rESULT.TXT')

FileWriteLine($file, 'TYPE %0\..\LSS.TMP>>%0\..\rESULT.TXT')

FileWriteLine($file, 'ECHO.>>%0\..\rESULT.TXT')

FileWriteLine($file, ' ')

FileWriteLine($file, ' ')

FileWriteLine($file, 'del %0\..\lss.tmp')

FileWriteLine($file, 'ECHO **** sOFTWARE INSTALLED ON WORKSTATION ***>>%0\..\rESULT.TXT')

FileWriteLine($file, 'TREE \\%' & $input1 & '\c$\"Program Files"\CA\UAM\CLIENTWS\Software /f>>%0\..\LSS.TMP')

FileWriteLine($file, ' ')

FileWriteLine($file, 'TYPE %0\..\LSS.TMP>>%0\..\rESULT.TXT')

FileWriteLine($file, 'echo -----** END WORKSTATION *** -----')

FileWriteLine($file, ' ')

FileWriteLine($file, 'echo %2 ##############')

FileWriteLine($file, 'DEL 0%\..\IP.TMP')

FileWriteLine($file, 'DEL 0%\..\LSS.TMP')

FileWriteLine($file, '@ECHO')

FileWriteLine($file, 'del %0\..\result.txt')

FileWriteLine($file, 'del %0\..\LSS.TMP')

FileWriteLine($file, 'del %0\..\IP.TXT')

FileWriteLine($file, 'ECHO -------------------------------------------')

FileWriteLine($file, 'FOR /f %%a in (%0\..\WS.TXT) do call %0\..\_lss.cmd %%a')

FileWriteLine($file, 'ECHO.')

FileWriteLine($file, 'ECHO.')

FileClose($file);closes the file

RunWait("\_LSS.cmd")

;run the cmd file

; Delete our file once its done

FileDelete("_LSS.cmd")

EndFunc ;==>OKPressed

Func _Exit()

Exit

EndFunc ;==>_Exit

Share this post


Link to post
Share on other sites

I gave it a quick look changed some things.

You use the _lss.cmd file in different ways. For example:

In FileOpen: @ScriptDir & "\_LSS.cmd"

In RunWait: "\_LSS.cmd"

In FileDelete "_LSS.cmd"

This can work if you are in the root directory, else it will give problems.

Also create and close the file in the same function is the best way to do in this case.

Well, I didn't look into the generated script code, but give this a try and let me know what the result is. Maybe more adjustments are needed.

Dick

#include <GuiConstants.au3>
opt("GUIOnEventMode", 1)
; Create commands in cmd file

;create gui
$box = GUICreate("asset tool", 400, 400)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetIcon(@SystemDir & "\mspaint.exe", 0)

; $input1 = InputBox("asset", "Please Enter machine name")

; asset inputbox
GUICtrlCreateLabel("asset Please", 40, 20, 40, 40)
$input1 = GUICtrlCreateInput("", 40, 60, 90, 20); asset read command

$Sendmailbutton = GUICtrlCreateButton("Send mail", 40, 330, 100, 30)
GUICtrlSetOnEvent(-1, "OKPressed")

GUISetState()
While 1
    Sleep(100)
WEnd

Func OKPressed()
    
    $Input = GuiCtrlRead($input1)

   ;creates the batch file
    $file = FileOpen(@ScriptDir & "\_LSS.cmd", 2)
    
    FileWriteLine($file, '@echo off')
    FileWriteLine($file, 'set check_ws=%' & $Input & '%')
    FileWriteLine($file, '')
    FileWriteLine($file, 'TYPE \\%' & $Input & '\c$\"PROGRAM FILES"\CA\USD\SD\ASM\CONF\ASM.CNF|FIND "ASMSSLSR =SDCP3CME0">>0%\..\LSS.TMP')
    FileWriteLine($file, '')
    FileWriteLine($file, 'ping -n 1 %' & $Input & ' | find /i "reply">>0%\..\IP.TMP')
    FileWriteLine($file, 'ECHO ---------------------------------------------------------->>%0\..rESULT.TXT')
    FileWriteLine($file, 'ECHO.>>%0\..rESULT.TXT')
    FileWriteLine($file, 'ECHO.>>%0\..rESULT.TXT')
    FileWriteLine($file, 'ECHO 1] THE IP ADDRESS FOR \\%' & $Input & ' IS>>%0\..\rESULT.TXT')
    FileWriteLine($file, 'TYPE IP.TMP>>%0\..\rESULT.TXT')
    FileWriteLine($file, 'ECHO 2] THE LMS FOR \\%' & $Input & ' IS >>%0\..\rESULT.TXT')
    FileWriteLine($file, 'TYPE LSS.TMP>>%0\..\rESULT.TXT')
    FileWriteLine($file, 'del %0\..\lss.tmp')
    FileWriteLine($file, ' ')
    FileWriteLine($file, ' ')
    FileWriteLine($file, 'ECHO.>>%0\..rESULT.TXT')
    FileWriteLine($file, 'TYPE \\%' & $Input & '\c$"PROGRAM FILES"\CA\USD\SD\ASM\CONF\ASM.CNF|FIND "ASMUILSR =">>%0\..\LSS.TMP')
    FileWriteLine($file, ' ')
    FileWriteLine($file, ' ')
    FileWriteLine($file, 'ECHO.>>%0\..rESULT.TXT')
    FileWriteLine($file, 'ECHO 3] THE LOCAL LSS FOR \\%' & $Input & ' IS >>%0\..\rESULT.TXT')
    FileWriteLine($file, 'TYPE %0\..\LSS.TMP>>%0\..\rESULT.TXT')
    FileWriteLine($file, 'ECHO.>>%0\..\rESULT.TXT')
    FileWriteLine($file, ' ')
    FileWriteLine($file, ' ')
    FileWriteLine($file, 'del %0\..\lss.tmp')
    FileWriteLine($file, 'ECHO **** sOFTWARE INSTALLED ON WORKSTATION ***>>%0\..\rESULT.TXT')
    FileWriteLine($file, 'TREE \\%' & $Input & '\c$\"Program Files"\CA\UAM\CLIENTWS\Software /f>>%0\..\LSS.TMP')
    FileWriteLine($file, ' ')
    FileWriteLine($file, 'TYPE %0\..\LSS.TMP>>%0\..\rESULT.TXT')
    FileWriteLine($file, 'echo -----** END WORKSTATION *** -----')
    FileWriteLine($file, ' ')
    FileWriteLine($file, 'echo %2 ##############')
    FileWriteLine($file, 'DEL 0%\..\IP.TMP')
    FileWriteLine($file, 'DEL 0%\..\LSS.TMP')
    FileWriteLine($file, '@ECHO')
    FileWriteLine($file, 'del %0\..\result.txt')
    FileWriteLine($file, 'del %0\..\LSS.TMP')
    FileWriteLine($file, 'del %0\..\IP.TXT')
    FileWriteLine($file, 'ECHO -------------------------------------------')
    FileWriteLine($file, 'FOR /f %%a in (%0\..\WS.TXT) do call %0\..\_lss.cmd %%a')
    FileWriteLine($file, 'ECHO.')
    FileWriteLine($file, 'ECHO.')
    
    FileClose($file);closes the file
    
    
;run the cmd file
    RunWait(@ScriptDir & "\_LSS.cmd")
    
; Delete our file once its done
    FileDelete(@ScriptDir & "\_LSS.cmd")
    
EndFunc  ;==>OKPressed

Func _Exit()
    Exit
EndFunc  ;==>_Exit

Share this post


Link to post
Share on other sites

Cheers dudue that works fine i dont have to use a seprate msg box now

and it deleted the cmd later too

thanks a lot

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