这是一个修改本机administrator密码的程序,我希望修改不成功,能够弹出一个框,提示一下!
现在无论是修改成功还是不成功,它都跳出修改不成功。
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  NET_API_STATUS = DWORD;
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Button2: TButton;
    Edit1: TEdit;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;
  APIStatus:NET_API_STATUS; //返回值implementation{$R *.dfm}
//改用户密码
function NetUserChangePassword(domainname:PWideChar;username:pwidechar;oldpassword:pwidechar;newpassword:pwidechar):LongInt;stdcall; external 'netapi32.dll';procedure TForm1.Button1Click(Sender: TObject);
begin
try
  APIStatus:=NetUserChangePassword(nil,'Administrator',StringToOleStr(edit1.text),'a');
  if (APIStatus = NERR_Success) then
  begin
    Label1.Caption:=TCaption('初始化成功,请重新启动电脑!');
    //Label1.Color:=;
    Label1.Font.Color:=clRed ;
  end
  else
  begin
     ShowMessage('错误,修改不成功');
  end
  //ShowMessage('kdkdk');
except
  ShowMessage('kdkdk');
end;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
Close();
end;end.

解决方案 »

  1.   

    我只是想将公司里的administrator密码统一,方便我们远程装杀毒软件。另:NERR_Success  怎么定义?
      

  2.   

    这里是一段VC代码,希望你能看懂:#ifndef UNICODE
    #define UNICODE
    #endif#include <stdio.h>
    #include <assert.h>
    #include <windows.h> 
    #include <lm.h>#pragma comment(lib, "Netapi32.lib")int wmain(int argc, wchar_t *argv[])
    {
    LPSESSION_INFO_10 pBuf = NULL;
    LPSESSION_INFO_10 pTmpBuf;
    DWORD dwLevel = 10;
    DWORD dwPrefMaxLen = -1;
    DWORD dwEntriesRead = 0;
    DWORD dwTotalEntries = 0;
    DWORD dwResumeHandle = 0;
    DWORD i;
    DWORD dwTotalCount = 0;
    LPTSTR pszServerName = NULL;
    LPTSTR pszClientName = NULL;
    LPTSTR pszUserName = NULL;
    NET_API_STATUS nStatus;
    //
    // Check command line arguments.
    //
    if (argc > 4)
    {
    wprintf(L"Usage: %s [\\\\ServerName] [\\\\ClientName] [UserName]\n", argv[0]);
    exit(1);
    }if (argc >= 2)
    pszServerName = argv[1];if (argc >= 3)
    pszClientName = argv[2];if (argc == 4)
    pszUserName = argv[3];
    //
    // Call the NetSessionEnum function, specifying level 10.
    //
    do // begin do

    nStatus = NetSessionEnum(pszServerName,
    pszClientName,
    pszUserName,
    dwLevel,
    (LPBYTE*)&pBuf,
    dwPrefMaxLen,
    &dwEntriesRead,
    &dwTotalEntries,
    &dwResumeHandle);
    //
    // If the call succeeds,
    //
    if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
    {
    if ((pTmpBuf = pBuf) != NULL)
    {
    //
    // Loop through the entries.
    //
    for (i = 0; (i < dwEntriesRead); i++)
    {
    NET_API_STATUS nRetVal = 0;
    TCHAR sz[100] = L"";
    assert(pTmpBuf != NULL);if (pTmpBuf == NULL)
    {
    fprintf(stderr, "An access violation has occurred\n");
    break;
    }
    //
    // Print the retrieved data. 
    //
    wprintf(L"\n\tClient: %s\n", pTmpBuf->sesi10_cname);
    wprintf(L"\tUser: %s\n", pTmpBuf->sesi10_username);
    wprintf(L"\tActive: %d\n", pTmpBuf->sesi10_time);
    wprintf(L"\tIdle: %d\n", pTmpBuf->sesi10_idle_time);
    wsprintf(sz, L"\\\\%s", pTmpBuf->sesi10_cname);
    nRetVal = NetSessionDel(NULL, sz, NULL);
    if ( nRetVal != NERR_Success )
    {
    wprintf(L"\tKicking him..: Error #%d\n", GetLastError());
    }
    else
    {
    wprintf(L"\tI kicked his a**! :-)\n");
    }pTmpBuf++;
    dwTotalCount++;
    }
    }
    }
    //
    // Otherwise, indicate a system error.
    //
    else
    fprintf(stderr, "A system error has occurred: %d\n", nStatus);
    //
    // Free the allocated memory.
    //
    if (pBuf != NULL)
    {
    NetApiBufferFree(pBuf);
    pBuf = NULL;
    }
    }
    // 
    // Continue to call NetSessionEnum while 
    // there are more entries. 
    // 
    while (nStatus == ERROR_MORE_DATA); // end do// Check again for an allocated buffer.
    //
    if (pBuf != NULL)
    NetApiBufferFree(pBuf);
    //
    // Print the final count of sessions enumerated.
    //
    fprintf(stderr, "\nTotal of %d entries enumerated\n", dwTotalCount);return 0;
    }If I pass only the username via the third parameter it also worked like a charm./"mike" is the name of my second PC I used for testing
      

  3.   

    NERR_Success来自于NetSessionEnum(pszServerName,pszClientName,pszUserName,dwLevel,(LPBYTE*)&pBuf,dwPrefMaxLen,&dwEntriesRead,&dwTotalEntries,&dwResumeHandle)的一个枚举值.
      

  4.   

    报的什么错误?
    先看看你的系统目录下有没有netapi32.dll这个dll
      

  5.   

    抱歉,好像还是有点错误,说“NERR_Success”没有定义,我也不知道这个东西应该怎样声明啊