Detect if Windows is running? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Detect if Windows is running?

KDivad LeahcimKDivad Leahcim Posts: 3,948Member
Anyone know how? I can't seem to think of a way to do so since QB/VBDOS don't allow you to collect ERRORLEVEL codes.

Thanks,
KDL

Comments

  • the walrusthe walrus Posts: 249Member
    [b][red]This message was edited by the walrus at 2003-10-10 22:40:42[/red][/b][hr]
    You could have QBasic shell a windows program that would relay whether it had been run or not...

    [b]QBasic example code:[/b]
    [code]
    DIM ff AS LONG, gS AS STRING
    [red]'Check to see if its in the right directory...[/red]
    CLS
    ff = FREEFILE
    OPEN "winask.txt" FOR OUTPUT AS #ff
    PRINT #ff, "Windows is not running"
    CLOSE #ff
    SHELL "winask.exe"
    SLEEP 1
    ff = FREEFILE
    OPEN "winask.txt" FOR INPUT AS #ff
    INPUT #ff, gS
    CLOSE #ff
    PRINT gS
    [/code]

    And if you use Visual Basic to make the Windows app...

    [b]VB code example:[/b]
    [code]
    Private Sub Form_Load()
    Dim ff As Long
    If Right(App.Path, 1) = "" Then
    ff = FreeFile
    Open App.Path + "winask.txt" For Output As #ff
    Else
    ff = FreeFile
    Open App.Path + "winask.txt" For Output As #ff
    End If
    Print #ff, "Windows is running"
    Close #ff
    End
    End Sub
    [/code]


  • the walrusthe walrus Posts: 249Member
    or if you used vb, youd probly just want to use a module with sub main, rather than a form..but you already know that..
  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : or if you used vb, youd probly just want to use a module with sub main, rather than a form..but you already know that..
    :

    Yeah, I knew that.

    I hadn't thought to shell a windows app that makes a change and then see whether or not the change occurred. I'm sure there are all kinds of traditions being broken by that method so I'll have to give it a shot. If nothing else, it's a lot better than the "nothing" that I had thought of before now.

    Thanks!
    KDL
  • Folker FritzFolker Fritz Posts: 19Member
    I have found this in the ABC archives:


    '******************************************************************************
    '* ISWIN.BAS
    '*
    '* This program will determine whether Windows is running and, if so,
    '* its operating mode.
    '* QuickBASIC must be loaded, as follows: QB /L QB
    '*
    '* Translated by Hans Lunsing from ISWIN.C by Andrew Schulman,
    '* February 1993, which you can find on pages 170-172 of
    '*
    '* "Undocumented DOS Second edition, A Programmer's Guide to Reserved
    '* MS-DOS Functions ans Data Structures",
    '* by Andrew Schulman, Ralf Brown, David Maxey, Raymond J. Michels,
    '* and Jim Kyle,
    '* published 1994 by Addison-Wesley Publishing Company,
    '* ISBN 0-201-63287-X
    '******************************************************************************
    DEFINT A-Z
    ' Type for segmented address

    TYPE FarPtr
    Offset AS INTEGER 'offset
    Segment AS INTEGER 'segment
    END TYPE

    DECLARE FUNCTION DetectSwitcher ()
    DECLARE SUB DOSGetVector (Number AS INTEGER, Vector AS FarPtr)
    DECLARE FUNCTION WinGetVM ()
    DECLARE FUNCTION IsWin (Major AS INTEGER, Minor AS INTEGER, Mode AS INTEGER)

    '$INCLUDE: 'Qb.bi' 'Include file for interrupt calls

    CONST FALSE = 0, TRUE = NOT FALSE

    CONST MULTIPLEX = &H2F 'multiplex interrupt number

    'Modes:
    CONST REALmode = 1 'Windows in real mode
    CONST STANDARDmode = 2 'Windows in standard mode
    CONST ENHANCEDmode = 3 'Windows in enhanced mode

    CONST SYSTEMVM = 1 'System Virtual Machine ID

    DIM Major AS INTEGER 'Primary version number
    DIM Minor AS INTEGER 'Secondary version number
    DIM Mode AS INTEGER 'Mode in which Windows is running
    DIM sMode AS STRING 'Mode string
    DIM Version AS STRING 'Version string

    IF NOT IsWin(Major, Minor, Mode) THEN
    PRINT "Windows is not running"
    ELSEIF Major = 2 THEN
    PRINT "Running Windows-386 V 2.x"
    ELSE
    Version = LTRIM$(STR$(Major)) + "." + RIGHT$("0" + LTRIM$(STR$(Minor)), 2)
    SELECT CASE Mode
    CASE 1: sMode = "Real"
    CASE 2: sMode = "Standard"
    CASE 3: sMode = "Enhanced"
    END SELECT
    PRINT "Running Windows "; Version; " (or higher) "; sMode; " mode"
    END IF
    IF Mode = ENHANCEDmode THEN
    ' If the task at hand is running within the System-VM the system must
    ' be some hacked version of Windows like MSDPMI, or the task must be
    ' running inside WINSTART.BAT.
    IF WinGetVM = SYSTEMVM THEN
    PRINT "Running DOS application in System VM:"
    PRINT "Must be WINSTART.BAT or hacked Windows!"
    END IF
    END IF
    END

    FUNCTION DetectSwitcher
    '-----------------------------------------------------------------------
    ' Function returns TRUE if DOSSHELL task switcher is loaded,
    ' and returns FALSE otherwise.
    '-----------------------------------------------------------------------
    DIM R AS RegTypeX
    R.BX = 0
    R.DI = 0
    R.ES = 0
    R.AX = &H4B02
    CALL InterruptX(MULTIPLEX, R, R) 'DOSSHELL 5+ installation check
    DetectSwitcher = (R.ES <> 0 OR R.DI <> 0)
    END FUNCTION

    SUB DOSGetVector (IntNum AS INTEGER, IntVec AS FarPtr)
    '-----------------------------------------------------------------------
    ' Function returns IntVec of interrupt number IntNum as a segmented
    ' address in IntVec.
    ' (It is the same function as MBHANCE's SaveCurrentVec.)
    '-----------------------------------------------------------------------
    DIM R AS RegTypeX
    R.AX = &H3500 OR (IntNum AND &HFF)
    CALL InterruptX(&H21, R, R)
    IntVec.Segment = R.ES
    IntVec.Offset = R.BX
    END SUB

    FUNCTION IsWin (Major AS INTEGER, Minor AS INTEGER, Mode AS INTEGER)
    '-----------------------------------------------------------------------
    ' Tests for Windows. Returns TRUE if running in Windows, and FALSE if
    ' otherwise. Moreover returns version number and mode as parameters.
    '-----------------------------------------------------------------------
    DIM R AS RegTypeX 'Processor registers for interrupt call
    DIM IntVec AS FarPtr

    Major = 0 'Initialize version numbers
    Minor = 0
    Mode = 0 'Initialize mode

    ' Make sure someone, anyone has INT 2Fh

    DOSGetVector &H2F, IntVec
    IF IntVec.Segment = 0 AND IntVec.Offset = 0 THEN
    IsWin = FALSE
    EXIT FUNCTION
    END IF

    'Call MULTIPLEX/160A to see if Windows 3.1+

    R.AX = &H160A
    CALL InterruptX(MULTIPLEX, R, R)
    IF R.AX = 0 THEN 'AX = 0 if Windows running
    Mode = R.CX 'Mode, 2 = Std., 3 = Enhanced
    'Calculation of major version number is
    'OK as long as it is < 128
    Major = R.BX 256 'Major version number
    Minor = R.BX AND 255 'Minor version number
    IsWin = TRUE
    ELSE

    'Call MULTIPLEX/1600 to see if Windows 3.0 Enhanced mode or Windows/386

    R.AX = &H1600
    CALL InterruptX(MULTIPLEX, R, R)
    'Calculation of minor version number is
    'OK as long as it is < 128
    Major = R.AX AND 255 'Major version number
    Minor = R.AX 256 'Minor version number
    SELECT CASE Major
    CASE 1, &HFF 'Windows/386 2.x is running
    Major = 2 'Windows/386 2.x
    Minor = 1 'don't know; assume 1
    Mode = ENHANCEDmode 'Windows/386 sort of like Enhanced
    IsWin = TRUE
    CASE 0, &H80 'AL = 0 or 80h if no Windows

    'Call MULTIPLEX/4680h to see if Windows 3.0 Standard or Real mode;
    'but, this could be a "3.0 derivative" such as DOSSHELL task
    'switcher!

    R.AX = &H4680
    CALL InterruptX(MULTIPLEX, R, R)
    IF R.AX = 0 THEN 'AX = 0 if MULTIPLEX/4680 handled
    'Make sure it isn't DOSSHELL task switcher
    IF DetectSwitcher THEN
    IsWin = FALSE 'DOSSHELL taskswitcher
    ELSE
    Major = 3
    Minor = 0
    'Either have Windows Standard mode or Real mode; to distinguish
    'have to do fake Windows broadcasts with MULTIPLEX/1605h. Yuk!
    'We'll avoid that here by assuming 3.0 Standard mode. If you
    'really want to distinguish 3.0 Standard mode and real mode
    'See Microsoft Systems Journal, March 1991, p. 113; and Micro-
    'soft Knowledge Base articles Q75943 and Q75338.
    Mode = STANDARDmode
    IsWin = TRUE
    END IF
    ELSE
    IsWin = FALSE 'No Windows
    END IF
    CASE ELSE
    'Must be Windows 3.0 Enhanced mode
    Mode = ENHANCEDmode
    IsWin = TRUE
    END SELECT
    END IF

    END FUNCTION

    FUNCTION WinGetVM
    '-----------------------------------------------------------------------
    ' Function returns Virtual machine ID within Windows Enhanced Mode.
    '-----------------------------------------------------------------------
    DIM R AS RegTypeX
    R.AX = &H1683
    CALL InterruptX(MULTIPLEX, R, R) 'Get Virtual Machine ID
    WinGetVM = R.BX
    END FUNCTION

  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : I have found this in the ABC archives:

    Very cool! I'll have to test it later when I have a chance to figure out which library it was that has the interupt capabilities in it, but this is awesome!

    Thanks,
    KDL
  • Folker FritzFolker Fritz Posts: 19Member
    : Very cool! I'll have to test it later when I have a chance to figure out which library it was that has the interupt capabilities in it, but this is awesome!
    :
    : Thanks,
    : KDL

    just start quickbasic with QB /L
  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : just start quickbasic with QB /L
    :

    I actually have a seperate shortcut to do that; I had just forgotten about it.

    Works beautifully, thanks!
Sign In or Register to comment.