Jump to content
MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. ×

Help need with CMD script


Nexus_06
 Share

Recommended Posts

I have several things packaged up for 2k/XP , but now I want to make them work also on Windows7. I have some questions...

For instance, I have a sfx which I created which contains stuff I copy to system32... this pack contains sysinternals tools and some from other sites. It also copies shortcuts and help files to the proper directories.

for my paths I have say...

%windir%\system32\

%windir%\help\

%allusersprofile%\start menu\programs\accessories\system tools\

I know that win7 (and vista) has protection on these folders, how can I take temporary control of them to copy the needed files?

also is there a way I can integrate the scripts into one script, which detects which OS it is being run on, and branch to the different routines if needed?

any help appreciated

Link to comment
Share on other sites

  • 3 weeks later...

one script, which detects which OS it is being run on..

To Detect Windows version from the command line use the VER command, with find and errorlevels you can then redirect your commands

Example for usage:

VER | FIND.exe /i "xp" >NUL
if %errorlevel%==0 ECHO You are using XP..

to identify x86 and x64 CPU, use the variable %processor_architecture%

also see this:

http://support.microsoft.com/kb/556009

I hope this helps

Edited by ckislam
Link to comment
Share on other sites

Nicely put here:

http://ss64.com/nt/ver.html

Bugs

The VER command reports the version of CMD.exe, so if for example you run the Win XP version of CMD under NT 4 then the VER command will return:

Microsoft Windows XP [Version 4.0.1381]

Though I guess that is "good enough" for "normal" use.

I guess the "proper" way is to check the %OS% varaible, than check contents of this Registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion

ProductName

CurrentBuildNumber

CurrentVersion

Should contain all the needed data (that can be compared with the VER results)

jaclaz

Link to comment
Share on other sites

Something like this is what I suppose Yzöwl is talking about.

You mean the thread where Aegis says to check HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion ? :unsure::whistle:

:P

From batch/command line one can use WMIC allright, some examples:

WMIC OS list  /Format:list
WMIC OS list BRIEF /Format:list
WMIC OS get /Format:list
WMIC OS get name, version /Format:list

jaclaz

Edited by jaclaz
Link to comment
Share on other sites

Here's a method I've used which should always work, (unless your crazy enough to have disabled the workstation service)!

ThisOS.cmd

@Echo off&Setlocal enableextensions
For /f "delims=" %%# In ('Net config work^|Find /i " Windows "') Do Call :OSis %%#
If Defined HostOS (Echo Detected OS is Windows %HostOS%) Else (
Echo Host OS not Detected!)
Pause&Goto :Eof
:OSis
Echo %*|Find "2000">Nul 2>&1&&(Set "HostOS=2000"&Goto :Eof)
Echo %*|Find "2002">Nul 2>&1&&(Set "HostOS=XP"&Goto :Eof)
Echo %*|Find "2003">Nul 2>&1&&(Set "HostOS=2003"&Goto :Eof)
Echo %*|Find "Vista">Nul 2>&1&&(Set "HostOS=Vista"&Goto :Eof)
Echo %*|Find "2008">Nul 2>&1&&(Set "HostOS=2008"&Goto :Eof)
Echo %*|Find "7">Nul 2>&1&&(Set "HostOS=7"&Goto :Eof)
(Set HostOS=)

Link to comment
Share on other sites

Technically incorrect, this will detect the version of the Command Interpreter not that of Windows!

May be you should try this:

ver /?

Displays the Windows version

I get this:

at XP: Microsoft Windows XP [Version 5.1.2600]

at 7: Microsoft Windows [Version 6.1.7600]

Also stated at microsoft documentation:

http://www.microsoft.com/resources/documen...r.mspx?mfr=true

Ver

Displays the Windows XP version number.

How did you find out that it detects the command Interpreter version not that windows?!

Funny that microsoft was mistaken :)

Anyhow you know it better than them ;)

Thanks

Link to comment
Share on other sites

It is a fact, VER gives the version of the command interpreter!

Microsoft's documentation assumes that end users will not replace executables with versions from earlier or later Operating Systems, hence they don't produce documentation to cover such an eventuality.

If you wish be proven incorrect, please try swapping XP and Windows 2000 cmd.exe's or even different SP levels of CMD.EXE and run the command in each.

Link to comment
Share on other sites

Here's a method I've used which should always work, (unless your crazy enough to have disabled the workstation service)!

ThisOS.cmd

@Echo off&Setlocal enableextensions
For /f "delims=" %%# In ('Net config work^|Find /i " Windows "') Do Call :OSis %%#
If Defined HostOS (Echo Detected OS is Windows %HostOS%) Else (
Echo Host OS not Detected!)
Pause&Goto :Eof
:OSis
Echo %*|Find "2000">Nul 2>&1&&(Set "HostOS=2000"&Goto :Eof)
Echo %*|Find "2002">Nul 2>&1&&(Set "HostOS=XP"&Goto :Eof)
Echo %*|Find "2003">Nul 2>&1&&(Set "HostOS=2003"&Goto :Eof)
Echo %*|Find "Vista">Nul 2>&1&&(Set "HostOS=Vista"&Goto :Eof)
Echo %*|Find "2008">Nul 2>&1&&(Set "HostOS=2008"&Goto :Eof)
Echo %*|Find "7">Nul 2>&1&&(Set "HostOS=7"&Goto :Eof)
(Set HostOS=)

Make it simple (in one line) :)

FOR %%i in (2000 2002 2003 Vista 2008 7) DO NET CONFIG WORK|Find "%%i">Nul 2>&1&&(Set "HostOS=%%i"&ECHO %HOSTOS%)

Link to comment
Share on other sites

Make it simple (in one line) :)

FOR %%i in (2000 2002 2003 Vista 2008 7) DO NET CONFIG WORK|Find "%%i">Nul 2>&1&&(Set "HostOS=%%i"&ECHO %HOSTOS%)

It would be nice if that worked for all, however I think that expecting, for instance 7, not to appear in any line of the 'net config' output other than the Software version one is asking a little too much! Also outputting 2002 to an XP user may confuse them. The other niggle I'd have is that you will be running the more intensive 'net config' command six times as opposed to one.
Link to comment
Share on other sites

Windows XP Professional

FOR /f %%A in ('wmic os get name^, version /format:list') Do Set %%A

I'm not sure if that will work on Vista or Windows 7. But anyone using either of those should consider upgrading to Windows XP anyway.

Edited by Dumpy Dooby
Link to comment
Share on other sites

If I was to use Wmic for this, I'd probably use this:

@Echo off & Setlocal enableextensions
For /F "tokens=1* delims==" %%a In ('Wmic OS Get Caption /value^|Find "="') Do (
Call :_ %%b)
Echo %%HostOs%%=%HostOs%
Ping -n 6 127.0.0.1 > Nul & Goto :Eof
:_
(Set HostOs=%*)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...