0
如何通過PowerBuilder代碼訪問受密碼保護的網絡共享文件夾? 有什麼不對?如何通過PowerBuilder訪問受密碼保護的共享文件夾
我使用的PowerBuilder 11.5
感謝 Ambat
如何通過PowerBuilder代碼訪問受密碼保護的網絡共享文件夾? 有什麼不對?如何通過PowerBuilder訪問受密碼保護的共享文件夾
我使用的PowerBuilder 11.5
感謝 Ambat
這裏是一個代碼片段我已經藏匿了。我不確定信息來源,所以我不能給予適當的評價。
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
感謝您的回覆,以上給出的解決方案已經嘗試過。從這些東西只有網絡使用命令的作品。但有時它不起作用。有沒有任何透明的解決方案。 –