WNetAddConnection2函数参数问题(30分)

L

liujzi

Unregistered / Unconfirmed
GUEST, unregistred user!
这个函数的第一个参数该怎么写,是个structure结构的,大虾给我举个例子吧,谢谢![8D][:(!]
DWORD WNetAddConnection2(

LPNETRESOURCE lpNetResource, // points to structure that specifies connection details
LPCTSTR lpPassword, // points to password string
LPCTSTR lpUsername, // points to user name string
DWORD dwFlags // set of bit flags that specify connection options
);
 
procedure TForm1.BitBtn1Click(Sender: TObject);
var
aa:TNetResource;
retval : integer;
begin
aa.dwScope := RESOURCE_CONNECTED;
aa.dwType := RESOURCETYPE_ANY;
aa.lpLocalName := 'h:';
aa.lpRemoteName := '//1.1.1.1/share';
aa.lpProvider := Nil;
RetVal := WNetAddConnection2(aa,'pswstr','usrstr',0);
showmessage(inttostr(retval));
end;
 
TO:chenxz,我正在做一个远程关机程序,需要先登录上对方。我想用程序方式以管理员登录,chenxz你能帮我看看下面的程序吗?
注:本地机名:LJZ
对方电脑名:WQW
对方user:administrator PASSWORD:microsoft
谢谢!

procedure AdjustToken();
var
hdlProcessHandle : Cardinal;
hdlTokenHandle : Cardinal;
tmpLuid : Int64;
tkpPrivilegeCount : Int64;
tkp : TOKEN_PRIVILEGES;
tkpNewButIgnored : TOKEN_PRIVILEGES;
lBufferNeeded : Cardinal;
Privilege : array[0..0] of _LUID_AND_ATTRIBUTES;
begin
hdlProcessHandle := GetCurrentProcess;
OpenProcessToken(hdlProcessHandle,
(TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY),
hdlTokenHandle);

// Get the LUID for shutdown privilege.
LookupPrivilegeValue('', 'SeShutdownPrivilege', tmpLuid);
Privilege[0].Luid := tmpLuid;
Privilege[0].Attributes := SE_PRIVILEGE_ENABLED;
tkp.PrivilegeCount := 1; // One privilege to set
tkp.Privileges[0] := Privilege[0];
// Enable the shutdown privilege in the access token of this
// process.
AdjustTokenPrivileges(hdlTokenHandle,
False,
tkp,
Sizeof(tkpNewButIgnored),
tkpNewButIgnored,
lBufferNeeded);

end;
procedure Tserver.Button1Click(Sender: TObject);
var
ReqCode:array[0..29] of char;
ReqCodeStr:string;
aa:TNetResource;
retval : integer;
begin

aa.dwScope := RESOURCE_CONNECTED;
aa.dwType := RESOURCETYPE_ANY;
aa.lpLocalName := 'ljz';
aa.lpRemoteName := 'wqw';
aa.lpProvider := Nil;
RetVal := WNetAddConnection2(aa,'microsoft','administrator',0);
showmessage(inttostr(retval));
AdjustToken;
InitiateSystemshutdown('wqw','HELLO',10,true,true);

end;

 
>>aa.lpLocalName := 'ljz';
lplocalname应该是一个盘符,而不是主机名,如果你不要映射到本地磁盘,这个参数设为
空就可以了,这时的调用等于只是把访问的用户名和密码传过去。访问时用全路径。
 
而且记得你的本地盘符不能是已经存在的盘符。

 
多人接受答案了。
 
顶部