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 ConResPuts(StdOut
, IDS_GENERIC_SYNTAX
);
53 PrintNetMessage(MSG_COMPUTER_SYNTAX
);
57 if (_wcsicmp(argv
[i
], L
"/help") == 0)
59 /* Print full help text*/
60 ConResPuts(StdOut
, IDS_GENERIC_SYNTAX
);
61 PrintNetMessage(MSG_COMPUTER_SYNTAX
);
62 PrintNetMessage(MSG_COMPUTER_HELP
);
66 if (_wcsicmp(argv
[i
], L
"/add") == 0)
71 else if (_wcsicmp(argv
[i
], L
"/del") == 0)
78 PrintErrorMessage(3506/*, argv[i]*/);
83 if (pComputerName
== NULL
||
84 (bAdd
== FALSE
&& bDelete
== FALSE
) ||
85 (bAdd
== TRUE
&& bDelete
== TRUE
))
87 ConResPuts(StdOut
, IDS_GENERIC_SYNTAX
);
88 PrintNetMessage(MSG_COMPUTER_SYNTAX
);
93 * Create the computer account name:
94 * Skip the leading '\\' and appand a '$'.
96 wcscpy(ComputerAccountName
, &pComputerName
[2]);
97 wcscat(ComputerAccountName
, L
"$");
102 * Create the computer password:
103 * Skip the leading '\\', shorten to a maximum of 14 characters
104 * and convert to lower case
106 wcsncpy(ComputerPassword
, &pComputerName
[2], LM20_PWLEN
);
107 ComputerPassword
[LM20_PWLEN
] = UNICODE_NULL
;
108 _wcslwr(ComputerPassword
);
110 /* Set the account data */
111 UserInfo
.usri1_name
= ComputerAccountName
;
112 UserInfo
.usri1_password
= ComputerPassword
;
113 UserInfo
.usri1_password_age
= 0;
114 UserInfo
.usri1_priv
= USER_PRIV_USER
;
115 UserInfo
.usri1_home_dir
= NULL
;
116 UserInfo
.usri1_comment
= NULL
;
117 UserInfo
.usri1_flags
= UF_SCRIPT
| UF_WORKSTATION_TRUST_ACCOUNT
;
118 UserInfo
.usri1_script_path
= NULL
;
120 /* Add the computer account */
121 Status
= NetUserAdd(NULL
,
128 /* Delete the coputer account */
129 Status
= NetUserDel(NULL
,
130 ComputerAccountName
);
133 if (Status
== NERR_Success
)
135 PrintErrorMessage(ERROR_SUCCESS
);
139 PrintErrorMessage(Status
);