这是一个修改本机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.
现在无论是修改成功还是不成功,它都跳出修改不成功。
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.
解决方案 »
- Delphi中如何删除和修改ini文件里的某条记录?
- 怎样使ListView里面的数据能正确排序??
- listbox問題
- 为什么这个强制类型转换不可以?
- 那里下载delphi的Installshield Express
- 怎么改变一个ADOCommand的执行语句阿
- 菜鸟求救:我在一个unit中定义了一个procedure ,怎样在别的unit中也能使用它。赠分100
- 怎样做像超级解霸那样跟窗体共用背景图片的菜单
- 动态库问题----使用delphi 2006 调用低版(delphi 6.0)的DLL时,字符串在Dll里面不全!!(急!!给高分!!)
- Tdump
- 怎样在点击按钮2以后,就能够停止点击按钮1后正在进行的工作?
- fieldbyname +delphi+修改语句
#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
先看看你的系统目录下有没有netapi32.dll这个dll