Solved

Using system ("net send ...")

Posted on 2004-04-01
12
303 Views
Last Modified: 2010-04-15
I inherited a Access DB that uses a bunch of .bat files that net sends all the users of this DB when it needs repaired and when it is back up. I would like to consolidate these into a c prog. that reads from a list of users instead. I'm having problems getting the message into a string variable and then sending it.

does anyone know how to do this?

Thanks in advance.

Jim
0
Comment
Question by:scuzz1
  • 4
  • 3
  • 2
  • +3
12 Comments
 
LVL 45

Expert Comment

by:Kdo
ID: 10734170
Hi scuzz1,

There are several problem areas here concerning strings.  In a logical sense, you're really going to have to build several strings.  Here are the basic steps that you'll need to take:

1.  Build the string the you want to send.
2.  Encapsulate it with quotes.
3.  Append the string after the "net " command string.
    The result will be 'net "some message"'.
4.  Convert the embedded double quotes to backslash double-quote.

The resulting string will look like "net \"some message\"".

If the string that you're going to send has embedded quotes, you'll need to perform another round of conversion on the quotes.

Kent
0
 

Author Comment

by:scuzz1
ID: 10734223
Hi Kent,

I have all the messages I need pasted together into string vars (including the "net send" command) I was trying to use it like this

  system ( varname )

Can I do it like that?
0
 
LVL 45

Expert Comment

by:Kdo
ID: 10734250
Hi scuzz1,

Sure.  The code should resemble this:


  char Message[1000];
  char *Text = "Send This";

  strcpy (Message, "net ");
  strcat (Message, "\"");
  strcat (Message, Text);
  strcat (Message, "\"");

  system (Message);


Kent
0
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
LVL 45

Accepted Solution

by:
Kdo earned 500 total points
ID: 10734263
Hi scuzz1,

Make that:


  char Message[1000];
  char *Text = "Send This";

  strcpy (Message, "net send ");   /* Missed this the first time around  :()  */
  strcat (Message, "\"");
  strcat (Message, Text);
  strcat (Message, "\"");

  system (Message);


Kent
0
 

Author Comment

by:scuzz1
ID: 10734295
I think the strcat (message, "\""); is what I'm looking for. I'll try it and get back to you.
0
 
LVL 2

Expert Comment

by:Avik77
ID: 10734367
Hi shouldn't u insert a * i.e
net send * message

Avik.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10738493
you can combine all these statements into a single snprintf and it is safer too

sprintf ( message, 1000, " net send %s", send_this );

you can read the string send_this from the user at run time

system (message );
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10738510
grrr ... I recommend snprintf and write down a sprintf

snprintf ( message, 1000, " net send %s %s", receiver, send_this );
 ^                                                   ^^    
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10739797
Hi,
if i remember correctly,the syntax of net send was:
 net send terminal number "message"
e.g. net send 4-33 "hello world"

char str[1000];
char term[100];

char msg[100];
strcpy(msg,"Repair needed etc....");

for(i=0;i<limit;i++)
{
strcpy(str,"net send ");
strcat(str,term); //where term stores the terminal number
strcat(str,"\"");
strcat(str,msg);//where msg stores the message which is the same for all users.
strcat(str,"\"");
system(str);
//change the terminal number for the next terminal in the string term
//if ur terminal numbers are just normal integer type numbers,use an integer
//keep incrementing them and use the itoa() function to convert them into string
//or as u said,u can store them in a double dimensional array of char(but that would take
//more space if the number of terminals is large).In that case,use term[i] where term[][] is where u store the terminal number
}

U said that u stored the entire command in strings.
the message is common to everyone so the only thing that changes in the command is the terminal number,just store those in a char[][] array and if they are numbers in some order
u can also use integers and the itoa() function
0
 
LVL 45

Expert Comment

by:Kdo
ID: 10740113
Hi Sunny,

The "wild" card in all of this is special characters.  That's why I suggested that the poster contain the data to be sent in quotes.

net send <destination> S t r i n g  w i t h  d o u b l e  s p a c i n g

Works only when the message is quoted.  And of course, any time that the string contains embedded quotes, the string must be converted to pass them properly.


Sure would be easier in *nix, huh?  A simple script would do all of the heavy lifting and keep the poster from having to maintain another program.  :)

Kent
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10740399
Hi Kent,

You are right ... *nix is far more suitable for this kind of stuff ...
Perhaps the reason why programmer's prefer it ... or is it too addictive ;o)
0
 
LVL 1

Expert Comment

by:mdhmi
ID: 10742303

Which OS is this running on?  You could construct your 'net send' using the Windows API, however, that would require much more effort then just calling the 'system' function with your 'net send'.

Mark

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Where is my core dump file in Ubuntu? 12 450
mixing C++ and C code elegantly 10 157
Acrinis True image 2 79
NEED HELP WITH VISUAL STUDIO 2017 (beginner) 6 40
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question