To change the user password using Script, I wrote a simple exe file using the C API. First compile the code bellow then you can use it from LS by executing it with the shell function.
You can send me a mail at ysabag@iba.co.il and I'll send you the exe.
Put the following code in: ChangePassword.c
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include <errno.h>
#include <lapicinc.h>
#include <lapiplat.h>
#include <osenv.h>
#include <kfm.h>
LAPI_MAIN
{
STATUS error = NOERROR;
char OrigPassword[20];
char NewPassword[20];
char IDFileSpec[MAXENVVALUE+1];
LAPI_INIT(error);
if (error)
LAPI_INIT_ERROR;
if (argc<3)
LAPI_RETURN ("Syntax ChangePassword.exe KeyFileName OrigPassword NewPassword");
if (argc==3)
{
strcpy(OrigPassword, argv[1]);
strcpy(NewPassword, argv[2]);
/* Get the current user's id file path specification */
if (error=!OSGetEnvironmentString ("KeyFileName", IDFileSpec, MAXENVVALUE))
{
printf ("Cannot locate current id file, using NULL for pIDFilen");
LAPI_RETURN (ERR(error));
}
}
else
{
strcpy(IDFileSpec, argv[1]);
strcpy(OrigPassword, argv[2]);
strcpy(NewPassword, argv[3]);
}
if (error = SECKFMChangePassword (IDFileSpec, OrigPassword, NewPassword))
LAPI_RETURN (ERR(error));
}
The Make file :
!include <ntwin32.mak>
# The name of the program.
PROGNAME = ChangePassword
#
# DEC Alpha doesn't want the structures to be packed so we use the CPU
# type to conditionally add it as part of compile string
#
!IF "$(CPU)" == "ALPHA"
cpuflags =
!ELSE
cpuflags = /Zp
!ENDIF
# Dependencies
$(PROGNAME).EXE: $(PROGNAME).OBJ
$(PROGNAME).OBJ: $(PROGNAME).C
# Compilation command.
.C.OBJ:
$(cc) $(cdebug) $(cflags) $(cpuflags) /DNT $(cvars) $*.c
# Link command.
.OBJ.EXE:
$(link) $(linkdebug) $(conflags) -out:$@ $** notes0.obj $(conlibs)
notes.lib user32.lib
This was first published in October 2001