|
Application.StartupPath ?
|
|
|
|
|
Hi,
I have started the application like this in a Service called myservice.
Process myapp=Process.Start("application path");
Now I want to get the application path (which is hard coded) through the program.
With myapp how to find out the path of the exe.
Regards,
Satya Prasad
|
|
|
|
|
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.WindowStyle=System.Diagnostics.ProcessWindowStyle.Hidden;
proc.StartInfo.FileName=Environment.CurrentDirectory+"\\myexe.exe";
proc.StartInfo.Arguments=myargumentstring; //if u have arguments
proc.Start();
|
|
|
|
|
Hi,
Sorry I think my question is not clear.
I have some process which starts some exe's.
Now I am hard coding those exe's names.
What I want the program should get the complete path of the exe and start those exe. Because these exe can be installed anywhere, If I hard code it creates problem. As you said Environment.CurrenDirectory it gives only the process's current directory not the exe's directory which I want to start.
Is there any way to get that path of exe.
Thanks and Regards,
Satya Prasad.
|
|
|
|
|
SatyaDY wrote:
Sorry I think my question is not clear
No kidding....
SatyaDY wrote:
Because these exe can be installed anywhere, If I hard code it creates problem.
You need some way of determining where those .EXE's are? Did you install them as part of your package? If so, then you could generate an .INI file listing the locations of the .EXE's. Your service could then read that .INI file to get the path to the .EXE's you want to launch. If not, your going to have to come up with a way to find these .EXE's and create an .INI file that can be used by your service. Possibly asking the user where they are? Or writing code to hunt them down? It's up to you...
Another method, although less reliable and surely more problematic, would be to write code that searches the drive for the .EXE names you want, then launch them. I think you can see the security and reliability problems with that approach...
RageInTheMachine9532
|
|
|
|
|
When executables are in directories listed in the PATH environment variable, they can be executed without specify a directory. If they aren't in the path (including the current working directory), then you need to know where they are up-front like Dave said.
If the executable is in the PATH and you still want the full path, use Environment.GetEnvironmentVariable for "PATH", then use String.Split to split the paths into a string[] array using ";" as the delimiter. You can then search those paths in order to find all the paths to the executables.
If they aren't in the PATH, then you should either store the paths in the registry or some common file during installation, or creating an RCW (Runtime Callable Wrapper) around the MSI runtime (if you used Windows Installer for your installation of these programs) and query for the executable's component path.
There's no automagical way to get this information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
since now I used sonething like this:
System.IO.FileInfo fi = new System.IO.FileInfo(Application.ExecutablePath);
GlobalContainer.ExecutablePath = fi.DirectoryName;
fi = null;
Help states:
Property Value
The path and executable name for the executable file that started the application.
Caveeat: You need to reference System.Windows.Forms.
-sa
--
http://www.livingit.de
http://www.mobile-bookmarks.info
http://www.not2long.net
|
|
|
|
|
Hello,
I have added the user control to a form. How do I listen for form resize event inside my user control. i.e When ever form is resized, i need to resize the user control also. I dont want to use docking property of user control.
I tried with the below statement:
private void InitializeComponent()
{
//.........
this.TopLevelControl.Resize +=new EventHandler(TopLevelControl_Resize);
}
But this is throwing NullRefrenceException - Object reference not set to an instance of an object.
Is there any other way?
Thanks & Rgds
Jayakarthikeyan.S
|
|
|
|
|
Try the Anchor property of the control.
RageInTheMachine9532
|
|
|
|
|
Hello,
Anchor property does not resize the control and location is getting changed.
Here i want control to be resized along with the form. When the form is resized larger and once control reaches its default size then control should stop resizing.
Thanks & Rgds
jayakarthikeyan
|
|
|
|
|
jayakarthikeyan wrote:
Anchor property does not resize the control and location is getting changed.
Wanna bet?
That's exactly what the anchor property does. It anchors one of more sides of the control to the side of its container, in your case the form.
If you select all four sides of the Anchor property, then the controls top left corner will be pinned in place and the bottom right corner will be moved to keep the same distance from the bottom right corner of the form. If you select just the top and left sides, then the control will maintain its position and not resize. If you select just the bottom and right sides, the control will not resize but will only move to keep it's position relative to the bottom right corner of the form.
The bottom line is if you select two opposite sides to Anchor, the control will resize itself to maintain those two edges relative to the sides of the form. If not, then the control will move to maintain its relative position to the edge that is selected.
To get the minimum size, use the MinimumSize property of the FORM, not the control. This way your form cannot be resized so small that the controls on it get so small that they are useless.
Your only other alternative is to override the Anchor property of the control and supply the resizing code yourself. BTW: What do you mean by "reaching it's default size"? The control can resize, but only within a certain range? Does it have to maintain a minimum and/or maximum size? If that is the case, then you WILL have to override Anchor and supply the resize code yourself.
RageInTheMachine9532
|
|
|
|
|
Thanx Dave. It's resizing when form is resized.
Jayakarthikeyan
|
|
|
|
|
You can also use the Dock property with DockStyle.Fill besides anchoring, but Dave's right - anchoring is used for this very purpose and gives you more control than docking in many cases.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm looking for a design pattern that allows for volatile interface changes to meet the needs of varying demands. Basically I have a project where abstractions will be relatively stable but, the actual implementations will vary. I've thought about using the bridge pattern but, I'm not sure if thats the best idea. If anyone has any suggestions they would be greatly appreciated.
|
|
|
|
|
I have seen some .NET code on the web that uses the Microsoft.Win32.Win32Native class. However, whenever I try to use it I get a compiler error (#CS0122) saying that it is inaccessible due to its protection level. How can I get access to it?
Thank you,
Ray Gregory
|
|
|
|
|
The Win32Native class is internal . This means that those methods and members are only visible to that particular assembly, not to your code.
- Nick Parker My Blog | My Articles
|
|
|
|
|
This error appears when i decrypt the message that is read from a file. The message in this file is encrypted. Before encrypting the message, this message is Xml data that read from a xml file.
What is the meaning of this error ? Thanks for help
Mscorlib (in Mscorlib.dll)
at System.Security.Cryptography.CryptoAPITransform._DecryptData(IntPtr hKey, Byte[] rgb, Int32 ib, Int32 cb, Boolean fDone)
at System.Security.Cryptography.CryptoAPITransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)
at System.Security.Cryptography.CryptoStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at WindowsApplication3.Form1.button10_Click(Object sender, EventArgs e)
|
|
|
|
|
This message is not complete part of your exception. It only say where does exception happen but you didn't send error message and your code so we can help yu more.
Mazy
"Man is different from animals in that he speculates, a high risk activity." - Edward Hoagland
|
|
|
|
|
Actually, there was no exception being thrown.
If you have seen the code ... the try-catch is something that i insert to see what thing is happening ...
This is because ... the program was hanged in the do loop ...
I don't know how to express ... if you have tried the code, you will know what is happening...
Things made me mad ...
Anyway, thanks for your reply ...
i still look forward you can help me to solve this problem ....
|
|
|
|
|
how to scan a barcode and input it to my c# code
how to know information about all this senario?
|
|
|
|
|
Reading barcodes from documents that have been printed with some kind of symbology is a kind of micro-specialization. There are several different kinds of symbols used (UPC, EAN, Interleaved 2 of 5, Code 39, etc.) in which barcodes are produced by printing on laser printers, barcode label printers, dot matrix printers, etc... and then you have readers (wands, scanners, etc.) that are either serial or keyboard wedge readers. The latter -- keyboard wedge -- are easier to use, and often plug and play. A decent reader will cost between US$100 and US$200 and should be programmable to read different symbols, look for check digits, etc. Once you have a reader, you can get the result into a text box just as though someone had typed the information using a keyboard.
What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.
|
|
|
|
|
I'm trying to build a 2-player game that uses the keyboard to control the game elements. I'd like certain keys to control player 1 and others to control player 2. I was thinking about doing this by having each player's game piece contain a controller object that is used to capture key events and then call back to the game piece to do things like set direction. The controller would implement IMessageFilter and the game piece would create it like: Application.AddMessageFilter( new Ctrl( this )). Wondering if it's possible to add multiple message filters like this.
|
|
|
|
|
I don't really think that you would need two message filters to handle this process, one should do the trick. The key that is press gets packed into the WParam of the Message so once you evaluate what was hit you can simply dispatch control to the appropriate method.
private const int WM_KEYDOWN = 0x0100;
public bool PreFilterMessage(ref Message m)
{
if(m.Msg == WM_KEYDOWN)
{
char c = (char)m.WParam;
if(c == 'A')
MessageBox.Show("A was hit");
}
return false;
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
Well, what I'm trying to do is have each controller be associated with a specific game piece. That way I don't have to keep track of what game pieces were created or hard code specific references. If I want to create 2 players, I can, but if I later decide to create 7 players, I don't have to change much code.
|
|
|
|
|
Yes it's possible, which is why the related methods are called AddMessageFilter and RemoveMessageFilter . There is a reason to keep a consistent naming convention, and Microsoft has done that with 90% of their code.
You also could've just thrown together a quick example. Throwing together samples is a staple of development.
Microsoft MVP, Visual C#
My Articles
|
|
|
|