Ask Your Question
0

Macro check if windows or linux [closed]

asked 2016-08-22 17:49:07 +0200

mark_t gravatar image

updated 2020-07-10 22:01:53 +0200

Alex Kemp gravatar image

What is the best way to check in a macro if its running on windows or linux?

I want to modify shell command to work with either bash or cmd.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-07-10 22:02:08.947557

Comments

Similar question is here.

EasyTrieve gravatar imageEasyTrieve ( 2017-05-11 21:21:35 +0200 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2016-08-22 22:42:37 +0200

paul1149 gravatar image

This is from Andrew's OOME:

'Listing 173. Display the GUI type as a string.
Sub DisplayGUIType()
 Dim s As String
 Select Case GetGUIType()
 Case 1
 s = "Windows"
 Case 2
 s = "OS/2" ' Set in the source code, but no longer documented.
 Case 3
 s = "Mac OS" ' Used to be documented, never supported, I expect Mac to return 4.
 Case 4
 s = "UNIX"
 Case Else
 s = "Unknown value " & CStr(GetGUIType()) & CHR$(10) &_
 "Probably running in Client/Server mode"
 End Select
 MsgBox "GUI type is " & s, 0, "GetGUIType()"
End Sub
' The value -1 is returned if the type is not known, but that is not specifically documented. This probably 
'means that you are running in a client / server mode, but, I have not checked that.
edit flag offensive delete link more

Comments

Thanks, GUI type just didn't register when I was looking at the index for OS type.

mark_t gravatar imagemark_t ( 2016-08-22 23:19:07 +0200 )edit
0

answered 2019-05-21 11:26:31 +0200

updated 2019-05-21 14:44:22 +0200

I recommend the following Basic code:

Option Explicit
Sub Main : MsgBox OSName : End Sub

Function OSName As String
    ''' Return platform name as "MAC", "UNIX", "WIN" '''
    With GlobalScope.Basiclibraries
        If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
    End With
    Dim keyNode As Object ' com.sun.star.configuration.ConfigurationAccess'
    keyNode = Tools.Misc.GetRegistryKeyContent("org.openoffice.Office.Common/Help")
    OSName = keyNode.GetByName("System")
    ' inferred from "Tools.UCB.ShowHelperDialog" '
End Function ' (Tools).OSName '

Enjoy !

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-08-22 17:49:07 +0200

Seen: 511 times

Last updated: May 21 '19