Dumpy Dooby Posted September 20, 2009 Share Posted September 20, 2009 (edited) I don't understand the point of your Call command. That seems superfluous. How come you do it like that instead of just using "Set HostOs=%%a" ?I've revised mine per your recommendation of using Caption instead of Name. Works better because it doesn't have that nasty pipe.FOR /f "tokens=*" %A in ('wmic os get caption^, version /format:list') Do Set %A@Echo %Caption% [%Version%] Edited September 20, 2009 by Dumpy Dooby Link to comment Share on other sites More sharing options...
strel Posted September 20, 2009 Share Posted September 20, 2009 (edited) Yzöwl.Your method based on NET seemed to be rock solid, I mean HKLM\Software\Microsoft\Windows NT\Current Version values could have been modified, and your method don't rely on that, isn't it?I'm going to use it to substitute the poor VER based one in Silent .NET Maker synthesized.Thx a lot. Edited September 20, 2009 by strel Link to comment Share on other sites More sharing options...
Yzöwl Posted September 20, 2009 Share Posted September 20, 2009 I don't understand the point of your Call command. That seems superfluous. How come you do it like that instead of just using "Set HostOs=%%a" ?The wmic output invariably includes unwanted and unrequired trailing character(s)!Try @Echo [%Caption%] to see what I mean.I've revised mine<snip>.FOR /f "tokens=*" %A in ('wmic os get caption^, version /format:list') Do Set %A@Echo %Caption% [%Version%]Regardless of the fact that this is no longer a one-liner, the fact that you've not excluded the trailing characterthe fact that you appear to be working in a console as opposed to a CMD script, Here's a screen recording for you to download, of your script fixed to run and pause from a batch on a Vista x86 box.Here's the script it runs, Dumpys.cmd@For /F "tokens=*" %%A In ('Wmic Os Get Caption^, Version /Format:list') Do @Set %%A@Echo %Caption% [%Version%]@PauseObviously the unwanted output can be removed like this:@Set %%A>Nulbut you can see why using Set %%A isn't a good idea.Now correcting that and ignoring the unwanted trailing character, I'm going to allow the echoing of the set command to show you something else.@For /F "tokens=*" %%A In ('Wmic Os Get Caption^, Version /Format:list') Do Set %%A>Nul@Echo %Caption% [%Version%]@PauseYou should see that the set command is being run several times not just on the version and caption lines.I hope that explains to you why I suggested that method and why less can sometimes be more.My responses are based upon running the examples on Windows 7 and Vista machinesYou will also note in all these wmi based cases that there is a problem outputting the ™ symbol. Link to comment Share on other sites More sharing options...
ckislam Posted December 31, 2009 Share Posted December 31, 2009 (edited) found a a fatat error in the net config work method which leads to identify the windows version as 7 although it is xp.this error is caused as the net config work has the following output NetBT_Tcpip_{08BD6D91-B894-4FE6-B4EF-077A49EBBA77} (00242C01B83F)As you see the number 7 is available in the tcpip value which leads the find command to have an exitcode 0 EDIT: sorry it was my fault i used find "7" instead of "Windows 7" Edited January 1, 2010 by ckislam Link to comment Share on other sites More sharing options...
strel Posted December 31, 2009 Share Posted December 31, 2009 I finally discard to use it because, contrary to what I thought initially, this service is not strictly necessary unless you use SMB networks, and also it could happen the service is down ocassionally for some reason or for accident. Link to comment Share on other sites More sharing options...
Yzöwl Posted January 1, 2010 Share Posted January 1, 2010 The workstation service is on, (Automatic), by default. There's little chance of it being 'down occasionally' during an unattended install!If the Workstation service is disabled, a system cannot connect to shared file or print resources on a network.The following services, (which are required to access resources on a network and to perform domain authentication), depend on the Workstation service: Alerter Browser Messenger Net Logon RPC LocatorThe Microsoft Baseline Security Analyzer will not function if the Workstation service is disabled. It is possible that other applications may also require the Workstation service.It is the decision of the reader here as to whether or not they disable a particualr service, (especially this early in the install). However, in doing so, they should understand that they may lose functionality required by something else; this is an example of that lost functionality.It is therefore up to that person to use a workaround; this could simply be checking for the running service in the first instance and if stopped, start it. Link to comment Share on other sites More sharing options...
Phred Posted January 11, 2010 Share Posted January 11, 2010 Hi Yzöwl,At the moment I'm having the test fail (in hfslip-1.7.9.cmd). Workstation Service status is Started, Startup is Automatic. XP SP2.FOR /F "DELIMS=" %%I IN ('NET CONFIG WORK^|FIND /I " Windows "') DO ( ECHO %%I|FIND "2000">NUL 2>&1&&(SET HostOS=2000&GOTO :HOSD) ECHO %%I|FIND "2002">NUL 2>&1&&(SET HostOS=XP&GOTO :HOSD) ECHO %%I|FIND "XP">NUL 2>&1&&(SET HostOS=XP&GOTO :HOSD) ECHO %%I|FIND "2003">NUL 2>&1&&(SET HostOS=2003&GOTO :HOSD) ECHO %%I|FIND /I "Vista">NUL 2>&1&&(SET HostOS=Vista&GOTO :HOSD))I get - "FIND: Windows : No such file or directory"Any ideas why this might be??TIA for your help.Phred Link to comment Share on other sites More sharing options...
jaclaz Posted January 11, 2010 Share Posted January 11, 2010 Any ideas why this might be??Open a command prompt and run in it:NET CONFIG WORKwhat happens?jaclaz Link to comment Share on other sites More sharing options...
Phred Posted January 11, 2010 Share Posted January 11, 2010 Hi jaclaz,NET CONFIG WORK does return the expected output. So why wasn't " Windows " found in the text I asked myself?Long story short - testing discovered that FINDSTR worked but FIND didn't. PATH had a ATMEL utility (WIN AVR) directory in it that contained a FIND command - obviously not one that works like DOS FIND. Yzöwl's code works just fine using the correct FIND command.. Phred Link to comment Share on other sites More sharing options...
jaclaz Posted January 11, 2010 Share Posted January 11, 2010 Long story short - testing discovered that FINDSTR worked but FIND didn't. PATH had a ATMEL utility (WIN AVR) directory in it that contained a FIND command - obviously not one that works like DOS FIND. Yzöwl's code works just fine using the correct FIND command.. Just in case, WHICH:http://www.paulsadowski.com/wsh/cmdprogs.htmhttp://unxutils.sourceforge.net/jaclaz Link to comment Share on other sites More sharing options...
ckislam Posted January 11, 2010 Share Posted January 11, 2010 I use this short form and it works fine:FOR %%i in (2000 2002 2003 Vista 2008 7) DO NET CONFIG WORK|Find "Windows %%i">Nul 2>&1&&(Set HostOS=%%i&IF "%%i"=="2002" SET HostOS=XP) Link to comment Share on other sites More sharing options...
cluberti Posted January 16, 2010 Share Posted January 16, 2010 To the OP, if this is going to get complicated you might want to migrate from a CMD to a vbscript - certain things are easier to grep and act on, and the environment is a bit more powerful. Link to comment Share on other sites More sharing options...
Yzöwl Posted January 16, 2010 Share Posted January 16, 2010 I use this short form and it works fine:FOR %%i in (2000 2002 2003 Vista 2008 7) DO NET CONFIG WORK|Find "Windows %%i">Nul 2>&1&&(Set HostOS=%%i&IF "%%i"=="2002" SET HostOS=XP)If that works for you then fine, however it will cause problems for others.Unfortunately those using a server based OS have an output containing, for example:Windows Server 2003 not your required:Windows 2003 Server Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now