2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS net command
4 * FILE: base/applications/network/net/cmdComputer.c
5 * PROGRAMMERS: Eric Kohl <eric.kohl@reactos.org>
15 WCHAR ComputerAccountName
[MAX_PATH
+ 2];
16 WCHAR ComputerPassword
[LM20_PWLEN
+ 1];
21 PWSTR pComputerName
= NULL
;
22 NET_API_STATUS Status
= NERR_Success
;
24 OSVERSIONINFOEX VersionInfo;
26 VersionInfo.dwOSVersionInfoSize = sizeof(VersionInfo);
27 if (!GetVersionEx((LPOSVERSIONINFO)&VersionInfo))
29 PrintErrorMessage(GetLastError());
33 if (VersionInfo.wProductType != VER_NT_DOMAIN_CONTROLLER)
35 PrintErrorMessage(3515);
41 if (argc
> 2 && argv
[i
][0] == L
'\\' && argv
[i
][1] == L
'\\')
43 pComputerName
= argv
[i
];
49 if (_wcsicmp(argv
[i
], L
"help") == 0)
51 /* Print short syntax help */
52 PrintMessageString(4381);
53 ConPuts(StdOut
, L
"\n");
54 PrintNetMessage(MSG_COMPUTER_SYNTAX
);
58 if (_wcsicmp(argv
[i
], L
"/help") == 0)
60 /* Print full help text*/
61 PrintMessageString(4381);
62 ConPuts(StdOut
, L
"\n");
63 PrintNetMessage(MSG_COMPUTER_SYNTAX
);
64 PrintNetMessage(MSG_COMPUTER_HELP
);
68 if (_wcsicmp(argv
[i
], L
"/add") == 0)
73 else if (_wcsicmp(argv
[i
], L
"/del") == 0)
80 PrintErrorMessage(3506/*, argv[i]*/);
85 if (pComputerName
== NULL
||
86 (bAdd
== FALSE
&& bDelete
== FALSE
) ||
87 (bAdd
== TRUE
&& bDelete
== TRUE
))
89 PrintMessageString(4381);
90 ConPuts(StdOut
, L
"\n");
91 PrintNetMessage(MSG_COMPUTER_SYNTAX
);
96 * Create the computer account name:
97 * Skip the leading '\\' and appand a '$'.
99 wcscpy(ComputerAccountName
, &pComputerName
[2]);
100 wcscat(ComputerAccountName
, L
"$");
105 * Create the computer password:
106 * Skip the leading '\\', shorten to a maximum of 14 characters
107 * and convert to lower case
109 wcsncpy(ComputerPassword
, &pComputerName
[2], LM20_PWLEN
);
110 ComputerPassword
[LM20_PWLEN
] = UNICODE_NULL
;
111 _wcslwr(ComputerPassword
);
113 /* Set the account data */
114 UserInfo
.usri1_name
= ComputerAccountName
;
115 UserInfo
.usri1_password
= ComputerPassword
;
116 UserInfo
.usri1_password_age
= 0;
117 UserInfo
.usri1_priv
= USER_PRIV_USER
;
118 UserInfo
.usri1_home_dir
= NULL
;
119 UserInfo
.usri1_comment
= NULL
;
120 UserInfo
.usri1_flags
= UF_SCRIPT
| UF_WORKSTATION_TRUST_ACCOUNT
;
121 UserInfo
.usri1_script_path
= NULL
;
123 /* Add the computer account */
124 Status
= NetUserAdd(NULL
,
131 /* Delete the coputer account */
132 Status
= NetUserDel(NULL
,
133 ComputerAccountName
);
136 if (Status
== NERR_Success
)
138 PrintErrorMessage(ERROR_SUCCESS
);
142 PrintErrorMessage(Status
);