473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Call NetMessageBufferSend from a c# service return 2273 error

Hi,

I have a service made in csharp language and I try to send message to
network computer with the NetMessageBufferSend.
Here's the import of the function :
[DllImport("netapi32.dll",CharSet=CharSet.Unicode,E xactSpelling=false,
SetLastError=true)]
static extern int NetMessageBufferSend(
/*[MarshalAs(UnmanagedType.LPWStr)] */string servername,
/*[MarshalAs(UnmanagedType.LPWStr)] */string msgname,
/*[MarshalAs(UnmanagedType.LPWStr)] */string fromname,
/*[MarshalAs(UnmanagedType.LPWStr)] */string buf,
int buflen);

The call failed with the 2273 return code "Alias not found on the network",
but if I use the net send in a command window, I can send the message. I
tried to change the service account with "local system" or a "domain admin",
but I failed too.

It seems that it is a right problem, but I can't find it.
Nov 16 '05 #1
4 3730
> I have a service made in csharp language and I try to send message to
network computer with the NetMessageBufferSend.


this works for me:

public static int NetSend( string serverName, string msgName, string
fromName, string message )
{
try
{
byte[] buf = System.Text.Encoding.Unicode.GetBytes( message );
return NetMessageBufferSend( serverName, msgName, fromName, buf,
buf.Length );
}
catch ( Exception ex )
{
...
}
}
[DllImport("netapi32.dll", CharSet=CharSet.Unicode)]
static extern int NetMessageBufferSend(
string serverName,
string msgName,
string fromName,
[MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.U1,
SizeParamIndex=4)]
byte[] buf,
[MarshalAs(UnmanagedType.U4)]
int bufLen);

Wiktor Zychla
Nov 16 '05 #2

"Wiktor Zychla" <us**@nospam.com.eu> a écrit dans le message de news:
Oq**************@TK2MSFTNGP14.phx.gbl...
I have a service made in csharp language and I try to send message to
network computer with the NetMessageBufferSend.


this works for me:

public static int NetSend( string serverName, string msgName, string
fromName, string message )
{
try
{
byte[] buf = System.Text.Encoding.Unicode.GetBytes( message );
return NetMessageBufferSend( serverName, msgName, fromName, buf,
buf.Length );
}
catch ( Exception ex )
{
...
}
}
[DllImport("netapi32.dll", CharSet=CharSet.Unicode)]
static extern int NetMessageBufferSend(
string serverName,
string msgName,
string fromName,
[MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.U1,
SizeParamIndex=4)]
byte[] buf,
[MarshalAs(UnmanagedType.U4)]
int bufLen);

Wiktor Zychla


Thanks, I will test this declaration.
Nov 16 '05 #3
Only "Administrators" and "Server Operators" can call this function when
running on member servers and workstations.
Or simply put - you shouldn't call this from a service.
Willy.

"Loïc Delambre" <Bo*******************@ifrance.com> wrote in message
news:uo*************@tk2msftngp13.phx.gbl...
Hi,

I have a service made in csharp language and I try to send message to
network computer with the NetMessageBufferSend.
Here's the import of the function :
[DllImport("netapi32.dll",CharSet=CharSet.Unicode,E xactSpelling=false,
SetLastError=true)]
static extern int NetMessageBufferSend(
/*[MarshalAs(UnmanagedType.LPWStr)] */string servername,
/*[MarshalAs(UnmanagedType.LPWStr)] */string msgname,
/*[MarshalAs(UnmanagedType.LPWStr)] */string fromname,
/*[MarshalAs(UnmanagedType.LPWStr)] */string buf,
int buflen);

The call failed with the 2273 return code "Alias not found on the
network", but if I use the net send in a command window, I can send the
message. I tried to change the service account with "local system" or a
"domain admin", but I failed too.

It seems that it is a right problem, but I can't find it.

Nov 16 '05 #4

"Loïc Delambre" <Bo*******************@ifrance.com> a écrit dans le message
de news: e$**************@TK2MSFTNGP11.phx.gbl...

"Wiktor Zychla" <us**@nospam.com.eu> a écrit dans le message de news:
Oq**************@TK2MSFTNGP14.phx.gbl...
I have a service made in csharp language and I try to send message to
network computer with the NetMessageBufferSend.


this works for me:

public static int NetSend( string serverName, string msgName, string
fromName, string message )
{
try
{
byte[] buf = System.Text.Encoding.Unicode.GetBytes( message );
return NetMessageBufferSend( serverName, msgName, fromName, buf,
buf.Length );
}
catch ( Exception ex )
{
...
}
}
[DllImport("netapi32.dll", CharSet=CharSet.Unicode)]
static extern int NetMessageBufferSend(
string serverName,
string msgName,
string fromName,
[MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.U1,
SizeParamIndex=4)]
byte[] buf,
[MarshalAs(UnmanagedType.U4)]
int bufLen);

Wiktor Zychla


Thanks, I will test this declaration.

It don't work for me in the service. I changed my code to use the net.exe
command in a thread.
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Colin Young | last post by:
I am creating some code that runs in Excel using VSTO. I am trying to get some xml from a webservice, using the following code: GBWPipeline.PipelineService pipeline = new...
10
by: Clint | last post by:
Hey all - I'm having a really confusing problem concerning a web service. Right now, I have an application that needs to call a web service that does nothing but return "true" (this will...
1
by: lauch2 | last post by:
I am writing a service. Before exiting the ServiceMain(), I want to call SetServiceStatus(hServiceHandle, SERVICE_STOPPED) to set the service status to SERVICE_STOPPED, but the SetServiceStatus()...
1
by: MenuChen | last post by:
I want to use the NetMessageBufferSend Function to Send message inside a Office NetWork System. For example ,my machine name is "MenuChen",and I want to send a message"hello" to the machine whose...
0
by: jthornby | last post by:
I've built a web service to fetch things from a database and return them in an XML string. I've deployed the service to a test server and am now trying to call it from my code. I created a web...
5
by: Paul Hasell | last post by:
Hi, I'm trying to invoke a web method asynchronously but just can't seem to get it to tell me when it has finished! Below is the code I am (currently) using: private void...
4
by: Paul | last post by:
Hi, I've been struggling with this today, I'm developing a DotNet2.0 website in C# that needs to call a long running data query. Obviously this is a good candidate for an Asynchronous call, so...
0
markmcgookin
by: markmcgookin | last post by:
Hi, I have a web service that I call from a winforms application. This web service can be cancelled, or completed,and then will call back the win forms application with a response (i.e. e.Complete...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.