AutoIt BuilderOK. I have to admit it. I got caught in a bit of a fib on Sunday. Actually, it was more of a case of bad proofreading than anything else. In my post Automatic Drive Mapping, I stated:

you can’t make a batch file into an executable

Well, wary DCoT reader D Steele caught me in my mistake and let me know that there are actually several ways that you can convert a batch file into an executable.

I had actually realized this when I was writing the previous post but promptly forgot about it before I submitted the post. So, apologies for the error.

In fact, it is really easy to do. Here is how I do it in AutoIt:

;Make batch executable
#include <File.au3>
 
Dim $TempBatchFile = _TempFile(@TempDir,"",".bat")
Dim $HideConsole = False
 
FileInstall("MyBatch.bat",$TempBatchFile)
 
If $HideConsole Then
	RunWait($TempBatchFile,@TempDir,@SW_HIDE)
Else
	RunWait($TempBatchFile,@TempDir)
EndIf
 
FileDelete($TempBatchFile)
 
MsgBox(64,"Done","Execution complete!")

Download this code: MyBatch.au3

A couple of little things about this script. It will not show the “DOS box” as it is written. If you want to see the console screen, simply change this line:

Dim $HideConsole = False

to:

Dim $HideConsole = True

The console should now appear.

Also, the line:

FileInstall(“MyBatch.bat”,$TempBatchFile)

is where you put in the full path and name of your batch file. Simply change MyBatch.bat to the name of your batch file. You cannot use a variable for this because of how AutoIt is designed.

Once you have all of these things set, all you need to do is compile your script and you are done! Instantly compiled batch file!

Similar Posts:

If you found this post useful, why don't you buy me a cup of coffee to show your gratitude?

Hard DriveIn one of the comments on Providing User Feedback In AutoIt, Jim is wondering how you can map drives:

I was wondering though, can autoit make an executable that would setup a permanent drive map. Instead of a non-technical user mapping a drive, the executable file would setup a predefined mapped drive. That would be cool..
Thanks
Jim

Well, Jim, there are several different ways that you can map drives but two of the easiest are using a batch file or through AutoIt. Now I know that you can’t make a batch file into an executable but I thought that I would show you how todo this anyway.

Our Example

For this post, I want to use an example to help clarify these concepts. For our example, we would like to map drive letter T: to network share \\server\share.

Batch File

To map a drive in a batch file, simply use the net use command. So, for our example, we would use:

net use T: \\server\share

If you want the drive mapping to return each time you reboot, add the /persistent:yes option:

net use T: \\server\share /persistent:yes

AutoIt

In AutoIt, you use the DriveMapAdd command. Our example would look like this:

DriveMapAdd("T:","\\server\share")

To allow it to survive a reboot, add one more option:

DriveMapAdd("T:","\\server\share",8)

That’s all there is to it. You can then compile this into an executable and away you go!

Hope that answers your question, Jim

Similar Posts:

If you found this post useful, why don't you buy me a cup of coffee to show your gratitude?

PropertiesI recently read on Lifehacker about a system called ScrubIT which blocks pornography on your system. Here is what Lifehacker has to say:

All you do is configure your router to use ScrubIT’s DNS servers. Alternately, Windows 2000/XP users can download a utility that tweaks the networking settings accordingly.

I thought, “Very cool!” until I read this:

…there’s no uninstaller for the DNS utility, meaning once you’ve run it, your system will face “scrubbed” sites indefinitely. (I’m still working to extricate it from my PC; incredibly, the ScrubIT site offers no information on undoing the utility’s changes.) I’m hoping this rather startling oversight will be corrected soon, as it’s hard to recommend a service that won’t go away if you want it to.

So, I took it upon myself to investigate. I was surprised to see that the ScrubIT configuration utility was actually a compiles AutoIT script. After a bit of “playing” I was able to reverse engine the original script.

Essentially, all this configuration utility does is set the DNS settings on all of the network cards to their DNS settings; i.e. 67.138.54.100 and 207.225.209.66. In fact, it even uses the built in NETSH command to perform the DNS changes.

To remove the changes made by the configuration utility, all you need to do is the following:Open

  1. Open up the Control Panel
  2. Double click on Network Connections

Then for each network connection you see in this window, do the following:

  1. Right click on the network connection and click on Properties in the context menu
  2. Under, This connection uses the following items: click on Internet Protocol (TCP/IP)
  3. Click on the Properties button. This will open a new window
  4. At the bottom of the window, you will see a section selected that says Use the following DNS server addresses: and then it will have 67.138.54.100 and 207.225.209.66 in the list.
  5. If you use DHCP, then select Obtain DNS server address automatically. If you do not use DNS, change 67.138.54.100 and 207.225.209.66 to your DNS addresses.
  6. Close all windows.

That should do it for you.

Just one other bit of warning. If you use this configuration utility in a networking environment such as Windows Active Directory, this can break your system. You may experience either extremely long log-on times or lose the ability to log on to the domain at all. It is best to put these DNS settings into the router or firewall.

Update

I have completed the UnScrubIT configuration utility.  This is only to be used if you are running DHCP on your network.

Similar Posts:

If you found this post useful, why don't you buy me a cup of coffee to show your gratitude?

CodeNorm is new to Daily Cup of Tech and wants to know about the scripting language that I develop in. Norm writes:

I’m very interested in your creative and innovative use of scripts. Could you tell me what language you’re scripting in? I’m not familiar enough to identify what language it’s in.

Thank you!

Thanks for the e-mail, Norm. I have been enamored with AutoIt for many years now and I write pretty much everything exclusively in this scripting language. I used to be a big VBScript guy but switched over a while ago now.

There are several reasons that I use AutoIt as opposed to other languages:

  1. It is freeware.
  2. I am not a developer by trade and AutoIt allows me to create very useful scripts without much difficulty.
  3. Unlike many other scripting languages, AutoIt can create self-contained executables that do not rely on other outside libraries or sources.
  4. I can easily automate repetitive tasks including key presses and mouse movements.

Here are a few useful AutoIt links:

I hope that you have as much fun with AutoIt as I have.

Similar Posts:

If you found this post useful, why don't you buy me a cup of coffee to show your gratitude?

Code WashingIts been over three months since I wrote USB Drive AutoRun.inf Tweaking but there is still some very good activity over at this article.

For example, Aaron has created a couple of batch files that change the icon displayed by the USB drive. When it is plugged in, it randomly selects a different icon to display for the next time it is launched.

Inspired by Aaron’s work, Kevin created an AutoIt script that performs a very similar task!

I think that this is a really good example of people taking different technologies (i.e. autorun.inf configuration and batch/AutoIt programming), and coming up with something even better than the original. I am even considering adding some of Kevin’s work into my DCoT Menu application (with Kevin’s permission, of course)!

If anyone else has some good examples of how you have combined two seemingly unrelated technologies and come up with something bigger than the sum of the two, feel free to let everyone know in the comments. Or, if you are especially proud of a solution you have created, you may want to write a complete article for DCoT!

Similar Posts:

If you found this post useful, why don't you buy me a cup of coffee to show your gratitude?

« Previous PageNext Page »