變量我有一些小代碼。問題看起來在下一步程序中,儘管我寫了新的值,但請記住上一次操作的值。在下一步它總是從上一步獲得價值。我嘗試在任務之後或任務之前清理此值,但值始終保持清潔。值集/ p在循環中。在下一步它記住從最後一步
:BEGIN
cls
VER > NUL
echo #-------------------------------------------------#
SET /P PROGRAM=# Wybierz interesujacy cie program:
echo #-------------------------------------------------#
2>NUL CALL :CASE_%PROGRAM%
IF ERRORLEVEL 1 CALL :CASE_DEFAULT
:CASE_6
setlocal enabledelayedexpansion
for %%I in (`powershell.exe`) do if "%%~$PATH:I" neq "" (
set chooser=powershell "Add-Type -AssemblyName System.windows.forms|Out-Null;$f=New-Object System.Windows.Forms.OpenFileDialog;$f.InitialDirectory='%windir%\System32\PSTools';$f.Filter='Executable Files (*.exe)|All Files (*.*)|*.*';$f.showHelp=$true;$f.ShowDialog()|Out-Null;$f.FileName"
) else (
rem :: If not, compose and link C# application to open file browser dialog
set chooser=%temp%\chooser.exe
>"%temp%\c.cs" echo using System;using System.Windows.Forms;
>>"%temp%\c.cs" echo class dummy{
>>"%temp%\c.cs" echo public static void Main^(^){
>>"%temp%\c.cs" echo OpenFileDialog f=new OpenFileDialog^(^);
>>"%temp%\c.cs" echo f.InitialDirectory= "c:\\Windows\\System32\\PSTools\\";
>>"%temp%\c.cs" echo f.Filter="Executable Files (*.exe)|*.exe|All Files (*.*)|*.*";
>>"%temp%\c.cs" echo f.ShowHelp=true;
>>"%temp%\c.cs" echo f.ShowDialog^(^);
>>"%temp%\c.cs" echo Console.Write^(f.FileName^);}}
for /f "delims=" %%I in ('dir /b /s "%windir%\microsoft.net\*csc.exe"') do (
if not exist "!chooser!" "%%I" /nologo /out:"!chooser!" "%temp%\c.cs" 2>NUL
)
del "%temp%\c.cs"
if not exist "!chooser!" (
echo Error: Please install .NET 2.0 or newer, or install PowerShell.
goto :EOF
)
)
:: capture choice to a variable
for /f "delims=" %%I in ('%chooser%') do set "filename=%%I"
:: Clean up the mess
del "%temp%\chooser.exe" 2>NUL
IF "%filename%" == "C:\Windows\System32\PSTools\PsExec.exe" (
SET /P COMPNAME="# Wybierz nazwe komputera:
echo # Podales: %COMPNAME% #
echo #-------------------------------------------------#
pause
START "" %filename% -s \\%COMPNAME% cmd
) ELSE (
echo # Inne narzedzia nie sa jeszcze obslugiwane.
echo # Przepraszam
#-------------------------------------------------#
pause
)
set "COMPNAME="
REM set "COMPNAME=%COMPNAME*=%"
VER > NUL # reset ERRORLEVEL
GOTO BEGIN
如果你不想保存變量(只需輸入set/p),你必須首先初始化變量。 'Set「Program =」&SET/P PROGRAM =#Wybierz interesujacy cie program:' – LotPings