Disclaimer: This was only tested with Windows 7 and Windows 8. I believe that should work in other windows versions like vista or xp, but I haven't confirmed that yet.
EDIT (2015/03/20): I've noticed that the command to read the registry has different behaviors depending on where it runs. It can or can't add the "\" at the end of the SC2Path variable. That's why the batch should check what's the case and add the "\" to the variable if appropriate.
I've also noticed that the copy command could be affected if SC2 or SC2Galaxy are open. The batch should close them before copying.
I've updated the attached file fixing both issues.
EDIT2 (2015/05/07): I've found a way to make a shortcut file from a batch file and added it to the tutorial. The shortcut has the advantage over the .bat because SC2.exe has to be closed before starting the map. On the other hand, the shortcut can work with SC2 opened (only if there isn't any map running in Starcraft when launched).
EDIT2 (2016/04/13): Added a small note: After finishing designing your batch file, you should convert it to .exe, in order to avoid security issues prompted by the user's OS, firewall and/or antivirus.
This tool allows you to convert your .bat file into an .exe file.
----------------
TLDR Version
You can download the examples attached to this post (.lnk version - .bat version) and modify the .bat lines to make them work with your own maps and mods. It's not hard, believe me.
After finishing designing your batch file, you should convert it to .exe, in order to avoid security issues that the user's OS, firewall and/or antivirus could throw.
This tool allows you to convert your .bat file into an .exe file.
To make an installer you need to:
Create a new .txt file, and change its extension to .bat.
Get in it the directory of Starcraft II with the command "reg query" and set it in a variable
Copy your files to the maps and mods folders of Starcraft II directory with the command "copy" or "xcopy"
To make a launcher you need to:
Create a new .txt file, and change its extension to .bat.
Get in it the directory of Starcraft II with the command "reg query" and set it in a variable
Write an instruction to create a second .bat file (or a .lnk file) that launches SC2Switcher.exe
The code itself
The finished code will look like this one (.lnk version - Recommended. Remember to have XXMKLINK.EXE - available in the example batch - in the same folder of the .bat file):
Notice that it has the "mkdir" command. It's to create the "Maps" folder if it doesn't exists. You will have to make as many "copy" commands as files you have, and as much "mkdirs" commands as folders you have.
The .lnk version allows the player to open the map even if SC2 is already running (only while he's not playing another map). The benefit of this alternative is that the player can log into battle.net with his account, and play
the game with his own game preferences.
----------------
Full Tutorial
Hi there!
I'm seeing several singleplayer campaign projects being released trough this time, and I'm also seeing several coments of players and potential players having troubles to install them in their PCs, and launch them from the editor.
That's why I'm making this tutorial. After reading it, you'll be able to make a completely automatic batch file that copies your map and mod files to the corresponding maps/mods folders, and a launcher for the map that doesn't need to use the editor.
What is a batch file?
(From Wikipedia)
In DOS, OS/2, and also Microsoft Windows, batch file is the name given to a type of script file, a text file containing a series of commands to be executed by the command interpreter.
A batch file may contain any command the interpreter accepts interactively at the command prompt. A batch file may also have constructs (IF, GOTO, Labels, CALL, etc.) that enable conditional branching and looping within the batch file.
What do I need?
Windows, nothing else.
What am I going to do?
As said before, a file with a ".bat" extension that will copy all the needed files of your project to the "maps" and "mods" folders of starcraft II folder, and create another file that launches your main map.
How do I do it?
First, you will have to create a new ".txt" file with the notepad. You will write in it the commands that the batch will run and change its extension to ".bat" after finishing.
Go to start -> run -> notepad. It will create a new .txt file. You will have to save it as ".bat"
The first command to write in it is
@echooff
This command will avoid returning in the command line every line that the batch file has.
Now, you will need to use the copy or xcopy command to copy the files to the player's corresponding folders, for example:
(The difference between "copy" and "xcopy" is that "xcopy" copies a tree of files, and copy only copies one. I prefer using "copy" because when I was testing with xcopy, I had some troubles with the target path)
But, different users have those files in different paths, how do I make this work for everyone?
You can store variables in a batch file: The command "set" allows you to save a string into a variable with the name you want and use it later, for example:
setsc2path=C:\Program files (x86)\Starcraft II
If you use the "/p" signal, it will store into a variable the next thing that the user writes. For example
set/p sc2path=Write the directory of Starcraft II:
After storing it, you can call it naming it between two "%"
(echo returns in the command line the message written after it, pause is a command to wait until the user presses a key)
Can I get the paths I need without asking them to the user?
Yes, you can. You can get the StarCraft 2 directory from the registry, and the place where the ".bat" file is executed with a predefined variable.
In a batch, %d0%p0 is the directory where the ".bat" file executed is located.
To get the SC2 installation path you will need to use the command "reg query" to return the value of HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Starcraft II\InstallLocation.
But you only need the path, so you have to use a "for" loop. When it's used with the option "/f", it loops trough the text, spliting it in "tokens", wich are delimited with spaces or tabulations by default.
In this specyfic case, you need the text without the first token ("REG_SZ"), so you have to store in your variable everything from the 2nd token to the last one. That's achieved by the following way:
for/f"tokens=2*"%%a in ( 'reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Starcraft II" /v InstallLocation') doset"sc2path=%%~b"
Now, you only have to replace the paths of the copy (or xcopy) command with the variables obtained:
copy "%~d0%~p0YourMap.SC2Map""%SC2Path%maps\"
or
xcopy "%~d0%~p0YourMapFolder" "%SC2Path%maps\
(Notice that YourMap.SC2Map should be under the same folder that the batch to work properly, same with YourMapFolder)
IMPORTANT! -check the last character of the registry variable-
In some Windows versions, the variable SC2Path can be saved with the "\" at the end included, and in others without it.
That's why you have to add it manually if it isn't saved.
if you echo "%SC2Path:-1%", the batch will return the last character of the variable. You can use an "if" statement, to add to it the "\" if it doesn't end with it.
/IM is to say to Windows that it have to search the process by its name, and /F is to tell it to force the closure.
Nice! I know how to make a completely automatic installer. But how about the launcher? You've said that I didn't need the editor to launch my maps
You don't! There are two ways of opening your map without having to use the editor, and both use S2Switcher.exe -> It's the starcraft II executable file.
The first one is creating a shortcut to SC2Switcher. If you write the absolute path to the map you want to open next to the destination of SC2Switcher's shortcut, this shortcut will launch your map directly.
(Properties of the shortcut)
I've found a program on-line called "XXMKLINK.EXE". It allows batch files to create .lnk (shortcut) files. You can add the executable file to your downloadable package and call it from the installer to create a shortcut just like the one in the previous screenshot automaticaly.
"%d0%p0XXMKLINK.EXE" opens the downloaded executable placed in the root folder
"/q" disables the messages sent by the program with the errors or results of the process
"%SC2Path%Support\SC2Switcher.exe" is the target of the shortcut.
"\"%SC2Path%Maps\YourMap.SC2Map\"" is the argument next to the target to open the map. NOTICE the backslash before the quotes. They're there because xxmklink.exe would interpret those quotes as the end of the argument if the backslashes wouldn't exist.
----------------
The second way is to make a batch file that makes another batch file. How?
It's easy... An echo comand can be redirected to a plain text file with the ">" symbol. If you write the instruction that you need to launch SC2Switcher.exe with your map (the same that the shortcut had) and redirect it to a ".bat" file, then, when the player opens this new .bat will open directly your map.
This will create a new .bat file called Launcher.bat, that will open sc2 and launch the game.
Summarizing...
To make an installer you need to:
Create a new .txt file, and change its extension to .bat.
Get in it the directory of Starcraft II with the command "reg query" and set it in a variable
Copy your files to the maps and mods folders of Starcraft II directory with the command "copy" or "xcopy"
To make a launcher you need to:
Create a new .txt file, and change its extension to .bat.
Get in it the directory of Starcraft II with the command "reg query" and set it in a variable
Write an instruction to create a second .bat file (or a .lnk file) that launches SC2Switcher.exe
The code itself
The finished code will look like this one (.lnk version - Recommended. Remember to have XXMKLINK.EXE - available in the example batch - in the same folder of the .bat file):
Notice that it has the "mkdir" command. It's to create the "Maps" folder if it doesn't exists. You will have to make as many "copy" commands as files you have, and as much "mkdirs" commands as folders you have.
The .lnk version allows the player to open the map even if SC2 is already running (only while he's not playing
another map). The benefit of this alternative is that the player can log into battle.net with his account, and play
the game with his own game preferences.
Converting the .bat file into a .exe file
After finishing designing your batch file, you should convert it to .exe, in order to avoid security issues that the user's OS, firewall and/or antivirus could throw.
This tool allows you to convert your .bat file into an .exe file.
It's pretty straightforward. After installing and running it, a window will appear, where you'll have to choose the
original bat file and where you want to save the output.
You'll need to mark the option "Add administrator manifest" to make it ask for administrator permissions before running.
This software also allows you to pick an icon under the version information tab.
Well, that's all.
I hope this tutorial had been clear, and useful for somebody... I'm attaching an example map with its batch file.
You can google around and learn how to make your installer more complex by using conditional sentences (if), or submenus (goto).
Disclaimer: This was only tested with Windows 7 and Windows 8. I believe that should work in other windows versions like vista or xp, but I haven't confirmed that yet.
EDIT (2015/03/20): I've noticed that the command to read the registry has different behaviors depending on where it runs. It can or can't add the "\" at the end of the SC2Path variable. That's why the batch should check what's the case and add the "\" to the variable if appropriate.
I've also noticed that the copy command could be affected if SC2 or SC2Galaxy are open. The batch should close them before copying.
I've updated the attached file fixing both issues.
EDIT2 (2015/05/07): I've found a way to make a shortcut file from a batch file and added it to the tutorial. The shortcut has the advantage over the .bat because SC2.exe has to be closed before starting the map. On the other hand, the shortcut can work with SC2 opened (only if there isn't any map running in Starcraft when launched).
EDIT2 (2016/04/13): Added a small note: After finishing designing your batch file, you should convert it to .exe, in order to avoid security issues prompted by the user's OS, firewall and/or antivirus. This tool allows you to convert your .bat file into an .exe file.
----------------TLDR Version
You can download the examples attached to this post (.lnk version - .bat version) and modify the .bat lines to make them work with your own maps and mods. It's not hard, believe me.
After finishing designing your batch file, you should convert it to .exe, in order to avoid security issues that the user's OS, firewall and/or antivirus could throw. This tool allows you to convert your .bat file into an .exe file.
To make an installer you need to:
To make a launcher you need to:
The code itself
The finished code will look like this one (.lnk version - Recommended. Remember to have XXMKLINK.EXE - available in the example batch - in the same folder of the .bat file):
or this one (batch created .bat version):
Notice that it has the "mkdir" command. It's to create the "Maps" folder if it doesn't exists. You will have to make as many "copy" commands as files you have, and as much "mkdirs" commands as folders you have.
The .lnk version allows the player to open the map even if SC2 is already running (only while he's not playing another map). The benefit of this alternative is that the player can log into battle.net with his account, and play the game with his own game preferences.
----------------Full Tutorial
Hi there!
I'm seeing several singleplayer campaign projects being released trough this time, and I'm also seeing several coments of players and potential players having troubles to install them in their PCs, and launch them from the editor.
That's why I'm making this tutorial. After reading it, you'll be able to make a completely automatic batch file that copies your map and mod files to the corresponding maps/mods folders, and a launcher for the map that doesn't need to use the editor.
What is a batch file?
(From Wikipedia)
In DOS, OS/2, and also Microsoft Windows, batch file is the name given to a type of script file, a text file containing a series of commands to be executed by the command interpreter.
A batch file may contain any command the interpreter accepts interactively at the command prompt. A batch file may also have constructs (IF, GOTO, Labels, CALL, etc.) that enable conditional branching and looping within the batch file.
What do I need?
Windows, nothing else.
What am I going to do?
As said before, a file with a ".bat" extension that will copy all the needed files of your project to the "maps" and "mods" folders of starcraft II folder, and create another file that launches your main map.
How do I do it?
First, you will have to create a new ".txt" file with the notepad. You will write in it the commands that the batch will run and change its extension to ".bat" after finishing.
Go to start -> run -> notepad. It will create a new .txt file. You will have to save it as ".bat"
The first command to write in it is
This command will avoid returning in the command line every line that the batch file has.
Now, you will need to use the copy or xcopy command to copy the files to the player's corresponding folders, for example:
or
(The difference between "copy" and "xcopy" is that "xcopy" copies a tree of files, and copy only copies one. I prefer using "copy" because when I was testing with xcopy, I had some troubles with the target path)
But, different users have those files in different paths, how do I make this work for everyone?
You can store variables in a batch file: The command "set" allows you to save a string into a variable with the name you want and use it later, for example:
If you use the "/p" signal, it will store into a variable the next thing that the user writes. For example
After storing it, you can call it naming it between two "%"
(echo returns in the command line the message written after it, pause is a command to wait until the user presses a key)
Can I get the paths I need without asking them to the user?
Yes, you can. You can get the StarCraft 2 directory from the registry, and the place where the ".bat" file is executed with a predefined variable.
In a batch, %d0%p0 is the directory where the ".bat" file executed is located.
To get the SC2 installation path you will need to use the command "reg query" to return the value of HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Starcraft II\InstallLocation.
This code
will return something like this:
But you only need the path, so you have to use a "for" loop. When it's used with the option "/f", it loops trough the text, spliting it in "tokens", wich are delimited with spaces or tabulations by default.
In this specyfic case, you need the text without the first token ("REG_SZ"), so you have to store in your variable everything from the 2nd token to the last one. That's achieved by the following way:
Now, you only have to replace the paths of the copy (or xcopy) command with the variables obtained:
or
(Notice that YourMap.SC2Map should be under the same folder that the batch to work properly, same with YourMapFolder)
IMPORTANT! -check the last character of the registry variable-
In some Windows versions, the variable SC2Path can be saved with the "\" at the end included, and in others without it.
That's why you have to add it manually if it isn't saved.
if you echo "%SC2Path:-1%", the batch will return the last character of the variable. You can use an "if" statement, to add to it the "\" if it doesn't end with it.
(If the last character of %SC2Path% is "\", leave the variable as it is, else add a bar to its end)
IMPORTANT! -close SC2.exe and SC2Editor.exe-
Before copying the files, you could have some permission troubles if the player has opened the editor or starcraft. You have to force them to close.
/IM is to say to Windows that it have to search the process by its name, and /F is to tell it to force the closure.
Nice! I know how to make a completely automatic installer. But how about the launcher? You've said that I didn't need the editor to launch my maps
You don't! There are two ways of opening your map without having to use the editor, and both use S2Switcher.exe -> It's the starcraft II executable file.
The first one is creating a shortcut to SC2Switcher. If you write the absolute path to the map you want to open next to the destination of SC2Switcher's shortcut, this shortcut will launch your map directly.
(Properties of the shortcut)
I've found a program on-line called "XXMKLINK.EXE". It allows batch files to create .lnk (shortcut) files. You can add the executable file to your downloadable package and call it from the installer to create a shortcut just like the one in the previous screenshot automaticaly.
The instruction will look like this:
"%d0%p0XXMKLINK.EXE" opens the downloaded executable placed in the root folder
"/q" disables the messages sent by the program with the errors or results of the process
"%SC2Path%Support\SC2Switcher.exe" is the target of the shortcut.
"\"%SC2Path%Maps\YourMap.SC2Map\"" is the argument next to the target to open the map. NOTICE the backslash before the quotes. They're there because xxmklink.exe would interpret those quotes as the end of the argument if the backslashes wouldn't exist.
----------------The second way is to make a batch file that makes another batch file. How?
It's easy... An echo comand can be redirected to a plain text file with the ">" symbol. If you write the instruction that you need to launch SC2Switcher.exe with your map (the same that the shortcut had) and redirect it to a ".bat" file, then, when the player opens this new .bat will open directly your map.
The command should look like this:
This will create a new .bat file called Launcher.bat, that will open sc2 and launch the game.
Summarizing...
To make an installer you need to:
To make a launcher you need to:
The code itself
The finished code will look like this one (.lnk version - Recommended. Remember to have XXMKLINK.EXE - available in the example batch - in the same folder of the .bat file):
or this one (batch created .bat version):
Notice that it has the "mkdir" command. It's to create the "Maps" folder if it doesn't exists. You will have to make as many "copy" commands as files you have, and as much "mkdirs" commands as folders you have.
The .lnk version allows the player to open the map even if SC2 is already running (only while he's not playing another map). The benefit of this alternative is that the player can log into battle.net with his account, and play the game with his own game preferences.
Converting the .bat file into a .exe file
After finishing designing your batch file, you should convert it to .exe, in order to avoid security issues that the user's OS, firewall and/or antivirus could throw. This tool allows you to convert your .bat file into an .exe file.
It's pretty straightforward. After installing and running it, a window will appear, where you'll have to choose the original bat file and where you want to save the output.
You'll need to mark the option "Add administrator manifest" to make it ask for administrator permissions before running.
This software also allows you to pick an icon under the version information tab.
Well, that's all.
I hope this tutorial had been clear, and useful for somebody... I'm attaching an example map with its batch file.
You can google around and learn how to make your installer more complex by using conditional sentences (if), or submenus (goto).
Check out my kitbashes! Custom Campaign Initiative: Lots of great Custom Campaigns!! Check out and Support!!
This is cool. Thanks for sharing.
NECROBUMPING ALERT!
I've noticed some errors, and learned some new things. The tutorial is now updated (check the edit in the first post).
@ScorpSCII: Go
You're welcome! I'm glad this was useful for somebody.
Check out my kitbashes! Custom Campaign Initiative: Lots of great Custom Campaigns!! Check out and Support!!
Another bump!
I've finally found a way to create a .lnk (shortcut) file via batch. The tutorial has been updated again.
Check out my kitbashes! Custom Campaign Initiative: Lots of great Custom Campaigns!! Check out and Support!!