Jump to content
Sign in to follow this  
zeroni13

Executing batch files adding them inside the compiled exe?

Recommended Posts

zeroni13

I just started scripting in autoit, and this is my first script so please don't laugh. ;)

Anyway, what I'm trying to do is to mount/unmount a network drive with autoit, I have gotten it to run, but I dont want to have those batch files with me (I only want the exe file).

This is the script i have so far, but i want the batch files to be included inside the exe.

#include 
Opt('MustDeclareVars', 1)

MainGUI()


Func MainGUI()
Local $Window1, $Window2, $Button1, $Button2, $Button3, $msg
$Window1 = GUICreate("Report Server Mount", 240, 70)

Opt("GUICoordMode", 2)
$Button1 = GUICtrlCreateButton("Mount", 10, 10, 100, 50)
$Button2 = GUICtrlCreateButton("Unmount", 20, -1)

GUISetState()

While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $Button1
Run('mount.cmd')
GUIDelete($Window1)
$Window2 = GUICreate("Mounted", 240, 70)
Opt("GUICoordMode", 2)
$Button3 = GUICtrlCreateButton("Mounted", 10, 10, 220, 50)
GUISetState()

While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
If $msg = $GUI_EVENT_CLOSE Then Exit
ExitLoop
Case $msg = $Button3
Exit
EndSelect
WEnd

Case $msg = $Button2
Run('unmount.cmd')
GUIDelete($Window1)
$Window2 = GUICreate("Unmounted", 240, 70)
Opt("GUICoordMode", 2)
$Button3 = GUICtrlCreateButton("Unmounted", 10, 10, 220, 50)
GUISetState()

While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
If $msg = $GUI_EVENT_CLOSE Then Exit
ExitLoop
Case $msg = $Button3
Exit
EndSelect
WEnd
EndSelect
WEnd
EndFunc

If anybody know's what I'm doing wrong please tell me! Thanks!

Share this post


Link to post
Share on other sites
BrewManNH

This might be far easier than a batch file and script combo

#include <GUIConstantsEx.au3>
Opt('MustDeclareVars', 1)

MainGUI()


Func MainGUI()
     Local $Window1, $Window2, $Button1, $Button2, $Button3, $msg
     Local $Flag = 1 ; persistent mapping flag
     $Window1 = GUICreate("Report Server Mount", 240, 70)

     Opt("GUICoordMode", 2)
     $Button1 = GUICtrlCreateButton("Mount", 10, 10, 100, 50)
     $Button2 = GUICtrlCreateButton("Unmount", 20, -1)

     GUISetState()

     While 1
          $msg = GUIGetMsg()
          Select
               Case $msg = $GUI_EVENT_CLOSE
                    ExitLoop
               Case $msg = $Button1
                    ; maps the drive to the letter X:, replace the $Flag with the proper information
                    ; Replace <username> and <password> with a valid user name and password if needed, if none needed
                    ; delete that part.
                    DriveMapAdd("X:", "\\yournetworkdrive\Share", $Flag, "<username>", "<password>")

               Case $msg = $Button2
                    ; Deletes the mapped drive X:
                    DriveMapDel("X:")

          EndSelect
     WEnd
EndFunc   ;==>MainGUI


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
zeroni13

Thank you very much! Glad I can just throw those batch scripts away, and use pure autoit code, still I did not get what  Local $Flag = 1 ; persistent mapping flag" was for.

Share this post


Link to post
Share on other sites
BrewManNH

Click on DriveMapAdd in the code above and it will open the help documentation for the function, or the help file will give you the options it accepts.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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  

×