|
I need to know how to gain access to items in the command prompt using c#. What I want to do is send a message on XP using system32\net send blah blah. I know how to do it in c++
system("net send blah blah");
but Im not sure on C#. Any help would be greatly appreciated.
Confused and Waiting
Pumpkin Knight
|
|
|
|
|
What you could do is instantiate the Cmd Window and pass in your arguments as such.
public void sendThread()
{
Process p = new Process();
p.StartInfo.CreateNoWindow=true;
p.StartInfo.FileName = "cmd";
p.StartInfo.Arguments = "net send COMPUTER Hello there.";
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();
p.WaitForExit();
p.Close();
}
|
|
|
|
|
Hi all,
Please some response!
I have an applıcation and when it's running , Windows can not shut down!
It says nothing but goes back to desktop when I click shut down.
I really dont know why , maybe one knows.
Key features about my application:
- Uses OleDbConnection and OleDbDataAdapter for an Access2000 database.
- Has a notify icon on task bar and starts from there (not with a window form)
- Starts when Windows starts by using HKLM/..../CurrentVersion/Run
All left are ordinary and what I have experience a lot.
Any help will be appreciated.
Thanks.
Utku KAYA
|
|
|
|
|
Do you have some kind of loop or strangeness in your exit condition?
|
|
|
|
|
Your Problem is that you override the close function. So if Win tries to shutdown your app still wants to go to trayicon and prevents Win from Shutdown.
Use this code to fetch the Win Shutdown Command:
protected override void WndProc(ref Message m)
{
base.WndProc (ref m);
if (m.Msg == 0x11)
{
boolAlowClose = true;
this.Close();
}
}
So i think you have a bool where you set true if you want realy to leave the application (where you check the bool on app close event and set e.cancel)
Hope this helps!
Greets
Matthias
|
|
|
|
|
I have written a c# service that uses a process timer to perform tasks on a regular basis.
Under certain conditions, I want this timer thread to be able to kill the service but I cannot figure out how to do it.
Can anyone help me?
Thanks in advance for your help!
Darryl Borden
Principal IT Analyst
darryl.borden@elpaso.com
|
|
|
|
|
I have figured it out - I can create a servicecontroller component and issue a stop from there.
Darryl Borden
Principal IT Analyst
darryl.borden@elpaso.com
|
|
|
|
|
Hello All,
If i have a tab control with several tab pages, and I drag and drop an item on the tab portion of any of these pages, is there an easy way to get that tab page object from the x y values given to me during the dragdrop event? I fired the ondragdrop event from the tab control because I was not able to get the tab portion of a tab page to fire a drag drop event.
Thanks,
Ryan
|
|
|
|
|
If you mean the actual tab of the tab page using the coordinates, there's really only about one way. You can't get the tab portion directly, but you get the bounding rect for an individual tab. You could wrap it all in a simple method like so (I use Point to make the example code easier, but you can either create a Point from X and Y or pass them in and make a Point ):
private TabPage GetTabPageFromPoint(Point p)
{
p = this.tabControl1.PointToClient(p);
for (int i=0; i<this.tabControl1.TabPages; i++)
{
Rectangle rect = this.tabControl1.GetTabRect(i);
if (rect.Contains(p)) return this.tabControl1.TabPages[i];
}
return null;
}
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks Heath,
I had the looping mechanism, but I had completely forget to convert the coordienates from the screen to the tab control coordinates.
Thanks again,
Ryan
|
|
|
|
|
Would TabControl.GetChildAtPoint work?
The graveyards are filled with indispensible men.
|
|
|
|
|
No, since the tab portion of a TabPage is not a control.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hy, can anybody help me, or does anybody know how to make the same thing with the tray?
mfg maZe
|
|
|
|
|
To do this in .NET (this is the C# forum after all), use the NotifyIcon component, which you can find in your toolbox. It's easy to use.
If it doesn't do everything you need, there are several articles here on CP that discuss / create more advanced components that use the shell API's Shell_NotifyIcon (which the NotifyIcon component does internally as well - just doesn't always expose everything you might need to use).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I want to write a program to get the character which mouse pointer focus on.
Just like that first move the mouse pointer on some character for a while and i could get which character or word it pointed.
It is so diffucult to find proper way to do this.
I have try to use IDataObject d = Clipboard.GetDataObject(); and other thing..
But it fails. because some in some case i could find the character but others no.
Could anyone suggest me one good way suited for every control?
Example......
when i use a MS WORD application.. And put some word there like.
HELP
|
mouse pointer pointed that word and i could get that word is "HELP"....
Thanks in advanced.
Kato
|
|
|
|
|
Hi
I need to have a folder browser in my program - and i then added one, but i doesnt work. I then look at msdn.com where i found this pice of code
<br />
using System;<br />
using System.Drawing;<br />
using System.Windows.Forms;<br />
using System.IO;<br />
<br />
public class FolderBrowserDialogExampleForm : System.Windows.Forms.Form<br />
{<br />
private FolderBrowserDialog folderBrowserDialog1;<br />
private OpenFileDialog openFileDialog1;<br />
<br />
private RichTextBox richTextBox1;<br />
<br />
private MainMenu mainMenu1;<br />
private MenuItem fileMenuItem, openMenuItem;<br />
private MenuItem folderMenuItem, closeMenuItem;<br />
<br />
private string openFileName, folderName;<br />
<br />
private bool fileOpened = false;<br />
<br />
static void Main() <br />
{<br />
Application.Run(new FolderBrowserDialogExampleForm());<br />
}<br />
<br />
<br />
public FolderBrowserDialogExampleForm()<br />
{<br />
this.mainMenu1 = new System.Windows.Forms.MainMenu();<br />
this.fileMenuItem = new System.Windows.Forms.MenuItem();<br />
this.openMenuItem = new System.Windows.Forms.MenuItem();<br />
this.folderMenuItem = new System.Windows.Forms.MenuItem();<br />
this.closeMenuItem = new System.Windows.Forms.MenuItem();<br />
<br />
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();<br />
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();<br />
this.richTextBox1 = new System.Windows.Forms.RichTextBox();<br />
<br />
this.mainMenu1.MenuItems.Add(this.fileMenuItem);<br />
this.fileMenuItem.MenuItems.AddRange(<br />
new System.Windows.Forms.MenuItem[] {this.openMenuItem,<br />
this.closeMenuItem,<br />
this.folderMenuItem});<br />
this.fileMenuItem.Text = "File";<br />
<br />
this.openMenuItem.Text = "Open...";<br />
this.openMenuItem.Click += new System.EventHandler(this.openMenuItem_Click);<br />
<br />
this.folderMenuItem.Text = "Select Directory...";<br />
this.folderMenuItem.Click += new System.EventHandler(this.folderMenuItem_Click);<br />
<br />
this.closeMenuItem.Text = "Close";<br />
this.closeMenuItem.Click += new System.EventHandler(this.closeMenuItem_Click);<br />
this.closeMenuItem.Enabled = false;<br />
<br />
this.openFileDialog1.DefaultExt = "rtf";<br />
this.openFileDialog1.Filter = "rtf files (*.rtf)|*.rtf";<br />
<br />
this.folderBrowserDialog1.Description = <br />
"Select the directory that you want to use as the default.";<br />
<br />
this.folderBrowserDialog1.ShowNewFolderButton = false;<br />
<br />
this.folderBrowserDialog1.RootFolder = Environment.SpecialFolder.Personal;<br />
<br />
this.richTextBox1.AcceptsTab = true;<br />
this.richTextBox1.Location = new System.Drawing.Point(8, 8);<br />
this.richTextBox1.Size = new System.Drawing.Size(280, 344);<br />
this.richTextBox1.Anchor = AnchorStyles.Top | AnchorStyles.Left | <br />
AnchorStyles.Bottom | AnchorStyles.Right;<br />
<br />
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
this.ClientSize = new System.Drawing.Size(296, 360);<br />
this.Controls.Add(this.richTextBox1);<br />
this.Menu = this.mainMenu1;<br />
this.Text = "RTF Document Browser";<br />
}<br />
<br />
private void openMenuItem_Click(object sender, System.EventArgs e)<br />
{<br />
if (!fileOpened) {<br />
openFileDialog1.InitialDirectory = folderBrowserDialog1.SelectedPath;<br />
openFileDialog1.FileName = null;<br />
}<br />
<br />
DialogResult result = openFileDialog1.ShowDialog();<br />
<br />
if(result == DialogResult.OK) <br />
{<br />
openFileName = openFileDialog1.FileName;<br />
try<br />
{<br />
Stream s = openFileDialog1.OpenFile();<br />
richTextBox1.LoadFile(s, RichTextBoxStreamType.RichText);<br />
s.Close(); <br />
<br />
fileOpened = true;<br />
<br />
} <br />
catch(Exception exp)<br />
{<br />
MessageBox.Show("An error occurred while attempting to load the file. The error is:" <br />
+ System.Environment.NewLine + exp.ToString() + System.Environment.NewLine);<br />
fileOpened = false;<br />
}<br />
Invalidate();<br />
<br />
closeMenuItem.Enabled = fileOpened;<br />
}<br />
<br />
else if(result == DialogResult.Cancel) <br />
{<br />
return;<br />
}<br />
}<br />
<br />
<br />
private void closeMenuItem_Click(object sender, System.EventArgs e)<br />
{<br />
richTextBox1.Text = "";<br />
fileOpened = false;<br />
<br />
closeMenuItem.Enabled = false;<br />
}<br />
<br />
<br />
private void folderMenuItem_Click(object sender, System.EventArgs e)<br />
{<br />
DialogResult result = folderBrowserDialog1.ShowDialog(); <br />
if( result == DialogResult.OK )<br />
{<br />
folderName = folderBrowserDialog1.SelectedPath; <br />
if(!fileOpened)<br />
{<br />
openFileDialog1.InitialDirectory = folderName;<br />
openFileDialog1.FileName = null;<br />
openMenuItem.PerformClick();<br />
} <br />
}<br />
}<br />
}<br />
When I copy this into my IDE, and run it - it works fine, but when i write the linies used for the FolderBrowserDialog it doesn´t work. I cant find the System.Enviroment.SpecialFolder enum. I cant find it at msdn.com - but they use it...
Can anyone help me...
thanks in advance
Søren Christensen
|
|
|
|
|
Sometimes VS.NET has a problem showing nested classes, structs, and enums. The System.Environment.SpecialFolder enum is a next enum of the Environment class. Just type it and you should be fine. For information, type "SpecialFolder" in VS.NET's index. Don't forget the power of using the integrated help already on your system, since it is often hard to find things on MSDN because their search doesn't include a simple index like VS.NET's integrated MSDN help.
Also, if you need one in .NET 1.0 (FolderBrowserDialog is only available in .NET 1.1) there is an easy way. Click on "Add References", click the COM tab, and find "Microsoft Shell Controls and Automation". Then you can use simple code like this to get the default one that already exists in Windows (which provides a consistent UI in your app, too):
Shell32.Shell shell = new Shell32.ShellClass();
Shell32.Folder folder = shell.BrowseForFolder(
this.Handle.ToInt32(),
"Destination",
0x8000,
Shell32.ShellSpecialFolderConstants.ssfDRIVES);
if (folder != null) return ((Folder2)folder).Self.Path;
else return null;
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hey
I've downloaded and installed the DirectX 9.0 SDK from Microsoft.com,
and tried to understand the C# CaptureSound sample that was included.
It seems that it only can capture/save sound for a short periode of time, so you only get the last bits of the sound that was captured.
I think (not realy shore), that it is an integer problem, since it's buffer values is made up of integers, but it can't realy be only that, since there are no values that goes to infinity.
How can I make it capture all of the sound?
Thanks in advance for your help ,
Thomas
|
|
|
|
|
In the same, they allocate a buffer to a certain size and read data into it until it's full or you disable the capture. In a rea;-world application, you must keep reading into the buffer and write it out when it's full (it'd be good to have two buffers so you can write a full on in one thread and start reading into the next buffer, then switch and repeat).
It's kind of like reading in a large file using a Stream or TextReader : you should use Stream.Read or TextReader.ReadBlock with a decent buffer size in a loop until data smaller than the buffer is read (the streams and readers take care of the EOF for you).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
The Problem:
I'm running C# and VB.NET projects from sourcesafe, with four developers working on the projects at any given time. The majority of any file references such as .DLLs and .SNK files are done via relative file paths i.e. ..\..\DataAccessLayer.snk.
In some cases, this relative approach doesn't work for some PCs that the developers use. Instead they need to use: \VMR\DAL\DataAccessLayer.snk
OK, you still with me? Good good. Now here's the final straw. We now have a project where neither of these file paths are allowing the project to compile. Instead it needs an explicit path name including the drive letter:
Assembly: AssemblyKeyFile("E:\VMR\DAL\DataAccessLayer.snk")
Unfortunately, I cannot impose that every developer keeps their source code on the same drive letter on their machines. The projects must support being installed onto various drive letters.
Firstly I cannot understand why a file path will work correctly on one machine and not another - and I have ensured that all the files etc. are in place as they should be.
So, unless there's some dumb user option I'm missing here, does anyone know why .NET behaves differently like this? Can I make it work 100% of the time without specifying a drive letter?
|
|
|
|
|
Martin Cross wrote:
So, unless there's some dumb user option I'm missing here, does anyone know why .NET behaves differently like this? Can I make it work 100% of the time without specifying a drive letter?
Just a thought, but why not always map to the UNC path (this way it's the same for every developer), who cares what drive letter any of your developers map to a network share, that could always change per developer as you are noting. In this case, there is even an article on CP to help with UNC paths: Network Shares and UNC paths[^].
P.S. - I'm sure Heath will respond to this eventually, I give him an hour or two.
-Nick Parker
DeveloperNotes.com
|
|
|
|
|
Network shares aren't the solution. A lot of us grab the latest version onto laptops and work from home using disconnected checkouts (dangerous I know).
So, am I not the only one where the file paths are a bit iffy then?
|
|
|
|
|
Simple: don't use files. Instead of using the AssemblyKeyFileAttribute use the AssemblyKeyNameAttribute . Import the key pair into a key container using sn -i KeyFile.snk MyCompany and then specify "MyCompany" (or whatever, so long as it matches) as the sole parameter to the latter attribute's constructor. You only need to do this once.
The only thing that isn't documented is whether the key container must exist as a machine container or a user container. It probably doesn't matter, but just a heads-up.
For a brief description, see my article: Using XML Digital Signatures for Application Licensing[^]. The articles not about your problem, but the solution is discussed a little (about key containers, that is).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Good grief man! That's beautiful.
Thanks < bows down as he backs away slowly >
|
|
|
|
|
I use right mouse button to open next form in overridden OnMouseDown() method in overridden DataGrid (standard DataGrid works ok). Before this, automatic menu (copy, paste etc.) is opened - while creating new form. How to avoid it? Only OnKey...() has Handled property - but OnKey isn't fired.
-or-
How to add my item to automatic menu (copy, paste etc.)?
Thx in advance.
Hi,
AW
|
|
|
|