NetUserSetInfo() not working on some computers
up vote
-1
down vote
favorite
What im trying to achieve is to reset the BAD_PW_COUNT variable when a another script attempts to login using the LogonUserA API.
For some reason, compiling this script and running it works fine on my machine(the machine the script was compiled on) but not on other machines(Virtual machines). When running the executable, it either always crashes with a exception code of 0x0005(i assume its related to permissions/access denied) or System Error 87. These errors even persists when the executable is ran through a administrative Command prompt and even through PSEXEC running as SYSTEM.
#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "netapi32.lib")
#include <windows.h>
#include <stdio.h>
#include <assert.h>
#include <lm.h>
#include <sddl.h> /* for ConvertSidToStringSid function */
int wmain(int argc, wchar_t * argv)
{
DWORD dwLevel = 0;
NET_API_STATUS nStatus;
if (argc != 3)
{
fwprintf(stderr, L"Usage: %s \\ServerName UserNamen", argv[0]);
exit(1);
}
dwLevel = 2;
USER_INFO_2 ui;
ui.usri2_bad_pw_count = UF_SCRIPT | UF_LOCKOUT;
nStatus = NetUserSetInfo(NULL,
argv[2],
dwLevel,
(LPBYTE)&ui,
NULL);
if (nStatus == NERR_PasswordTooShort)
fwprintf(stderr, L"User account %s has been disabledn", argv[2]);
else
fprintf(stderr, "A system error has occurred: %dn", nStatus);
return 0;
}
Any help or guidance is greatly appreciated!. Im sort of new to C++ and Windows API in general as i usually dont deal with this sort of field.
c++ c windows winapi
add a comment |
up vote
-1
down vote
favorite
What im trying to achieve is to reset the BAD_PW_COUNT variable when a another script attempts to login using the LogonUserA API.
For some reason, compiling this script and running it works fine on my machine(the machine the script was compiled on) but not on other machines(Virtual machines). When running the executable, it either always crashes with a exception code of 0x0005(i assume its related to permissions/access denied) or System Error 87. These errors even persists when the executable is ran through a administrative Command prompt and even through PSEXEC running as SYSTEM.
#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "netapi32.lib")
#include <windows.h>
#include <stdio.h>
#include <assert.h>
#include <lm.h>
#include <sddl.h> /* for ConvertSidToStringSid function */
int wmain(int argc, wchar_t * argv)
{
DWORD dwLevel = 0;
NET_API_STATUS nStatus;
if (argc != 3)
{
fwprintf(stderr, L"Usage: %s \\ServerName UserNamen", argv[0]);
exit(1);
}
dwLevel = 2;
USER_INFO_2 ui;
ui.usri2_bad_pw_count = UF_SCRIPT | UF_LOCKOUT;
nStatus = NetUserSetInfo(NULL,
argv[2],
dwLevel,
(LPBYTE)&ui,
NULL);
if (nStatus == NERR_PasswordTooShort)
fwprintf(stderr, L"User account %s has been disabledn", argv[2]);
else
fprintf(stderr, "A system error has occurred: %dn", nStatus);
return 0;
}
Any help or guidance is greatly appreciated!. Im sort of new to C++ and Windows API in general as i usually dont deal with this sort of field.
c++ c windows winapi
There's nothing in the code you show that is specific to C++, it could be all plain C. And please don't use multiple language tags, only the one you actually are programming in (which in this case could be eitherc
orc++
). C and C++ are two very different languages really. And please read about how to ask good questions, as well as this question checklist.
– Some programmer dude
Nov 22 at 14:21
Error 5 tells you that the account does not have access to that machine. Like System. Error 87 tells you that the USER_INFO_2 struct is not initialized correctly. Use={}
to zero-initialize it and provide required field values, like usri2_priv. The last argument of NetUserSetInfo can tell which field is bad.
– Hans Passant
Nov 22 at 14:32
1
Just as a complete aside: the example on the NetUserSetInfo does exactly what you're asking to do. Trying to do this, using aUSER_INFO_2
structure requires callingNetUserGetInfo
first, to populate the current values.
– Petesh
Nov 22 at 14:35
0x0005
is not an (SEH) exception code. If it crashes, the most common reason is an access violation, with code0xC0000005
. Using an uninitialized variable (ui
) that contains pointers can certainly cause an access violation.
– IInspectable
Nov 22 at 21:47
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
What im trying to achieve is to reset the BAD_PW_COUNT variable when a another script attempts to login using the LogonUserA API.
For some reason, compiling this script and running it works fine on my machine(the machine the script was compiled on) but not on other machines(Virtual machines). When running the executable, it either always crashes with a exception code of 0x0005(i assume its related to permissions/access denied) or System Error 87. These errors even persists when the executable is ran through a administrative Command prompt and even through PSEXEC running as SYSTEM.
#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "netapi32.lib")
#include <windows.h>
#include <stdio.h>
#include <assert.h>
#include <lm.h>
#include <sddl.h> /* for ConvertSidToStringSid function */
int wmain(int argc, wchar_t * argv)
{
DWORD dwLevel = 0;
NET_API_STATUS nStatus;
if (argc != 3)
{
fwprintf(stderr, L"Usage: %s \\ServerName UserNamen", argv[0]);
exit(1);
}
dwLevel = 2;
USER_INFO_2 ui;
ui.usri2_bad_pw_count = UF_SCRIPT | UF_LOCKOUT;
nStatus = NetUserSetInfo(NULL,
argv[2],
dwLevel,
(LPBYTE)&ui,
NULL);
if (nStatus == NERR_PasswordTooShort)
fwprintf(stderr, L"User account %s has been disabledn", argv[2]);
else
fprintf(stderr, "A system error has occurred: %dn", nStatus);
return 0;
}
Any help or guidance is greatly appreciated!. Im sort of new to C++ and Windows API in general as i usually dont deal with this sort of field.
c++ c windows winapi
What im trying to achieve is to reset the BAD_PW_COUNT variable when a another script attempts to login using the LogonUserA API.
For some reason, compiling this script and running it works fine on my machine(the machine the script was compiled on) but not on other machines(Virtual machines). When running the executable, it either always crashes with a exception code of 0x0005(i assume its related to permissions/access denied) or System Error 87. These errors even persists when the executable is ran through a administrative Command prompt and even through PSEXEC running as SYSTEM.
#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "netapi32.lib")
#include <windows.h>
#include <stdio.h>
#include <assert.h>
#include <lm.h>
#include <sddl.h> /* for ConvertSidToStringSid function */
int wmain(int argc, wchar_t * argv)
{
DWORD dwLevel = 0;
NET_API_STATUS nStatus;
if (argc != 3)
{
fwprintf(stderr, L"Usage: %s \\ServerName UserNamen", argv[0]);
exit(1);
}
dwLevel = 2;
USER_INFO_2 ui;
ui.usri2_bad_pw_count = UF_SCRIPT | UF_LOCKOUT;
nStatus = NetUserSetInfo(NULL,
argv[2],
dwLevel,
(LPBYTE)&ui,
NULL);
if (nStatus == NERR_PasswordTooShort)
fwprintf(stderr, L"User account %s has been disabledn", argv[2]);
else
fprintf(stderr, "A system error has occurred: %dn", nStatus);
return 0;
}
Any help or guidance is greatly appreciated!. Im sort of new to C++ and Windows API in general as i usually dont deal with this sort of field.
c++ c windows winapi
c++ c windows winapi
edited Nov 22 at 14:20
Some programmer dude
293k24243403
293k24243403
asked Nov 22 at 14:18
nikki
43
43
There's nothing in the code you show that is specific to C++, it could be all plain C. And please don't use multiple language tags, only the one you actually are programming in (which in this case could be eitherc
orc++
). C and C++ are two very different languages really. And please read about how to ask good questions, as well as this question checklist.
– Some programmer dude
Nov 22 at 14:21
Error 5 tells you that the account does not have access to that machine. Like System. Error 87 tells you that the USER_INFO_2 struct is not initialized correctly. Use={}
to zero-initialize it and provide required field values, like usri2_priv. The last argument of NetUserSetInfo can tell which field is bad.
– Hans Passant
Nov 22 at 14:32
1
Just as a complete aside: the example on the NetUserSetInfo does exactly what you're asking to do. Trying to do this, using aUSER_INFO_2
structure requires callingNetUserGetInfo
first, to populate the current values.
– Petesh
Nov 22 at 14:35
0x0005
is not an (SEH) exception code. If it crashes, the most common reason is an access violation, with code0xC0000005
. Using an uninitialized variable (ui
) that contains pointers can certainly cause an access violation.
– IInspectable
Nov 22 at 21:47
add a comment |
There's nothing in the code you show that is specific to C++, it could be all plain C. And please don't use multiple language tags, only the one you actually are programming in (which in this case could be eitherc
orc++
). C and C++ are two very different languages really. And please read about how to ask good questions, as well as this question checklist.
– Some programmer dude
Nov 22 at 14:21
Error 5 tells you that the account does not have access to that machine. Like System. Error 87 tells you that the USER_INFO_2 struct is not initialized correctly. Use={}
to zero-initialize it and provide required field values, like usri2_priv. The last argument of NetUserSetInfo can tell which field is bad.
– Hans Passant
Nov 22 at 14:32
1
Just as a complete aside: the example on the NetUserSetInfo does exactly what you're asking to do. Trying to do this, using aUSER_INFO_2
structure requires callingNetUserGetInfo
first, to populate the current values.
– Petesh
Nov 22 at 14:35
0x0005
is not an (SEH) exception code. If it crashes, the most common reason is an access violation, with code0xC0000005
. Using an uninitialized variable (ui
) that contains pointers can certainly cause an access violation.
– IInspectable
Nov 22 at 21:47
There's nothing in the code you show that is specific to C++, it could be all plain C. And please don't use multiple language tags, only the one you actually are programming in (which in this case could be either
c
or c++
). C and C++ are two very different languages really. And please read about how to ask good questions, as well as this question checklist.– Some programmer dude
Nov 22 at 14:21
There's nothing in the code you show that is specific to C++, it could be all plain C. And please don't use multiple language tags, only the one you actually are programming in (which in this case could be either
c
or c++
). C and C++ are two very different languages really. And please read about how to ask good questions, as well as this question checklist.– Some programmer dude
Nov 22 at 14:21
Error 5 tells you that the account does not have access to that machine. Like System. Error 87 tells you that the USER_INFO_2 struct is not initialized correctly. Use
={}
to zero-initialize it and provide required field values, like usri2_priv. The last argument of NetUserSetInfo can tell which field is bad.– Hans Passant
Nov 22 at 14:32
Error 5 tells you that the account does not have access to that machine. Like System. Error 87 tells you that the USER_INFO_2 struct is not initialized correctly. Use
={}
to zero-initialize it and provide required field values, like usri2_priv. The last argument of NetUserSetInfo can tell which field is bad.– Hans Passant
Nov 22 at 14:32
1
1
Just as a complete aside: the example on the NetUserSetInfo does exactly what you're asking to do. Trying to do this, using a
USER_INFO_2
structure requires calling NetUserGetInfo
first, to populate the current values.– Petesh
Nov 22 at 14:35
Just as a complete aside: the example on the NetUserSetInfo does exactly what you're asking to do. Trying to do this, using a
USER_INFO_2
structure requires calling NetUserGetInfo
first, to populate the current values.– Petesh
Nov 22 at 14:35
0x0005
is not an (SEH) exception code. If it crashes, the most common reason is an access violation, with code 0xC0000005
. Using an uninitialized variable (ui
) that contains pointers can certainly cause an access violation.– IInspectable
Nov 22 at 21:47
0x0005
is not an (SEH) exception code. If it crashes, the most common reason is an access violation, with code 0xC0000005
. Using an uninitialized variable (ui
) that contains pointers can certainly cause an access violation.– IInspectable
Nov 22 at 21:47
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432933%2fnetusersetinfo-not-working-on-some-computers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
There's nothing in the code you show that is specific to C++, it could be all plain C. And please don't use multiple language tags, only the one you actually are programming in (which in this case could be either
c
orc++
). C and C++ are two very different languages really. And please read about how to ask good questions, as well as this question checklist.– Some programmer dude
Nov 22 at 14:21
Error 5 tells you that the account does not have access to that machine. Like System. Error 87 tells you that the USER_INFO_2 struct is not initialized correctly. Use
={}
to zero-initialize it and provide required field values, like usri2_priv. The last argument of NetUserSetInfo can tell which field is bad.– Hans Passant
Nov 22 at 14:32
1
Just as a complete aside: the example on the NetUserSetInfo does exactly what you're asking to do. Trying to do this, using a
USER_INFO_2
structure requires callingNetUserGetInfo
first, to populate the current values.– Petesh
Nov 22 at 14:35
0x0005
is not an (SEH) exception code. If it crashes, the most common reason is an access violation, with code0xC0000005
. Using an uninitialized variable (ui
) that contains pointers can certainly cause an access violation.– IInspectable
Nov 22 at 21:47