如何通过PowerBuilder代码访问受密码保护的网络共享文件夹? 有没有选择?
我正在使用PowerBuilder 11.5
由于 Ambat
答案 0 :(得分:0)
这是我松了一口气的代码片段。我不确定消息来源,所以我不能给予适当的信任。
FUNCTION long ShellExecuteW &
(long hwnd, string lpOperation, &
string lpFile, string lpParameters, string lpDirectory, &
integer nShowCmd ) LIBRARY "shell32"
string ls_Null
long ll_rc
SetNull(ls_Null)
ll_rc = ShellExecuteW &
( handle( this ), "open", as_path, ls_Null, ls_Null, 1)
RETURN ll_rc
How about run("net use ...")
where net use syntax is :
NET USE [devicename | *] [\\computername\sharename[\volume] [password | *]]
[/USER:[domainname\]username]
[[/DELETE] | [/PERSISTENT:{YES | NO}]]
__________________________________________________________________
DWORD WNetCancelConnection2(
_In_ LPCTSTR lpName, (string)
_In_ DWORD dwFlags, (ulong)
_In_ BOOL fForce
);
DWORD dwResult;
dwResult = WNetCancelConnection2("z:",
CONNECT_UPDATE_PROFILE, // remove connection from profile (use 1)
FALSE); // fail if open files or jobs
DWORD WNetUseConnection(
_In_ HWND hwndOwner,
_In_ LPNETRESOURCE lpNetResource,
_In_ LPCTSTR lpPassword,
_In_ LPCTSTR lpUserID,
_In_ DWORD dwFlags,
_Out_ LPTSTR lpAccessName,
_Inout_ LPDWORD lpBufferSize,
_Out_ LPDWORD lpResult
);
Function Declaration:
FUNCTION ulong WNetUseConnectionA (ulong hwndOwner, &
REF s_netresource lpNetResource, string lpPassword,
string lpUsername, ulong dwFlags, REF string lpAccessName, &
REF ulong lpBufferSize, REF ulong lpResult) library "mpr.dll"
Structure Definition:
$PBExportHeader$s_netresource.srs
global type s_netresource from structure
unsignedlong dwScope
unsignedlong dwType
unsignedlong dwDisplayType
unsignedlong dwUsage
string lpLocalName
string lpRemoteName
string lpComment
string lpProvider
end type
Mapping Code:
CONSTANT ulong NO_ERROR = 0
CONSTANT ulong CONNECT_REDIRECT = 128
CONSTANT ulong RESOURCETYPE_DISK = 1
s_netresource lstr_netresource
String ls_null
String ls_buffer
String ls_MappedDrive
uLong ll_bufferlen
uLong ll_null
uLong ll_ErrInfo
uLong ll_success
SetNull(ll_null)
SetNull(ls_null)
ls_buffer = Space(32)
ll_bufferlen = Len(ls_buffer)
lstr_netresource.dwType = RESOURCETYPE_DISK
lstr_netresource.lpLocalName = ls_null
lstr_netresource.lpRemoteName = "UNC resource name here"
lstr_netresource.lpProvider = ls_null
ll_ErrInfo = WNetUseConnectionA(ll_null, lstr_netresource, &
'password', 'username', &
CONNECT_REDIRECT, ls_buffer, ll_bufferlen, ll_success)
IF ll_ErrInfo = NO_ERROR THEN
MessageBox("Drive Mapped", "Drive Letter is " + ls_buffer)
Return 1
ELSE
MessageBox("Mapping Falied", "Error is " + String(ll_ErrInfo))
Return -1
END IF
-------------------- disconnect drive
DWORD WNetCancelConnection2(
_In_ LPCTSTR lpName,
_In_ DWORD dwFlags,
_In_ BOOL fForce
);
DWORD dwResult;
dwResult = WNetCancelConnection2("z:",
CONNECT_UPDATE_PROFILE, // remove connection from profile (use 1)
FALSE); // fail if open files or jobs