This posting covers how to create a script (application) for your Mac to automatically connect to a shared Windows folder when you login to your Mac.
Creating the Script
- Open the Apple Script Editor: Applications > Utilities > AppleScript Editor
- Enter the script code below:
(Note: if you copy/paste this code you may need to re-type all the “double quotes” to correct the syntax.)
- Click the Compile button to validate your code.
tell application "Finder"
if not (exists disk "SHARED") then mount volume "smb://MyServer/MyShare"
Saving the Script File as an AppleScript file
This will save the script in a format that can later be edited, if you chose to make changes.
- File > Save
- Specify a name for your script. For example: MapNetworkServers.scpt
- File Format: Script
- Run Only: Unchecked
Saving the Script File as an Application
This will save the file in an executable format. This is the file that will run at login.
- File > Save As
- Specify where you want to save your script file, and specify a file name. For example: MapNetworkServers.app. I created a folder called “Commands” in my Documents folder where I store my script and application file.
- Set the File Format to Application.
- Check the Run Only check box. This will cause the script to run and exit.
- Click Save.
You should now have two files:
- MapNetworkServers.scpt – keep this file so you can modify this script in the future.
- MapNetworkServers.app – this is the script you will use to configure to execute when you login.
Configure the Script to Run at Login
- Go to System Preference > Accounts
- Select the appropriate user; the user you want this script to run when they login.
- Select the Login Items tab.
- Click the “+” button at the bottom of the list of applications to add a new startup application.
- Browse to your MapNetworkServers.app file and select it.
- You should now see it in the list.
- Optional: You can check the Hide check box, if you like. I suggest not doing this until you know your script is working correctly.
That’s it. Your shared Windows server folders should now be mapped automatically when you login.
This sample script only maps one folder, the “MySharedFolder” folder. However, on my home network I have several folders on the same server that exist. If you have previously selected all the shared Windows folders (using Finder > Go > Connect to Server), and provide your login credentials to that server, all the shared folders on that server will appear; which is ultimately what I want anyway. This also allows your script to be shorter and easier to maintain by having to map one shared folder in your script instead of having to write a line of code for each and every shared foler on that Windows server.
This is something that anyone who uses Virtual Server or Virtual PC should know.
System administrators and software developers, especially those who are developing SharePoint solutions, often develop or test using virtual machines, either Virtual PC 2007 or Virtual Server 2005 R2. Creating new virtual machines can be a time consuming effort; one we would all like to prevent from having to do every time we need a new virtual machine. The great thing is that you can save all the time it takes to install Windows and the latest Windows Updates if you SysPrep a virtual machine.
What Is SysPrep?
SysPrep is a tool that allows you to prepare or “prep” a machine with the operating system along with any software you wish was pre-installed and pre-configured. Once a machine is SysPrep’d, you have a new virtual machine that has the Windows operating system along with any additional software or features you want, such as IIS, pre-installed and pre-configured. SysPrep allows you to create your perfect system configuration packaged so that you can have a new virtual machine up and running in just minutes. And, it is available for both Windows Server 2003 and Windows XP.
Where Is SysPrep?
The SysPrep tool is located in a separate download from Microsoft called the System Preparation tool for Windows Server 2003 Service Pack 2 Deployment.
How To SysPrep
Building Your Virtual Machine Image
- Install your OS. Windows Server 2003 R2 SP2 (or latest service pack), or Windows XP, or Vista.
Note: I have not personally tried to SysPrep a Vista machine yet.
- Do NOT join the machine to a domain, at least not yet. (so you can leave the Admin password blank)
- Reset the Administrator password to blank.
- Get the latest Windows Updates. Reboot and get latest again until there are no more required updates.
- Antivirus (Yes, your virtual machines should have antivirus software installed.)
- BGInfo (optional. Just a tool I like to use that provides system information on the desktop background.)
- Daemon Tools CD Emulator. (optional. Just a tool I like to use to access ISO images.)
- Install the latest VM Additions. (optional, but you will likely want to install this. This comes with your Virtual PC and Virtual Server.)
- .NET Framework 3.5 SP1. (optional. This will include the latest .NET Framework for 1.1, 2.0, and 3.0.)
- Activate the Windows license (if you want to prevent having to re-activate Windows for each new virtual machine you create.)
Preparing to SysPrep: Creating a SysPrep.inf File
Before you can SysPrep you virtual machine, you need to create a SysPrep.inf configuration file. This file contains the information about your machine. It will also prevent you from having to enter you CD Key each time you create a new virtual machine from you SysPrep’d image. Below is a sample of the SysPrep.inf file that you need to create. This file configures the SysPrep process and automates boot up process.
- On your virtual machine, create a folder SysPrep at the root of your C: drive (C:\SysPrep).
- Copy the following text into a text file named SysPrep.inf.
- Enter the correct values for the following keys:
- TimeZone – the value of 10 is MST. You may want to change this to your local time zone, but it is not required to do so.
- OEMDuplicatorsting – this should contain the name of the operating system you have installed on your virtual machine.
- FullName – your name, the name you would enter if you were installing Windows.
- OrgName – the name of your company, or blank.
- ProductKey – Your product key (CD key) license.
Sample SysPrep.inf file:
OEMDuplicatorstring="Windows Server 2003 R2 Standard"
FullName="YOUR NAME HERE like Mark Wagner"
OrgName="YOUR COMPANY NAME HERE like Contoso"
Your SysPrep.inf configuration file is now ready to be used.
SysPrep-ing your Virtual Machine
SysPrep-ing your virtual machine takes just a minute or two. Most of the time is simply shutting down your virtual machine. Important: do not start this virtual machine back up or it will un-SysPrep your machine. If this does happen, you can simply go through these steps below to SysPrep you virtual machine again.
- On your virtual machine, in the C:\SysPrep folder, run SysPrep.exe.
- Check the “Don’t reset grace period for activation” option.
- Make sure Shutdown mode is Shut down.
- Click the Reseal button to shutdown and package.
- Click OK to generate new SID’s.
- Your virtual machine will now shut down and be SysPrep’d.
- You now have a virtual image that is SysPrep’d, but not ready to be used.
- Before you use this image, you will need to make a backup copy of your virtual machine image files. This will allow you to always have a SysPrep’d virtual machine ready and waiting.
- Backup your SysPrep’d virtual machine image files (.vhd, .vmc), and rename them to something you can easily understand and that describes what your image contains. For example:
- Windows Server 2003 R2 SP2 SysPrep.vmc
- Windows Server 2003 R2 SP2 SysPrep.vhd
- You now have Your virtual machine SysPrep’d. You can now use this image to quickly create a new virtual machine in minutes, with a new machine name and new unique System ID (SID) each time you use it.
Using Your SysPrep’d Image to Create a New Virtual Machine
Now, creating a new virtual machine will only take just a couple minutes.
- First, you need to copy your SysPrep’d image to a new name and to a new location where you will use this new virtual machine. Copy your SysPrep’d image files (.vmc & .vhd) to a new location where you want your new virtual machine file to reside.
- Rename them to a new, appropriate name. For example, if you are going to create a SharePoint server you might name them something like:
- Add this new virtual machine to you Virtual PC or Virtual Server; which ever you are using;
- Edit the configuration and make sure the virtual hard drive (VHD) is pointing to your new .vhd file. In this example, the MySharePoint2007.vhd file.
- Configure any other items such as memory allocation and network cards as necessary.
- Start the virtual machine.
- You will receive a few prompts such as the name for you new machine.
- If you wish, you can now join you virtual machine to a domain.
SysPrep is a must have time-saving tool for anyone who uses Virtual PC and/or Virtual Server.