This question already has answers here:
Windows batch os version check with if support
(3 answers)
Script to check Windows version and then do action on only version 10.0 (2016 or greater)
(3 answers)
Detect Windows version and run command according to version
(1 answer)
Windows 9x/Me version in variable
(1 answer)
Closed 15 days ago.
I want to make a Batch file program, that can is compatible with Windows 10 and later. Not with older Windows systems.
Pseudocode:
if Win10+ then
[insert continued code here]
else
echo We're sorry, but the program you are trying to run isn't compatible with your Windows OS version.
echo Minimal requirement: Windows 10 (or later)
Please comment with the code if you have it.
I tried:
if "%version%" == "10.0" [continue the code]
else echo Not compatible
Perhaps your batch-file could use powershell's help:
#%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile "If ($([System.Environment]::OSVersion.Version.Major) -GE '10') { Exit 0 } Else { Exit 1 }"
#If ErrorLevel 1 Exit /B
#Rem Your Win10+ code goes here.
Related
This question already has answers here:
Display all environment variables from a running PowerShell script
(10 answers)
How to print environment variables to the console in PowerShell?
(5 answers)
Closed 4 months ago.
When entering echo path on PowerShell on my Windows 11, nothing proper is showing up.
I recall Windows 10 shows all environmental path variables, but not anymore?
ECHO %PATH% returns the value of the PATH environment variable when run in cmd.exe, but not PowerShell.
The PowerShell command you're looking for is as follows:
$env:PATH
If you need to list all environment variables in PowerShell, use gci env:. The equivalent command for cmd.exe is SET.
Please see this Stack Overflow post for more information.
Thanks to #mklement0 for the clarification.
This question already has answers here:
What are the PowerShell equivalents of Bash's && and || operators?
(4 answers)
Is there a powershell pattern for if($?) { }
(2 answers)
Can I get "&&" or "-and" to work in PowerShell?
(13 answers)
Closed 1 year ago.
Using the command below, I am able to get the value of a group policy setting:
secedit.exe /export /cfg C:\test\secedit.txt && type C:\test\secedit.txt | findstr "SeEnableDelegationPrivilege"
I need to be able to use the same command on PowerShell and I am having issues converting the && statement to work on PowerShell. I tried using this format () -and (), however, that has not worked, does anyone know a way of getting the && statement to work on PS?
If you want to emulate what that command is doing in PowerShell just change the && for a ;:
secedit.exe /export /cfg C:\test\secedit.txt; type C:\test\secedit.txt | findstr "SeEnableDelegationPrivilege"
I would add 1>$null after the first command to avoid the output of The task has completed successfully.....
Edit
I understand ; and && or || are not the same thing in PS 5.1 and below, but is the closest thing I can imagine to emulate what OP is doing.
Other thing he could attempt is:
secedit.exe /export /cfg C:\test\secedit.txt;if($?){type C:\test\secedit.txt | findstr "SeEnableDelegationPrivilege"}
I would link this helpful answer which explains it better than I do.
This question already has answers here:
How do I get the result of a command in a variable in windows? [duplicate]
(13 answers)
Closed 3 years ago.
I want to use result of one command in the next command line. Is there any way to do it? preferably in one line. For e.g.
1st: where svn;
2nd: explorer {{result_from_first_cmd}}.
I tried explorer where svn. Evidently didn't work.
Use a FOR loop. Yeah, it's crazy. It's Windows.
FOR /F "delims=" %%A IN ('where svn') DO (explorer "%%~A")
Which operating system are you using? Usually you can pipe outputs of one comman line tool to the next one using the | (pipe) operator.
This question already has answers here:
#ARGV is empty using ActivePerl in Windows 7
(4 answers)
Closed 9 years ago.
I recently switched from Windows XP to Win7.
Win7 does not pass command line arguments to to the #ARGV array in perl programs. There was no such problem with XP.
Can anyone suggest a fix for this problem?
The did get Win7 to associate the .pl extension with perl.exe
I suspect it has something to do with HKEY_CLASSES_ROOT.pl and HKEY_CLASSES_ROOT\Applications\perl.exe, but I don't know how to set them.
Call the script with the perl interpreter included perl blah.pl asdf and not blah.pl asdf as Windows will treat both differently in the newer versions
Check this question for more information and hope it helps as I have not used Windoz in so long.
I don't seem to be able to duplicate the problem.
I'm running Active Perl 5.18 on Windows 7, and both command forms give the same output. Can you give an example of input, command, and results?
argv.pl:
foreach (0 .. $#ARGV)
{ print "$_ ", $ARGV[$_], "\n"
}
.
C:\Perl64\Programs>argv a b c
0 a
1 b
2 c
.
C:\Perl64\Programs>perl argv.pl a b c
0 a
1 b
2 c
This question already has answers here:
How do I get the application exit code from a Windows command line?
(7 answers)
Closed 9 years ago.
print exit code in cmd in windows os ....some command return exit code ...where this code store...and i want to print this exit code and assign it to variable
You can use %ERRORLEVEL% environment variable, it will hold the last code that was returned. You can echo it or assign it to a variable, depending on your needs.