Hello,
I'd like to be able to map (and then unmap) to a specific network drive as part of a JSL file using a DLL. Through talking to some internal IT people they've pointed me to mpr.dll and the WNetAddConnection2 and WNetCancelConnection2 functions. However, I'm not an expert programmer and so even though I've looked at the examples in the Scripting Guide and the examples on this discussion board (which do amazing things) I can't get mine to work. Also, I've never called a DLL before in any programming that I've done... Is there someone who can help me out?
The code that I've cobbled together so far (from an IT colleague who read the help file but doesn't know JMP) is below. Can anyone see obvious errors? I'd really appreciate the help...
Thanks
Colin
(Sorry it didn't format nicely. I tried some options but they looked weird)
// username, password, network map location have all been changed for pasting here
//Load the required DLL
dll_obj = Load Dll("mpr.dll");
//Assign constants to structure members - see constants list below for reference
// These are defined in the dll as DWORD (unsigned positive integers)
dwScope = HexToNumber("00000002"); //&H2;
dwType = HexToNumber("00000001"); //&H1;
dwDisplayType = HexToNumber("00000003"); //&H3;
dwUsage = HexToNumber("00000001"); //&H1;
dwFlags = HexToNumber("00000004"); //&H4;
lpLocalName = "Z:";
lpRemoteName = "\\10.254.1.1\!drive\";
lpComment = "";
lpProvider = "";
lpPassword = "password"; // Network Password
lpUserName = "domain\username";
//Declare exported function and set alias
dll_obj << DeclareFunction(
"WNetAddConnection2",
Alias("MapNetworkDrive"),
StructArg(
Arg(Int32, "dwScope"),
Arg(Int32, "dwType"),
Arg(Int32, "dwDisplayType"),
Arg(Int32, "dwUsage"),
Arg(AnsiString, "lpLocalName"),
Arg(AnsiString, "lpRemoteName"),
Arg(AnsiString, "lpComment"),
Arg(AnsiString, "lpProvider"),
"NETRESOURCE",
input
),
Arg(AnsiString, "lpPassword", input),
Arg(AnsiString, "lpUserName", input),
Arg(Int32, "dwFlags", input),
Returns(Int32)
);
//Function processing - map drive
/* DLL Function Call Syntax
dll_obj << Alias(
Structure(Every Arg),
PasswordArg,
UsernameArg,
DWFlagsArg
);
*/
result = dll_obj << MapNetworkDrive(
dwScope,
dwType,
dwDisplayType,
dwUsage,
lpLocalName,
lpRemoteName,
lpComment,
lpProvider,
lpPassword,
lpUserName,
dwFlags
);
// Successful connection should return 0 (NO_ERROR)
// Unload DLL
dll_obj << UnloadDll