【问题标题】:How to access Password Protected Shared folder through PowerBuilder如何通过 PowerBuilder 访问受密码保护的共享文件夹
【发布时间】:2014-04-04 01:18:49
【问题描述】:

如何通过 PowerBuilder 代码访问受密码保护的网络共享文件夹? 有什么选择吗?

我使用的是 PowerBuilder 11.5

谢谢 安巴特

【问题讨论】:

    标签: powerbuilder


    【解决方案1】:

    这是一个我已经隐藏起来的代码片段。我不确定来源,所以我不能给予适当的信任。

    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 
    

    【讨论】:

    • 感谢您的回复,上面给出的解决方案已经尝试过了。从这些东西中,只有 net use 命令有效。但有时它不起作用。是否有任何永久解决方案。
    猜你喜欢
    • 2011-06-07
    • 1970-01-01
    • 2012-02-12
    • 2019-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-16
    • 1970-01-01
    相关资源
    最近更新 更多