Tag Archives: cmd.exe

XAMPP and Windows: How to Create a Symbolic Link Tips, Tricks and Tutorials 25 NOV 2014

If you have scripts which need to be run in your local web browser but fall outside of your web root or any other declared vhost directory, there is always the option of simply creating symbolic links to these external locations from within your web root folder.

To do this (and I needed to on my Windows 7 environment to get around some Sencha ajax origin restrictions during debugging) follow the following steps:

1. Click the Start button to bring up the start menu.

2. Type cmd in the universal search box at the bottom of the start menu. (You should see at the top of the search results under Programs cmd.exe highlighted)

3. Press the Ctrl + Shift + Enter to launch the command prompt (cmd.exe) as Administrator. If you don’t do this, you’ll get a error saying that there are insufficient permissions to create the symbolic link later on. (You can also right click and select “Run as Administrator” to achieve the same thing.)

4. A box saying “Windows needs your permission to continue” will pop up. Click Continue.

5. Go to the directory you want to create the link in. For example: cd c:\xampp\htdocs\

6. Use mklink to create your symbolic link (or shortcut):

mklink /D externalfolder "c:\Users\username\Documents\My Folder\"

Note: The /D is there because, in this example, we are linking to a directory. “externalfolder” is the name of the symbolic link (change to whatever you want). Finally, the path is where the symbolic link actually resolves to.

Using the example laid out below, we could now point our browser to http://localhost/externalfolder/hello-world.php which would run just fine, with the browser executing c:\Users\username\Documents\My Folder\hello-world.php in reality.

Useful little trick to be aware of.

xampp logo

Windows: How to Get your Laptop’s Serial Number and Model Name Tips, Tricks and Tutorials 08 AUG 2014

20091016-Windows-Command-PromptMost big name laptops and desktops all have serial numbers and model names, useful bits of information when looking up tech assistance. This information is usually printed on stickers and placed somewhere on either the bottom or the back of the device, but as we all know, stickers aren’t exactly the most permanent of solutions three or four years down the line.

If you are running Microsoft Windows (tested on Windows 7, Fujitsu Lifebook A Series laptop), and have lost your serial number or want to find out the model name, open up a command prompt (search for and execute cmd.exe in the Windows start menu).

With your DOS prompt now open, run:

wmic bios get serialnumber

This will retrieve your laptop’s serial number. To get the product name, run:

wmic csproduct get name

Useful to remember.

For interest’s sake, the heavy lifting is being done by Windows Management Instrumentation Command-line (WMIC), which uses the power of Windows Management Instrumentation (WMI) to enable systems management from the command line. See the related link for more info.

Related link: http://technet.microsoft.com/en-us/library/bb742610.aspx

Windows: How to Comment out a Line in a Batch File Tips, Tricks and Tutorials 27 JAN 2014

20091016-Windows-Command-PromptAs a reminder to myself so that I don’t have to Google it each and every time I need to work on a Windows Server (in other words, very seldom), there are three ways of adding comments into batch files (.bat) in Windows.

The first, most recognised way (standards-compliant, documented statement) is by making use of the REM statement. Any line in your batch file that starts with REM (which stands for REMark) is completely ignored by the batch interpreter.

Of course, because the way in which batch files are processed by COMMAND.COM and CMD.EXE, i.e. the batch file is read, the command is executed, and then the batch file is reread in order to execute the next command, rinse and repeat until the end of the file, REM statements do in essence slow down the execution of a batch file – though taking into account today’s processing power, this slowdown is negligible (unless of course your batch file is SUPER long!).

REM Comment - This bat-file moves all files

At this point it might be useful to remind yourself that by default the batch interpreter will print out each command before it is processed. Since REM commands don’t do anything, it’s safe to print them without any side effects. If however you want to avoid printing a command, including the REM statement, prefix it with @, or, to apply that setting throughout the program, run @echo off. (It’s echo off to avoid printing further commands; the @ is to avoid printing that command prior to the echo setting taking effect.)

The second way of commenting out a line in a batch file is by utilizing a clever trick that in essence has you converting your comment line into a label by prefixing it with a double colon (::). The first colon tells the batch interpreter that the following text is a label, while the second colon invalidates the label status but then forces the interpreter to still treat the line as a label anyway. This trick has the advantage of not slowing down the interpreter because it doesn’t have to stop to interpret the command statement like it has to for a REM statement – it simply jumps to the next line of the file without having to first reread the whole file again!

:: Comment - This bat-file moves all files

However, this trick does not allow you to start a comment mid line as labels always start at the first non-whitespace character in a command line. Also, code blocks are a pitfall for this trick as commands grouped by parentheses are interpreted as a single command line by the batch interpreter, which then obviously invalidates our ‘fake’ label as just mentioned above – your comment most likely won’t be sitting at the start of the concatenated command line!

Finally you can write multiple lines of comments (or comment blocks) by making use of the ability to jump over your lines of comment using the GOTO statement. In practice:

GOTO EndComment
Comment - This bat-file moves all files
Line 2 - Written by Craig
Line 3 - 2014-01-27
:EndComment

Note, it is probably a good idea to help others understand what is going on by using a descriptive GOTO label name.

And there you go, three different ways of adding comment lines into your .bat batch file.

Related Link: http://www.robvanderwoude.com/comments.php

Tech Tip: Retain your windows desktop environment on any device (PC/Mac/Linux/Android/iOS) by remote accessing your citrix xendesktop from CloudDesktopOnline at an unbelievable citrix xendesktop pricing. To enhance your experience with desktop in the cloud try out dedicated GPU hosting from Apps4Rent to fulfill your graphics requirements.