Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: wntAddDrive Unicode 499 unrecognized network error 183 WNetAddConnection2W WNetAddConnection2 WNetAddConnection
I have a program that interrogates a directory structure. The code has worked well up to now when I have a directory name that has unicode characters.
I am mapping to a drive letter that isn't used/doesn't exist. The UNC is:
\\ODSSrv2\Projects\EDDTest\EDD\003\Input\DumpDir\אבי פרידמן - אונ' תא - עדכוןThe directory currently exists and I can map it by hand via Windows Explorer.
Does this extender support unicode? If not can/will it?
I don't think wntAddDrive is going to work for you unless you happen to have the Hebrew code page installed on your system. I don't think the 'net use' command is going to be of much help here either.
This all comes down to the NT extender simply needing an overhaul to make it use Unicode end-to-end w/respect to the extender interface and the Win32 API functions that it calls. The middle layer of the extender code itself is where all of the refactoring needs to be done. Even though some of the extender's functions are deprecated, such as the domain sync function, many others are still quite applicable since they involve management of the O.S. itself and not anything in particular involving account management [e.g. NT domains vs. AD domains].
In the interim, you might be able to get something working using DllCall:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; WNetAddConnection2 ;; ;; Description: Unicode approximation of the network extenders 'wntAddDrive' function. ;; ;; Parameters: strNetName - name of network share to map ;; strDrive - name of drive letter including colon ;; strPassword - password of user making connection(can be 0 to use current) ;; strUser - name of user making connection ((can be 0 to use current) ;; bPersist - @True = make mapping persistent :: ;; Return: 0 on success otherwise system error number. ;; ;; Notes: NETRESOURCEW data structure ;; DWORD dwScope ;; DWORD dwType ;; DWORD dwDisplayType ;; DWORD dwUsage ;; LPWSTR lpLocalName ;; LPWSTR lpRemoteName ;; LPWSTR lpComment ;; LPWSTR lpProvider ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #DefineFunction WNetAddConnection2(strNetName, strDrive, strPassword, strUser, bPersist) ; String parameters must be Unicode. strNetName = ChrStringToUnicode(strNetName) strDrive = ChrStringToUnicode(strDrive) If VarType(strPassword) != 1 Then strPassword = ChrStringToUnicode(strPassword) If VarType(strPassword) != 1 Then strUser = ChrStringToUnicode(strUser) hNetRes = BinaryAlloc(32) hNetName = BinaryAlloc(StrByteCount(strNetName, -1)+2) hDrive = BinaryAlloc(StrByteCount(strDrive, -1)+2) BinaryPokeStrW(hNetName, 0, strNetName) BinaryPokeStrW(hDrive, 0, strDrive) pNetName = BinaryBufInfo(hNetName, 1) pDrive = BinaryBufInfo(hDrive, 1) ; Fill NETRESOURCE structure. BinaryPoke4(hNetRes, 0, 0) BinaryPoke4(hNetRes, 4, 1) ; 1 = RESOURCETYPE_DISK BinaryPoke4(hNetRes, 8, 0) BinaryPoke4(hNetRes, 12, 0) BinaryPoke4(hNetRes, 16, pDrive) ; Drive name BinaryPoke4(hNetRes, 20, pNetName) ; Network name BinaryPoke4(hNetRes, 24, 0) BinaryPoke4(hNetRes, 28, 0) ; Set string parameter data types. If VarType(strPassword) == 1 Then pwdType = "long" Else pwdType = "lpwstr" If VarType(strPassword) == 1 Then usrType = "long" Else usrType = "lpwstr" ; Normalize boolean parameter. If bPersist Then bPersist = 1 Else bPersist = 0 nResult = DllCall(DirWindows(1):"Mpr.dll",long:"WNetAddConnection2W",lpbinary:hNetRes,%pwdType%:strPassword,%usrType%:strUser,long:bPersist) If hNetRes Then BinaryFree(hNetRes) If hNetName Then BinaryFree(hNetName) If hDrive Then BinaryFree(hDrive) Return nResult ; 0 on success otherwise error value. #EndFunction ; Test strUnicode = ChrHexToUnicode("e905dc05d505dd05") ; Hebrew equivilant of english 'hello' strShare = "\\Ranger\junk\":strUnicode ; strShare is now Unicode strDrive = "z:" nResult = WNetAddConnection2(strShare, strDrive, 0, 0, @FALSE) Message("WNetAddConnection2", nResult) ; Cleanup If nResult == 0 AddExtender("WWWNT34i.DLL") wntCancelCon(strDrive, @TRUE, @TRUE) EndIf
Article ID: W18002
Filename: wntAddDrive and Unicode.txt
File Created: 2011:02:17:10:16:06
Last Updated: 2011:02:17:10:16:06