Jump to content

Executing batch files adding them inside the compiled exe?


 Share

Recommended Posts

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...