Windows XP

Aus Doku-Wiki
Zur Navigation springenZur Suche springen

Netzwerk

IP-Stack reparieren

netsh int ip reset <c:\PATH\DATEI.IP.LOG>

Scripts

Befehle

msconfig

Lokales Login-Script

Ähnlich wie bei einer Domänenumgebung, können auch unter Windows XP in einer Arbeitsgruppe
lokale Loginscripte angelegt werden. Mit diesen Scripten können dann Netzlaufwerke Verbunden werden.

  • Netlogon Freigabe anlegen
  • Der Ordner mit den Loginscripten kann ganz nach eigenem belieben im Dateisystem angelegt werden
  • Dieser Ordner wird dann als netlogon freigegeben.
  • Rechte: Freigebe - Jeder esen | Dateisystem - Jeder lesen, ausführen, auflisten
  • In dem Netlogon-Ordner können nun die Scripte für die einzelnen Benutzer abgelegt werden
  • Nun noch das Loginscript im Benutzerprofil eingetragen.
    • Start - Systemsteuerung - Verwaltung - Computerverwaltung - Lokale Benutzer und Gruppen - Benutzer
    • Doppelklick auf einen Benutzer - Register Profile
    • Im Eingabefeld Anmeldescript wird das Loginscript (Nur Scriptname ohne Pfad) angegeben

Scriptanweisungen

:: Beispile

:: Abfrage nach dem Computernamen
::--------------------------------
 IF /I %COMPUTERNAME%==XP1 goto end

:: Abfrage nach dem Benutzernamen und Ausführen von Befehlen
::------------------------------------------------------------
 goto %USERNAME%
 ;[BENUTZERNAME]
 net use h: \\XP1\[FREIGABE]			/persistent:NO >NUL

:: Befehl mit bedingung
::----------------------
 IF %standort%==55 net use v: \\XP1\Daten$	/persistent:NO >NUL

:: Netzlaufwerke loeschen
::-----------------------
net use * /delete /YES

:: IP herausfinden
::----------------
for /f "Tokens=2 Delims=[]" %%i in ('ping -n 1 -4 %computername%') do (
set ip=%%i
)

:: IP Zerlegen und Vergleichvariable anlegen
::--------------------------------------------

for /f "Tokens=1-5 Delims=." %%i in ('echo %ip%') do (
set ipp1=%%i
set ipp2=%%j
set ipp3=%%k
set ipp4=%%l
)
set standort=%ipp3%

:: ECHO Ausgaben
::--------------
echo Benutzer = %USERNAME%
echo Standort = %Standort%
echo PC       = %COMPUTERNAME%
echo off
 
:: Zeitabgleich mit Zeitserver DC1
::------------------------------------
 net time \\dc1 /set /yes

:: Weiter Scripte aurufen
::-----------------------
 call [PFAD]\Script.cmd

:: Sprungmarke
::-------------
 goto ALL
 :ALL

::-------------
 pause  # Erzeugt eingabeaufforderung
 exit   # Beendet das Script

