[英]My script work perfectly on my computer, but not on another computer
Well, this is my batch
script: 好吧,这是我的
batch
脚本:
@ECHO OFF
if not "%Minimizado%"=="" goto :Rodando
set Minimizado=true
start /min cmd /C "%~dpnx0"
goto :EOF
:Rodando
Ping www.google.nl -n 1 -w 1000
if errorlevel 1 (set internet=Nao Conectado) else (set internet=Conectado)
if %internet% == "Nao Conectado" (GOTO Rodando)
echo class Program { public static void Main() { >"%~dpn0.cs" echo using (var wc = new System.Net.WebClient()) { >>"%~dpn0.cs" echo wc.UseDefaultCredentials = true; >>"%~dpn0.cs" echo wc.DownloadFile(@"http://download.microsoft.com/download/1/1/7/117FB25C-BB2D-41E1-B01E-0FEB0BC72C30/WindowsServer2003-KB968930-x86-ENG.exe", @"%~dpn0.installer.exe");}}} >>"%~dpn0.cs" "%systemroot%\microsoft.net\framework\v3.5\csc.exe" /out:"%~dpn0.exe" "%~dpn0.cs" "%~dpn0.exe" "%~dpn0.installer.exe"
powershell.exe -Command "& {if($PSversionTable.PSVersion.Major -ge 3) {Invoke-WebRequest http://download1475.mediafire.com/dgmccvd5felg/cu6x9bzhx3hmz78/Teste.jpg -OutFile %~dpn0.png}}"
del %~dpn0.cs
START %~dpn0.png
First of all, it must run the command prompt
minimized, and thats actually working. 首先,它必须在最小化的情况下运行
command prompt
,这才是切实可行的。 But it also must: 但这还必须:
PowerShell 3.0
is already installed, if don't, download and install it PowerShell 3.0
,如果未安装,请下载并安装 PowerShell
is installed, download an image PowerShell
,下载映像 .cs
file .cs
文件 In my computer the batch runs perfectly, but in any other computer, simply don't work. 在我的计算机上,该批处理运行良好,但是在其他任何计算机上,根本无法正常工作。 Can you guys please tell me whats wrong?
你们能告诉我怎么了吗?
(I don't speak english fluently, so please, forgive-me for any language mistake) (我不会说流利的英语,所以请您原谅我的语言错误)
Try this code: 试试这个代码:
@echo off
if not "%Minimizado%"=="" goto Rodando
set "Minimizado=true"
start /min cmd /C "%~f0"
goto :EOF
:Rodando
%SystemRoot%\System32\ping.exe www.google.nl -n 1 -w 1000
if errorlevel 1 goto Rodando
echo class Program { public static void Main() {>"%~dpn0.cs"
echo using (var wc = new System.Net.WebClient()) {>>"%~dpn0.cs"
echo wc.UseDefaultCredentials = true;>>"%~dpn0.cs"
echo wc.DownloadFile(@"http://download.microsoft.com/download/1/1/7/117FB25C-BB2D-41E1-B01E-0FEB0BC72C30/WindowsServer2003-KB968930-x86-ENG.exe", @"%~dpn0.installer.exe");}}}>>"%~dpn0.cs"
"%systemroot%\microsoft.net\framework\v3.5\csc.exe" /out:"%~dpn0.exe" "%~dpn0.cs"
"%~dpn0.exe"
"%~dpn0.installer.exe"
powershell.exe -Command "& {if($PSversionTable.PSVersion.Major -ge 3) {Invoke-WebRequest http://download1475.mediafire.com/dgmccvd5felg/cu6x9bzhx3hmz78/Teste.jpg -OutFile %~dpn0.png}}"
del "%~dpn0.cs"
start "%~dpn0.png"
The line 线
if %internet% == "Nao Conectado" (GOTO Rodando)
results in a syntax error on execution if value of internet
is Nao Conectado
because of space in value and no double quotes used on left side of equation condition. 如果
internet
值为Nao Conectado
导致执行时出现语法错误,这是因为值的空间Nao Conectado
,并且方程式条件的左侧未使用双引号。 And even with value Conectado
the condition is always FALSE as a string without double quotes is compared case-sensitive with a string with double quotes. 即使使用值
Conectado
,条件也始终为FALSE,因为将不带双引号的字符串与区分大小写的字符串与带双引号的字符串进行比较。
And use always set "variable=value"
for the reasons explained in answer on 并使用始终
set "variable=value"
的原因是因为
Why is no string output with 'echo %var%' after using 'set var = text' on command line? 为什么在命令行上使用'set var = text'后没有显示'echo%var%'的字符串?
On the last two lines double quotes are added as path to batch file could contain 1 or more spaces. 最后两行添加双引号,因为批处理文件的路径可能包含1个或多个空格。
I have not checked the block creating the *.cs file, running installer and running PowerShell script. 我尚未检查创建* .cs文件,运行安装程序和运行PowerShell脚本的块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.