opsys, err := wmi.QueryTable(`root\cimv2`, `select CSName,Version,Caption,CSDVersion from Win32_OperatingSystem`)
** Copyright (C) 2001-2025 Zabbix SIA
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"golang.org/x/sys/windows"
"golang.zabbix.com/agent2/pkg/wmi"
func getHostname(params []string) (uname string, err error) {
return "", errors.New("Too many parameters.")
var mode, transform string
w := make([]uint16, windows.MAX_COMPUTERNAME_LENGTH+1)
if err = syscall.GetComputerName(&w[0], &sz); err != nil {
uname = windows.UTF16ToString(w)
if uname, err = os.Hostname(); err != nil {
if uname, err = os.Hostname(); err != nil {
if idx := strings.Index(uname, "."); idx > 0 {
return "", errors.New("Invalid first parameter.")
uname = strings.ToLower(uname)
return "", errors.New("Invalid second parameter.")