ReactOS  0.4.11-dev-946-g431643b
hostname.c
Go to the documentation of this file.
1 /*
2  * ReactOS Win32 Applications
3  * Copyright (C) 2005 ReactOS Team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 /*
20  * COPYRIGHT : See COPYING in the top level directory
21  * PROJECT : ReactOS/Win32 get host name
22  * FILE : subsys/system/hostname/hostname.c
23  * PROGRAMMER: Emanuele Aliberti (ea@reactos.com)
24  */
25 
26 #include <conio.h>
27 
28 #include <windef.h>
29 #include <winbase.h>
30 #include <winuser.h>
31 
32 #include "resource.h"
33 
34 int wmain(int argc, WCHAR* argv[])
35 {
36  WCHAR Msg[100];
37 
38  if (1 == argc)
39  {
40  WCHAR ComputerName[MAX_COMPUTERNAME_LENGTH + 1] = L"";
41  DWORD ComputerNameSize = sizeof(ComputerName) / sizeof(ComputerName[0]);
42 
43  if (!GetComputerName(ComputerName, &ComputerNameSize))
44  {
45  /* Fail in case of error */
47  _cwprintf(L"%s %lu.\n", Msg, GetLastError());
48  return 1;
49  }
50 
51  /* Print out the computer's name */
52  _cwprintf(L"%s\n", ComputerName);
53  }
54  else
55  {
56  if ((wcsicmp(argv[1], L"-s") == 0) || (wcsicmp(argv[1], L"/s") == 0))
57  {
58  /* The program doesn't allow the user to set the computer's name */
60  _cwprintf(L"%s\n", Msg);
61  return 1;
62  }
63  else
64  {
65  /* Let the user know what the program does */
67  _cwprintf(L"\n%s\n\n", Msg);
68  }
69  }
70 
71  return 0;
72 }
73 
74 /* EOF */
static int argc
Definition: ServiceArgs.c:12
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define GetComputerName
Definition: winbase.h:3614
int __cdecl _cwprintf(const MSVCRT_wchar_t *,...)
Definition: _cwprintf.c:14
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define IDS_USAGE
Definition: resource.h:3
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
static char ** argv
Definition: ServiceArgs.c:11
struct @1571 Msg[]
int wmain(int argc, WCHAR *argv[])
Definition: hostname.c:34
smooth NULL
Definition: ftsmooth.c:416
#define IDS_NOSET
Definition: resource.h:4
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1087
#define wcsicmp
Definition: string.h:1152
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:240
#define GetModuleHandle
Definition: winbase.h:3641
#define IDS_ERROR
Definition: resource.h:18