HolgerHops Posted August 9, 2008 Posted August 9, 2008 First I would like to thank you for this great script.On my computer the workstation service is disabled, so the script hangs when it tries to figure out the OS version.Problem lies here::: Find host OS - based on code posted by Yzöwl on MSFN.orgSET HostOS=UnknownFOR /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 "2003">NUL 2>&1&&(SET HostOS=2003&GOTO :HOSD) ECHO %%I|FIND /I "Vista">NUL 2>&1&&(SET HostOS=Vista&GOTO :HOSD))as this code relies on the workstation service to function properly.This Code should do the same, but doesn't rely on the workstation service:FOR /F "DELIMS=" %%I IN ('ver') DO ( ECHO %%I|FIND "2000">NUL 2>&1&&(SET HostOS=2000&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))
Yzöwl Posted October 31, 2008 Posted October 31, 2008 Sorry to add to a topic which has lay here silently for a couple of months but the reason for using that particular method was that VER returns only the version of the command interpreter not the running Operating System!
Tomalak Posted October 31, 2008 Posted October 31, 2008 Sorry to add to a topic which has lay here silently for a couple of months but the reason for using that particular method was that VER returns only the version of the command interpreter not the running Operating System!Hm, for me (German Windows XP Pro) it displays "Microsoft Windows XP [Version 5.1.2600]". So is it possible that someone runs another command interpreter with his OS (let's say the Win 2000 version of cmd.exe with Win XP), misleading the mentioned code to assume the wrong OS? Shouldn't happen on a clean source though...In the end it's just a matter of taste - the wish to have hfslip working even with disable workstation service may also not be that common.
Yzöwl Posted October 31, 2008 Posted October 31, 2008 First thing I'd be interested in is why anyone would see the need to disable that service. By doing so, not only would you be unable to connect to any shared file or print resources on a network you'd also in effect not be able to use several other dependent services. Although I'm sure that some 'extreme home users' may have disabled it, using the batch scripting methods employed with HFSLIP it is still the best command interpreter independent method of determining the OS.My suggestion without deliberately trying to find an alternative solution would be to incorporate a check for the services status first, if it isn't running then choose an alternate course of action to achieve your goal.Net start|Find "Work"As an alternative idea, you could use the attached executable I've created.For /f "delims=" %%# In ('NTOS.exe') Do Set "HostOS=%%#"The possible returned values are:<empty>Best found with If Not Defined HostOSThis will indicate an unknown or non-NT based OSNT 3.51NT 4.02000XP2003VistaThis will be returned for Windows Vista or 2008I hope it comes in useful to those of you requiring it!NTOS.zip
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