Sign in to follow this  
Followers 0
y0_Aero

Converting batch file over to AutoIT

10 posts in this topic

I'm wanting to convert over two simple batch files over to AutoIT and completely automate them as currently i have to edit the batch files to change the workstation names.

First batch file simply starts a service for a number of workstations, the line is as follows:

sc \\WORKSTATIONNAME config SERVICENAME start= auto && sc \\WORKSTATIONNAME start SERVICENAME

And the second batch file runs an external program which runs through batch which remotely deletes user profiles, it's the same line repeated again as like the first line:

\\NETWORKPATHOFPROGRAM /c:WORKSTATIONNAME /u /ed:admin*

I'd like to be able to get the person to input the workstation names in a GUI input box and whatever they input to be put into the 'WORKSTATIONNAME' section of the line, i know this would be done using Variables but i can't get my head round how i'd be able to parse whatever they input and loop the line each time.

If anyone could point out where to start or some functions that would be handy for me that would be great, thankyou.

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

What have you tried so far?

Show us the code to help you.

Edited by Exit

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

So far I've found that I can run the macro @ComSpec so I know I'd have to do something along the lines of:

Run(@ComSpec & " /c WORKSTATIONNAME " & 'command', "", @SW_HIDE)

So would I then set variables and place them in the 'WORKSTATIONNAME' line once inputted from a GUI?

Share this post


Link to post
Share on other sites

Hi again y0_Aero.

I suggest you whip up some code, including your GUI arrangement, and share that here (masking anything private).

It is always much easier to get help if the asker provides some code first, which we can then modify where necessary.

It also helps us understand what skill level you are at, so as to best target our help or advice.

Like i said earlier in the Chatbox, you can do the full AutoIt thing and avoid Batch files, or you can implement both together, where your GUI setup has code to modify/edit the Batch files to meet your need.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

Hello TheSaint,

So far i've mocked up the GUI arrangement and added some Menu's for future projects but the tab i'm focusing on at the moment is the 'Project' tab.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Toolbox", 423, 309, 260, 140)
$PageControl1 = GUICtrlCreateTab(0, 8, 444, 320)
$TabSheet1 = GUICtrlCreateTabItem("Home")
$Pic2 = GUICtrlCreatePic("\\pathofimage", 4, 33, 417, 273)
$TabSheet2 = GUICtrlCreateTabItem("Project")
$Edit1 = GUICtrlCreateEdit("", 16, 72, 169, 129)
GUICtrlSetData(-1, "Edit1")
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Button1 = GUICtrlCreateButton("Submit", 16, 208, 89, 25)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Button2 = GUICtrlCreateButton("Clear", 112, 208, 73, 25)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$TabSheet3 = GUICtrlCreateTabItem("IP Tools")
$TabSheet4 = GUICtrlCreateTabItem("Registry")
$TabSheet5 = GUICtrlCreateTabItem("Programs")
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func workstation()
    Run(@ComSpec & " /c " & 'command & variable?', "", @SW_SHOW)
End Func

Now i'm just unsure on how i get whatever is inputted into the edit box to be put into a ComSpec macro line, would it be set from a variable?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

When  I was first starting I would use inputbox() rather than a full gui, and then when I had working code impliment the gui later.  Of course Koda and the other tools makes it easy enough to create a quick and dirty gui but just an idea to pass along.

As far as what you have the basic concept of passing a variable from a gui would be like this in most situations. (I commented where I added)

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Toolbox", 423, 309, 260, 140)
$PageControl1 = GUICtrlCreateTab(0, 8, 444, 320)
$TabSheet1 = GUICtrlCreateTabItem("Home")
$Pic2 = GUICtrlCreatePic("\\pathofimage", 4, 33, 417, 273)
$TabSheet2 = GUICtrlCreateTabItem("Project")
$Edit1 = GUICtrlCreateEdit("", 16, 72, 169, 129)
GUICtrlSetData(-1, "Edit1")
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Button1 = GUICtrlCreateButton("Submit", 16, 208, 89, 25)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Button2 = GUICtrlCreateButton("Clear", 112, 208, 73, 25)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$TabSheet3 = GUICtrlCreateTabItem("IP Tools")
$TabSheet4 = GUICtrlCreateTabItem("Registry")
$TabSheet5 = GUICtrlCreateTabItem("Programs")
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1 ;If Submit is Pressed...
            ExitLoop ;Exit the While Loop
    EndSwitch
WEnd

$EditValue = GUICtrlRead($Edit1) ;Get Value from $Edit1

workstation() ;Call our Function

Func workstation()
    Run(@ComSpec & " /c " & $EditValue, "", @SW_SHOW) ;Plug in command & varible as needed beware quotes!
EndFunc

 

Edited by ViciousXUSMC

Share this post


Link to post
Share on other sites

Maybe... 

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            workstation(GUICtrlRead($Edit1))
    EndSwitch
WEnd

Func workstation($INFO)
    MsgBox(0,"Test", @ComSpec & " /c " & $INFO)
;~     Run(@ComSpec & " /c " & 'command & variable?', "", @SW_SHOW)
EndFunc

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

And as you can see from Valuater, if you do not want to exit the GUI then call the function, normally I exit my loop with a GUI and intend to close it after a button press.

Share this post


Link to post
Share on other sites

I understand what you mean about just using inputbox() rather than a koda gui to start i'll keep that in mind for the future!

That's great so i can use GUICtrlRead to get the value from a variable then obviously call the function and use the ComSpec macro.

So that works for the premise of what i want, now how would i handle it if multiple workstation names are entered in the edit box seperated by commas, how would i parse each workstation name and then get it to loop the two ComSpec macros that i want to run on each workstation.

Thankyou both of you for your help!

Share this post


Link to post
Share on other sites

If you are expecting a list, like so: AFWorkstation1, AFWorkstation2, AFWorkstation3, AFWorkstation4, take a look at StringSplit in the help file. You can use this in conjunction with GUICtrlRead. Then you call your function/loop and pass the name of the workstation(s).


√-1 2^3 ∑ π, and it was delicious!

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