- Netware client must be installed at the host running this code.
- I’m using Novell Client for Windows Vista 1.0 in Windows 2008 SP1 .NET 3.5
- This code does not map novell volume drive to the host machine.Use UNC path.
// The Netware.dll
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
namespace knNovell
{
public class Netware
{
[DllImport(”calwin32.dll”, CharSet = CharSet.Ansi)]
private static extern int NWCallsInit(int _in, int _out);
[DllImport(”locwin32.dll”, CharSet = CharSet.Ansi)]
private static extern int NWFreeUnicodeTables();
[DllImport(”netwin32.dll”, CharSet = CharSet.Ansi)]
private static extern int NWDSCreateContextHandle(out UInt32 newHandle);
[DllImport(”netwin32.dll”, CharSet = CharSet.Ansi)]
private static extern int NWDSFreeContext(UInt32 context);
[DllImport(”netwin32.dll”, CharSet = CharSet.Ansi)]
private static extern int NWDSLogin(UInt32 context, UInt32 optionsFlag, string objectName, string password, UInt32 validityPeriod);
[DllImport(”netwin32.dll”, CharSet = CharSet.Ansi)]
private static extern int NWDSLogout(UInt32 context);
[DllImport(”netwin32.dll”, CharSet = CharSet.Ansi)]
private static extern int NWDSSetContext(UInt32 context, Int16 key, string value);
static UInt32 context;
public static string Connect(string ServerName, string Tree, string UsrContext, string UsrName, string UsrPwd, string TargetFolder)
{
try
{
NWCallsInit(0, 0);
NWDSCreateContextHandle(out context);
NWDSSetContext(context, 11, Tree);
NWDSSetContext(context, 3, UsrContext);
NWDSLogin(context, 0, UsrName, UsrPwd, 0);
/* Since novell return code does not make any sense,
* this line try to read any folder inside the server.
* If no exception, the login process is successful.
* In my case, I will try to access \SYS\CLSOUT folder.
*/
string[] verifyLogin = Directory.GetFiles(@”\\” + ServerName + @”\SYS\” + TargetFolder + @”\”);
return ”0”;
}
catch (Exception ex)
{
return ex.Message;
}
}
public static string Disconnect()
{
try
{
NWDSLogout(context);
NWDSFreeContext(context);
NWFreeUnicodeTables();
return ”0”;
}
catch (Exception ex)
{
return ex.Message;
}
}
}
}
//The main
using System;
using System.Collections.Generic;
using System.Text;
using knNovell; // Dont forget to add reference to Netware.dll
namespace testNetwareDll
{
class Program
{
static void Main(string[] args)
{
string ServerName = “DNS_ServerName or Netbios name”;
string Tree = “TREE”;
string UsrContext = “UserContext”;
string UsrName = “Username”;
string UsrPwd = “Pwd”;
string TargetFolder = “CLSOUT”;
Console.WriteLine(Netware.Connect(ServerName, Tree, UsrContext, UsrName, UsrPwd, TargetFolder));
Console.ReadKey();
Netware.Disconnect();
Console.ReadKey();
}
}
}
//You can use this code to create Windows Services using this skel
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.IO;
using System.Threading;
using knNovell; // Dont forget to add reference to Netware.dll
namespace knFrameworks
{
public partial class MyService : ServiceBase
{
public KnService()
{
InitializeComponent();
}
Thread MyNovellService;
protected override void OnStart(string[] args)
{
MyNovellService = new Thread(this.fileService);
MyNovellService.Start();
}
protected override void OnStop()
{
MyNovellService.Abort();
}
public void fileService()
{
for (; ; ) //Infinite Loop
{
//Your Code
} // Infinite loop
}
} // End
}
Ref site:
Thanks man
This code saved me a lot of time,
thanks again.
Comment by Slobodan — November 13, 2008 @ 6:04 PM
Great!
Comment by khairulnixam — November 19, 2008 @ 1:17 AM
This code has been a lifesaver for me! Thank you so much
Comment by Michael Smith — March 9, 2009 @ 8:18 AM
Worked for me.
Much appreciated!
Comment by Mike — July 19, 2011 @ 2:06 PM