man kann mit opsi-Bordmitteln relativ leicht der Windows-Umgebungsvariablen "Path" ein weiteres Verzeichnis hinzufügen (http://download.uib.de/opsi4.0/doc/html ... y-commands).
Aber wie kann man bei der Deinstallation dieses Verzeichnis wieder entfernen?
Ich habe versucht, die einzelnen Einträge von "Path" in einer Stringliste abzulegen, aus dieser Stringliste den neuen Wert für "Path" zusammenzusetzen und dann in die Registry zu schreiben:
Code: Alles auswählen
[Actions]
setloglevel=7
DefVar $dir_to_remove$
DefVar $path$
DefVar $path_before$
DefStringList $dirs_in_path$
set $dir_to_remove$="C:\Test"
set $path$ = GetRegistryStringValue("[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment] Path")
set $path_before$ = $path$
set $dirs_in_path$ = splitString($path$, ";")
set $path$ = ""
for %s% in $dirs_in_path$ do sub_handle_one_dir
registry_write_path
comment "old Path: >" + $path_before$ + "<"
comment "new Path: >" + $path$ + "<"
; only reboot if "Path" was changed
if not (lower($path$) = lower($path_before$))
ExitWindows /Reboot
endif
[sub_handle_one_dir]
if not (lower("%s%") = lower($dir_to_remove$))
if ($path$ = "")
set $path$ = "%s%"
else
set $path$ = $path$ + ";" + "%s%"
endif
endif
[registry_write_path]
openkey [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]
set "Path"=REG_EXPAND_SZ:"$path$"
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Test;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
Nachdem ich mein Skript habe laufen lassen, sieht "Path" so aus:
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;
"C:\Test" wurde korrekt entfernt, aber:
Jedes "%SystemRoot%" wurde vom opsi-Winst ersetzt durch "C:\Windows". Das will ich vermeiden. Wie kann ich das tun?
Oder gibt es vielleicht sowieso eine viel einfachere Möglichkeit, nicht mehr benötigte Verzeichnisse aus "Path" zu entfernen?
Vielen Dank!
Holger
P. S.: Hier noch das zugehörige Log:
Code: Alles auswählen
[5] [Apr 10 12:01:24:545] --
[5] [Apr 10 12:01:24:546] --
[1] [Apr 10 12:01:24:547] opsi-winst 4.11.3.6 started at 10.04.2013 10:48:37
[1] [Apr 10 12:01:24:549]
[1] [Apr 10 12:01:24:550] ============ Version 4.11.3.6 WIN32 script "C:\Users\[...]\Desktop\opsi-python27\CLIENT_DATA\reduce_path.ins"
[1] [Apr 10 12:01:24:552] start: 2013-04-10 12:01:24
[1] [Apr 10 12:01:24:553] on client named "[...]"
[1] [Apr 10 12:01:24:555] loggedin user "[...]"
[1] [Apr 10 12:01:24:557] winst running as "[...]"
[1] [Apr 10 12:01:24:558] winst running with admin privileges
[1] [Apr 10 12:01:24:559] winst running in standard script mode
[1] [Apr 10 12:01:24:559] executing: "C:\Program Files (x86)\opsi.org\opsi-client-agent\opsi-winst\winst32.exe"
[1] [Apr 10 12:01:24:560] system infos:
[1] [Apr 10 12:01:24:561] [...] - PC hardware address
[1] [Apr 10 12:01:24:562] [...].[...].DE - IP name
[1] [Apr 10 12:01:24:563] [...] - IP address
[1] [Apr 10 12:01:24:564] DEU - System default locale
[1] [Apr 10 12:01:24:565] MS Windowds 6.1 64 Bit
[1] [Apr 10 12:01:24:566]
[6] [Apr 10 12:01:24:567] Registry key [HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion] opened
[6] [Apr 10 12:01:24:568] Key closed
[1] [Apr 10 12:01:24:624] LogLevel was 6
[1] [Apr 10 12:01:24:625] LogLevel set to 7
[7] [Apr 10 12:01:24:626]
[7] [Apr 10 12:01:24:627] (created string list $dirs_in_path$)
[5] [Apr 10 12:01:24:627]
[5] [Apr 10 12:01:24:628] Set $dir_to_remove$="C:\Test"
[6] [Apr 10 12:01:24:629] The value of the variable "$dir_to_remove$" is now: "C:\Test"
[5] [Apr 10 12:01:24:631]
[5] [Apr 10 12:01:24:633] Set $path$ = GetRegistryStringValue("[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment] Path")
[7] [Apr 10 12:01:24:636] Registry started with redirection (32 Bit)
[6] [Apr 10 12:01:24:637] Registry key [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment] opened
[6] [Apr 10 12:01:24:639] Key closed
[6] [Apr 10 12:01:24:641] The value of the variable "$path$" is now: "%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Test;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\"
[5] [Apr 10 12:01:24:644]
[5] [Apr 10 12:01:24:646] Set $path_before$ = $path$
[6] [Apr 10 12:01:24:648] The value of the variable "$path_before$" is now: "%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Test;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\"
[5] [Apr 10 12:01:24:650]
[5] [Apr 10 12:01:24:653] Set $dirs_in_path$ = splitString($path$, ";")
[6] [Apr 10 12:01:24:655] retrieving strings from splitString [switch to loglevel 7 for debugging]
[7] [Apr 10 12:01:24:657] (string 0)%SystemRoot%\system32
[7] [Apr 10 12:01:24:659] (string 1)%SystemRoot%
[7] [Apr 10 12:01:24:661] (string 2)%SystemRoot%\System32\Wbem
[7] [Apr 10 12:01:24:663] (string 3)C:\Test
[7] [Apr 10 12:01:24:665] (string 4)%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
[7] [Apr 10 12:01:24:667]
[5] [Apr 10 12:01:24:669]
[5] [Apr 10 12:01:24:671] Set $path$ = ""
[6] [Apr 10 12:01:24:673] The value of the variable "$path$" is now: ""
[6] [Apr 10 12:01:24:675] retrieving strings from $dirs_in_path$ [switch to loglevel 7 for debugging]
[7] [Apr 10 12:01:24:677] (string 0)%SystemRoot%\system32
[7] [Apr 10 12:01:24:679] (string 1)%SystemRoot%
[7] [Apr 10 12:01:24:681] (string 2)%SystemRoot%\System32\Wbem
[7] [Apr 10 12:01:24:683] (string 3)C:\Test
[7] [Apr 10 12:01:24:685] (string 4)%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
[7] [Apr 10 12:01:24:687]
[6] [Apr 10 12:01:24:689]
[6] [Apr 10 12:01:24:690] ~~~~~~ Looping through: '%SystemRoot%\system32', '%SystemRoot%', '%SystemRoot%\System32\Wbem', 'C:\Test', '%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
[6] [Apr 10 12:01:24:692]
[6] [Apr 10 12:01:24:694] ~~~~~~~ Start Sub ~~~~~~~ sub_handle_one_dir
[5] [Apr 10 12:01:24:696]
[5] [Apr 10 12:01:24:698] If
[5] [Apr 10 12:01:24:700] lower("C:\Windows\system32") = lower($dir_to_remove$) <<< result false
[5] [Apr 10 12:01:24:702] not (lower("C:\Windows\system32") = lower($dir_to_remove$)) <<< result true
[5] [Apr 10 12:01:24:704] Then
[5] [Apr 10 12:01:24:706]
[5] [Apr 10 12:01:24:708] If
[5] [Apr 10 12:01:24:710] $path$ = "" <<< result true
[5] [Apr 10 12:01:24:712] ($path$ = "") <<< result true
[5] [Apr 10 12:01:24:714] Then
[5] [Apr 10 12:01:24:716]
[5] [Apr 10 12:01:24:718] Set $path$ = "C:\Windows\system32"
[6] [Apr 10 12:01:24:720] The value of the variable "$path$" is now: "C:\Windows\system32"
[5] [Apr 10 12:01:24:722]
[5] [Apr 10 12:01:24:724] Else
[5] [Apr 10 12:01:24:726] EndIf
[5] [Apr 10 12:01:24:728] EndIf
[6] [Apr 10 12:01:24:730]
[6] [Apr 10 12:01:24:731] ~~~~~~~ End Sub ~~~~~~~ sub_handle_one_dir
[6] [Apr 10 12:01:24:733]
[6] [Apr 10 12:01:24:735]
[6] [Apr 10 12:01:24:737] ~~~~~~~ Start Sub ~~~~~~~ sub_handle_one_dir
[5] [Apr 10 12:01:24:739]
[5] [Apr 10 12:01:24:741] If
[5] [Apr 10 12:01:24:743] lower("C:\Windows") = lower($dir_to_remove$) <<< result false
[5] [Apr 10 12:01:24:745] not (lower("C:\Windows") = lower($dir_to_remove$)) <<< result true
[5] [Apr 10 12:01:24:746] Then
[5] [Apr 10 12:01:24:748]
[5] [Apr 10 12:01:24:750] If
[5] [Apr 10 12:01:24:753] $path$ = "" <<< result false
[5] [Apr 10 12:01:24:754] ($path$ = "") <<< result false
[5] [Apr 10 12:01:24:756] Then
[5] [Apr 10 12:01:24:758]
[5] [Apr 10 12:01:24:759] Else
[5] [Apr 10 12:01:24:761]
[5] [Apr 10 12:01:24:763] Set $path$ = $path$ + ";" + "C:\Windows"
[6] [Apr 10 12:01:24:765] The value of the variable "$path$" is now: "C:\Windows\system32;C:\Windows"
[5] [Apr 10 12:01:24:767] EndIf
[5] [Apr 10 12:01:24:769] EndIf
[6] [Apr 10 12:01:24:771]
[6] [Apr 10 12:01:24:772] ~~~~~~~ End Sub ~~~~~~~ sub_handle_one_dir
[6] [Apr 10 12:01:24:774]
[6] [Apr 10 12:01:24:776]
[6] [Apr 10 12:01:24:777] ~~~~~~~ Start Sub ~~~~~~~ sub_handle_one_dir
[5] [Apr 10 12:01:24:779]
[5] [Apr 10 12:01:24:781] If
[5] [Apr 10 12:01:24:783] lower("C:\Windows\System32\Wbem") = lower($dir_to_remove$) <<< result false
[5] [Apr 10 12:01:24:784] not (lower("C:\Windows\System32\Wbem") = lower($dir_to_remove$)) <<< result true
[5] [Apr 10 12:01:24:786] Then
[5] [Apr 10 12:01:24:788]
[5] [Apr 10 12:01:24:790] If
[5] [Apr 10 12:01:24:792] $path$ = "" <<< result false
[5] [Apr 10 12:01:24:793] ($path$ = "") <<< result false
[5] [Apr 10 12:01:24:795] Then
[5] [Apr 10 12:01:24:797]
[5] [Apr 10 12:01:24:798] Else
[5] [Apr 10 12:01:24:800]
[5] [Apr 10 12:01:24:802] Set $path$ = $path$ + ";" + "C:\Windows\System32\Wbem"
[6] [Apr 10 12:01:24:804] The value of the variable "$path$" is now: "C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem"
[5] [Apr 10 12:01:24:806] EndIf
[5] [Apr 10 12:01:24:808] EndIf
[6] [Apr 10 12:01:24:810]
[6] [Apr 10 12:01:24:811] ~~~~~~~ End Sub ~~~~~~~ sub_handle_one_dir
[6] [Apr 10 12:01:24:813]
[6] [Apr 10 12:01:24:815]
[6] [Apr 10 12:01:24:817] ~~~~~~~ Start Sub ~~~~~~~ sub_handle_one_dir
[5] [Apr 10 12:01:24:819]
[5] [Apr 10 12:01:24:820] If
[5] [Apr 10 12:01:24:823] lower("C:\Test") = lower($dir_to_remove$) <<< result true
[5] [Apr 10 12:01:24:824] not (lower("C:\Test") = lower($dir_to_remove$)) <<< result false
[5] [Apr 10 12:01:24:826] Then
[5] [Apr 10 12:01:24:828]
[5] [Apr 10 12:01:24:830] If
[5] [Apr 10 12:01:24:832] Then
[5] [Apr 10 12:01:24:834]
[5] [Apr 10 12:01:24:836] Else
[5] [Apr 10 12:01:24:838] EndIf
[5] [Apr 10 12:01:24:840] EndIf
[6] [Apr 10 12:01:24:841]
[6] [Apr 10 12:01:24:843] ~~~~~~~ End Sub ~~~~~~~ sub_handle_one_dir
[6] [Apr 10 12:01:24:845]
[6] [Apr 10 12:01:24:847]
[6] [Apr 10 12:01:24:848] ~~~~~~~ Start Sub ~~~~~~~ sub_handle_one_dir
[5] [Apr 10 12:01:24:850]
[5] [Apr 10 12:01:24:852] If
[5] [Apr 10 12:01:24:854] lower("C:\Windows\System32\WindowsPowerShell\v1.0\") = lower($dir_to_remove$) <<< result false
[5] [Apr 10 12:01:24:856] not (lower("C:\Windows\System32\WindowsPowerShell\v1.0\") = lower($dir_to_remove$)) <<< result true
[5] [Apr 10 12:01:24:858] Then
[5] [Apr 10 12:01:24:860]
[5] [Apr 10 12:01:24:862] If
[5] [Apr 10 12:01:24:864] $path$ = "" <<< result false
[5] [Apr 10 12:01:24:865] ($path$ = "") <<< result false
[5] [Apr 10 12:01:24:867] Then
[5] [Apr 10 12:01:24:869]
[5] [Apr 10 12:01:24:871] Else
[5] [Apr 10 12:01:24:873]
[5] [Apr 10 12:01:24:875] Set $path$ = $path$ + ";" + "C:\Windows\System32\WindowsPowerShell\v1.0\"
[6] [Apr 10 12:01:24:877] The value of the variable "$path$" is now: "C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\"
[5] [Apr 10 12:01:24:879] EndIf
[5] [Apr 10 12:01:24:881] EndIf
[6] [Apr 10 12:01:24:883]
[6] [Apr 10 12:01:24:885] ~~~~~~~ End Sub ~~~~~~~ sub_handle_one_dir
[6] [Apr 10 12:01:24:887]
[6] [Apr 10 12:01:24:889]
[6] [Apr 10 12:01:24:890] ~~~~~~ End Loop
[5] [Apr 10 12:01:24:892]
[5] [Apr 10 12:01:24:894] Execution of registry_write_path
[7] [Apr 10 12:01:24:896] Registry started with redirection (32 Bit)
[7] [Apr 10 12:01:24:898] Key is: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
[7] [Apr 10 12:01:24:900] Key0 is: HKEY_LOCAL_MACHINE
[6] [Apr 10 12:01:24:902] Registry key [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment] opened
[6] [Apr 10 12:01:24:904] Variable "Path" had value "%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Test;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\"
[6] [Apr 10 12:01:24:906] Info: "Path" changed to "C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\"
[6] [Apr 10 12:01:24:908] Key closed
[5] [Apr 10 12:01:24:911] comment: old Path: >%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Test;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\<
[5] [Apr 10 12:01:24:913] comment: new Path: >C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\<
[5] [Apr 10 12:01:24:915]
[5] [Apr 10 12:01:24:917] If
[5] [Apr 10 12:01:24:919] lower($path$) = lower($path_before$) <<< result false
[5] [Apr 10 12:01:24:921] not (lower($path$) = lower($path_before$)) <<< result true
[5] [Apr 10 12:01:24:923] Then
[5] [Apr 10 12:01:24:926]
[5] [Apr 10 12:01:24:932] ExitWindows set to Reboot
[5] [Apr 10 12:01:24:934] EndIf
[1] [Apr 10 12:01:24:941] ___________________
[1] [Apr 10 12:01:24:943] script finished
[1] [Apr 10 12:01:24:945] 0 errors
[1] [Apr 10 12:01:24:947] 0 warnings
[1] [Apr 10 12:01:24:949]
[1] [Apr 10 12:01:24:950]
[6] [Apr 10 12:01:24:952] Delete "c:\opsi.org\tmp\_winstbat_*"
[6] [Apr 10 12:01:24:955] Search "c:\opsi.org\tmp\"