Jump to content

Feature request: remove need for workstations service


Recommended Posts

Posted

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.org
SET HostOS=Unknown
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 "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)
)

  • 2 months later...

Posted

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!

Posted
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.

Posted

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 HostOS
    This will indicate an unknown or non-NT based OS
  • NT 3.51
  • NT 4.0
  • 2000
  • XP
  • 2003
  • Vista
    This will be returned for Windows Vista or 2008

I hope it comes in useful to those of you requiring it!

NTOS.zip

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...