Windows Live Alerts
Start access
Support Forum
Remote Desktop Services
Terminal Services
Web Interface
Tips & Tools
Lassen Sie sich von einem Experten Beraten

Shell scripting basics Print E-mail

This is a basic introduction in Windows shell scripting. The script examples are sometimes used in combination with well known Microsoft resourcekit utilities like iFmember.

Shell scripts & Windows registry

For some Applications you might need the username somewhere in a registry key.
For instance:

The main idear is to get the UserName from the Windows environment variable %UserName% and create the registry file just befor it will be applied.

  1. @echo off
  2. @echo Windows Registry Editor Version 5.00> MyApp.reg
  3. @echo [HKCU\Software\MyApp\User\%UserName%]>> MyApp.reg
  4. @echo "Start"="Parameter">> MyApp.reg
  5. regedit /s MyApp.reg

Image NOTE

The registry file MyApp.reg will be recreated every time the script is running, there is no need to delete the registry file MyApp.reg. Also make sure that there is NO space between "]_>" and "_>>"

Jump and Exit shell commands

Sometimes you want to skip commands for some reason or user / group and the following examples shows some different way how to do that.

Skip the Administator account and therefore doesn't get an l: drive
  1. @echo off
  2. if /i %UserName% == Administrator goto done
  3. net use l: \servername\share
  4. :done
Image NOTE

After the :done mark the script can continue if there are additional commands.

With the eof (end of file) option or the exit command you can end the script.
  1. @echo off
  2. if /I %UserName% equ Administrator goto :eof
  3. net use l: \servername\share

You want that only the Administrator runs a script and than exit the main script?
  1. @echo off
  2. If /I %UserName% == Administrator
  3. call MyScript.cmd & goto :eof
  4. net use l: \servername\share

Skip the Domain Citrix-Admin group and they get no l: drive
  1. @echo off
  2. iFmember "domain\citrix-admin"
  3. if ERRORLEVEL 1 call MyScript.cmd & goto :eof
  4. net use l: \servername\share

The following script shows how to check the Userhome drive and create a temp userhome drive if the real one is unavailable.

  1. @echo off
  2. if not exist H: md "%UserProfile%\TEMP" & subst H: "%UserProfile%\TEMP"

Shell script question

Q: At the end of a script type "DEL %0" What will happen?

A: The script is self deleting!

Image WebLinks

find or follow me @