net use [{Gerätename | *}] [{\\Computername[\Freigabename[\Volume]]] |[http://Computername/Freigabename[/Ordner]}] \
[{Kennwort | *}]]      [/user:[Domänenname\]Benutzername] [/user:[punktierter_Domänenname\]Benutzername] \
[/user: [Benutzername@punktierter_Domänenname] [/savecred] [/smartcard] [{/delete | /persistent:{yes | no}}]

Environment Variables

Links

Education Environment Variables in Windows XP

  • Table I. Some more common predefined environment variables
%ALLUSERSPROFILE% C:\Documents and Settings\All Users 
%APPDATA% C:\Documents and Settings\{username}\Application Data 
%COMPUTERNAME% {computername} 
%COMSPEC% C:\Windows\System32\cmd.exe 
%HOMEDRIVE% C: 
%HOMEPATH% \Documents and Settings\{username} 
%PATH% C:\Windows\System32\;C:\Windows\;C:\Windows\System32\Wbem 
%PATHEXT% .COM; .EXE; .BAT; .CMD; .VBS; .VBE; .JS ; .WSF; .WSH  
%PROGRAMFILES% Directory containing program files, usually C:\Program Files  
%PROMPT% Code for current command prompt format. Code is usually $P$G  
%SYSTEMDRIVE% The drive containing the Windows XP root directory, usually C:  
%SYSTEMROOT% The Windows XP root directory, usually C:\Windows  
%TEMP% and %TMP% C:\DOCUME~1\{username}\LOCALS~1\Temp 
%USERNAME% {username} 
%USERPROFILE% C:\Documents and Settings\{username} 
%WINDIR% C:\Windows 

The so-called predefined variables are generally unchanged during a login session but there are also some dynamic variables whose value may change. Some of these are listed in the next table.

  • Table II. Some dynamic environment variables Variable Value
%DATE% Current date in the format determined by the Date command 
%TIME% Current time in the format determined by the Time command 
%CD% Current directory with its full path  
%ERRORLEVEL% Number defining exit status of a previous command or program 
%RANDOM% Random number between 0 and 32767  

Environment variables are very convenient in scripts where certain standard directories and parameters need to be referenced but where the actual locations or names can vary from computer to computer.(Note that the presence of spaces in some names may necessitate the use of enclosing quotation marks around environment variables in scripts.) By having a placeholder, no prior knowledge is required of such details as the exact location of Windows or who is logged in. Some possibilities are explored in the following sections.

  • The PATH Environment Variable

The path to a file is basically its address on the computer. It tells programs how to find a file. It is the drive plus any directories and sub-directories where the file is located. The %PATH% environment variable specifies the command search path. Typically, this is a group of directories where executable files that are repeatedly used are to be found. Examples of the default values are listed in the first table above; in this case, they are the Windows directory and two of its important system sub-directories. To see what is in the PATH variable on a computer, open a command window and enter "echo %PATH%".
The PATH variable is not immutable and programs like Norton SystemWorks will stick themselves into PATH when they are installed. The PC user can also modify the contents using methods discussed further on. Adding directories to PATH can be very useful if you use scripts or the command line for system maintenance. For example, it can be convenient to put the directory where you keep backups into the PATH variable. It can also be useful to modify PATH if you put programs in a directory different from the usual one.
In the command line and in batch files, PATH can be modified by the command

path = dir1;dir2;dir3

This command will create a PATH environment variable consisting of the three directories dir1, dir2, and dir3. Note that the directory names are separated by a semicolon in the command statement. (An alternate form omits the "equals" sign.) This command will replace any previous directories that were in the PATH variable. To add a directory "newdir" to the current path use the statement

path = %PATH%;newdir 

It is essential to remember that any changes that are made in a command window only endure until the window is closed. For permanent changes, use the method discussed in another section. It is also possible to use the command-line executable setx.exe that is contained in the Windows XP Service Pack 2 Support Tools.
Any file that is in a directory listed in the PATH variable can be found or opened by direct reference to the name of the file without having to specify the drive and directories where it is located. This is very handy in scripting and in other ways. For instance, the name of an executable file that is in a directory listed in the PATH variable can be entered into Start-Run to open certain applications (more on this subject here). An example is the executable file for the classic version of the game Solitaire that is generally in the system folder C:\Windows\System32\. The file is sol.exe and its full address with complete path is C:\Windows\System32\sol.exe. Normally this entire string would have to be used in order to reference the Solitaire game. Because its directory is listed in the PATH variable, however, it is sufficient to reference just the file name sol.exe. In fact, because of another environment variable PATHEXT discussed next, simply entering sol into Start-Run is sufficient to open the solitaire game.

  • The PATHEXT Variable

As is explained on other pages, file extensions tell Windows what it is supposed to do with a file. Certain file extensions indicate that the file is executable; that is, the file opens a program or does something. The %PATHEXT% environment variable contains executable file extensions that do not have to be specified for any file in a directory given in the %PATH% variable. The extension .EXE is the most common. Thus the filename sol.exe need only be entered as sol in a command line. If files have the same name but different extensions, the operating system searches in the following order of precedence: .EXE, .COM, .BAT, and .CMD.

  • Adding or Editing Environment Variables

Existing variables can be edited or deleted and new ones can be added in several ways. For temporary changes, the command " Set" can be used in scripts or in a command window. An example is shown below:

set temp=C:\temp

Here, the %TEMP% directory has been changed from the default value. Note that the there must be no spaces on either side of the "equals" sign. Changes made with "Set" disappear when the command window is closed, thus rendering this method fairly uninteresting for the average PC user. A more useful application of "Set" is to list the environment variables. Open a command window and enter "set" to see what the variables are on your system. Those who wish can consult this Microsoft article for more details about "Set".
The same general considerations hold but there are differences in the details of environment variables for Vista. These are discussed at vistaonwindows.com.
A more permanent way to manage environment variables is provided in the System Properties dialog box. Open Control Panel-Performance and Maintenance-System (or right-click on My Computer and choose "Properties"). In the box that opens, click the "Advanced" tab to obtain the dialog box shown below. Next, click the button "Environment Variables".

  • Using the add-on tool Setx.exe

It is not part of the standard Windows XP setup but a command-line tool called setx.exe is included in the Windows XP Service Pack 2 Support Tools. This tool extends the set command so that permanent changes in the environment variables can be made. For example, to add a folder C:\New Folder to the path, the command would be

setx path "%PATH%;C:\New Folder" 


  • Scripts for Listing Environment Variables

The "Set" command can be used in a command prompt together with a redirection to a text file to make a list of the current environment variables. The command might be

set > C:\env_list.txt 

The file name "C:\env_list.txt" can be replaced by any of your choice.
Microsoft also has a VBScript that lists environment variables on this page.
Registry Keys for Environment Variables For those who are experienced with editing the Registry, there is another way to make changes in environment variables. User environment variables are stored in the Registry in the key:

HKEY_CURRENT_USER\Environment


System variables are found in the key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

Note that any environment variable that is in the form that needs to be expanded (for example, %PATH%) must be stored in the registry as a REG_EXPAND_SZ registry value. Editing the Registry is primarily for scripts used by systems administrators and is not recommended for the average PC user.

  • Setting Environment Variables in Autoexec.bat

The file autoexec.bat is a relic from DOS and older versions of Windows but may still be present in some systems. For the most part, Windows XP will ignore any autoexec.bat file but entries defining environment variables will be picked up. Although environment variables can be set in this way, there are probably better ways.

  • Environment variables in Vista

The same general considerations hold but there are differences in the details of environment variables for Vista. These are discussed at vistaonwindows.com.