|
I've got time.
Honestly, if an application killed off Explorer for me, without my permission, I'd want to know where on earth this person was who wrote it, for some very not-so-nice reasons...
Please tell me this isn't being deployed into the real world?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I understand your concerns and curiosity. I'm not going to be shutting down explorer all willy-nilly. There's a good reason for it in the context of what I'm working on.
For those of you that may wonder how this all turned out, I had to import the User32.dll functions, FindWindow and PostMessage (as tommazzo suggested). The final code looks like this:
public class Win32
{
public Win32(){}
[DllImport("User32.dll")]
private static extern IntPtr FindWindow(string ClassName,
string WindowName);
[DllImport("User32.dll")]
private static extern Boolean PostMessage(IntPtr hWnd,
uint Msg,
IntPtr wParam,
IntPtr lParam);
public bool ShutdownExplorer()
{
Boolean bSuccess = false;
IntPtr Handle = new IntPtr(0);
// Get a handle to explorer.exe
Handle = FindWindow("Progman", null);
// Shutdown explorer.exe
if(Handle != IntPtr.Zero) bSuccess = PostMessage(Handle,
0x0012,
IntPtr.Zero,
Ptr.Zero);
return bSuccess;
}
}
Thanks tommazzo for the solution. Thanks Dave for your insights.
Regards,
Ian
|
|
|
|
|
tommazzo wrote:
When I tested it however explorer.exe restarted a few seconds after it was killed.
It's supposed to do this. By default, Explorer automatically restarts itself if it's shutdown without a user session logoff. Sometimes, though, it doesn't restart itself. When this happens, you can still hit Ctrl-Alt-Del, start the Task Manager, click on File/New Task (Run), then type CMD in the prompt, NOT EXPLORER! Instead, type CMD and in the resulting command window, type START EXPLORER.
For some reason, if Explorer crashes and you type EXPLORER in the Start/Run box, it won't restart. Though, typing the START EXPLORER command in a CMD window works. Wierd...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I am writing a frontend to the ffmpeg program so I can convert multimedia files to a Playstation Portable format. I am using the Process Class with redirected outout so I don't have a console window popup. Now if I run the Program Through the IDE (Debug or Release) it works flawlessly. If I run the generated exe outside of the IDE I get errors from the program and the conversion does not complete or even do anything wright. I know this could be a ffmpeg issue but the only difference from working and not working is the IDE execution. I have checked the environment variables and there is only one difference a debug varibale is set in the IDE and I have artificaly set that just to see if that would work and it didn't.
Any Ideas?
Thanks
Cyber
|
|
|
|
|
There's more than just the IDE being there or not, the current directory also changes. So, I have a couple questions...
Does your application supply the full paths or all the files involved with ffmpeg? Does your code consider than ffmpeg might fail and log everything that came out of the session into a file somewhere? What errors are returned by ffmpeg when you shellexecute it?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Here is my Code:
Process P2 = new Process();
P2.StartInfo.UseShellExecute = false;
P2.StartInfo.FileName = Environment.CurrentDirectory + @"\ffmpeg.exe";
P2.StartInfo.WorkingDirectory = Environment.CurrentDirectory;
P2.StartInfo.RedirectStandardOutput = true;
P2.StartInfo.RedirectStandardError = true;
P2.StartInfo.Arguments = strCmd;
P2.StartInfo.CreateNoWindow = true;
P2.Start();
There is not exit code like info the program just can't read the input files correctly. I do have all the files in the Environment.CurrentDirectory and have even at one point appended the Environment.CurrentDirectory to the Environment Variable "PATH" statement.
Also if I allow the console box to appear with the redirect turned off. It works on both situations.
Thanks,
Cyber
|
|
|
|
|
I didn't ask for an exit code. I asked if you were reading the redirected output and dumping it into a file for later review. If the program can't read the files, or any other error ffmpeg complains about, it would be displayed in either one of the streams. If you were reading those streams, then the output could be dumped into a file for debugging.
Now, since your doing this to prevent a console window from showing up, it's entirely possible that ffmpeg doesn't support that. It might actually need a console window because the app is trying to write directly to the screen buffer in that window. If there is no console window, no screen buffer. No screen buffer, BOOM!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I am capturing both streams into a RichTextBox for Debugging and no usefull info is in there for finding out what is going on.
Quote
"Now, since your doing this to prevent a console window from showing up, it's entirely possible that ffmpeg doesn't support that. It might actually need a console window because the app is trying to write directly to the screen buffer in that window. If there is no console window, no screen buffer. No screen buffer, BOOM!"
It works fine if I use the the Debug Start option from the Menu.
Thanks,
Cyber
|
|
|
|
|
In that case, I have no idea what's going on. I've never had a problem shelling another process like this.
The only thing I can think of is don't use the CurrentDirectory. I've always used full path specifiers for all of my file access. Even the ones that are used as command line parameters in other programs. I just don't believe in leaving something like the "CurrentDirectory" to chance and calling it "reliable."
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
I am using Syncfusion.Windows.Forms.HTMLUI.HTMLUIControl() to open a specific url in an html browser. The documentation gives me an example that does work; however, I want to modify it so that the url is automatically displayed when the winform is rendered.
Here is what works (NOTE: The ... indicates code that I have not shown here, for brevity's sake):
<br />
...<br />
#region Windows Form Designer generated code<br />
...<br />
private void InitializeComponent()<br />
{<br />
...<br />
this.textBox1.Text = "http://www.google.com";<br />
...<br />
}<br />
...<br />
<br />
[STAThread]<br />
static void Main() <br />
{<br />
Application.Run(new Form1());<br />
}<br />
<br />
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)<br />
{<br />
if( ( ( int )e.KeyChar ) == 13 )<br />
{<br />
LoadDocument( textBox1.Text );<br />
}<br />
}<br />
<br />
private void LoadDocument( string path )<br />
{<br />
if( path == null )<br />
throw new ArgumentNullException( "path" );<br />
<br />
if( path.Length == 0 )<br />
throw new ArgumentException( "path - string can not be empty" );<br />
<br />
try<br />
{<br />
Uri uri = new Uri( path );<br />
htmluiControl1.LoadHTML( uri );<br />
}<br />
catch( Exception )<br />
{<br />
ShowError();<br />
}<br />
}<br />
...<br />
Again, what I want, is to have the url automatically loaded when the winform is rendered and eliminate the textbox and the need for the user to press the enter key.
Thank you in advance for any help you can give me.
Anne
|
|
|
|
|
We don't support 3rd party controls here, simply because there are thousands of them to play with. It's impossible for anyone to know everything about every control and extremely unlikely that someone who has worked with the control will ever see your post.
But, is there anything wrong with calling with calling the control's LoadHTML() method from inside the Form Load event, or maybe Form Activate?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thank you so much for your help... Sorry for the 3rd party control question -- ooops...
I will try what you suggest and also contact the maker of that control.
Thanks again,
Anne
|
|
|
|
|
Hi,
Could you please explain to me the purpose of using DataRelation? I seem to understand it wrong, hence implement it wrong..
Please correct me if I am wrong ( i know I am wrong), that DataRelation is used to setup a relationship between datatables and to create a new table with all of the attributes of the 2 tables?
What I am trying to implement is to combine 3 database tables to create a new table that has only the attributes I want..
Elapid For The Win
|
|
|
|
|
Right on the first part, wrong on the rest.
A DataRelation is the analog of a SQL Server foreign key constraint. It does relate two DataTables on a user-defined key in a parent/child relationship. It does not, however, merge the columns of two or more DataTables into a unified view.
There's ample information in MSDN on this topic.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
I currnetly have a reporting method that works well for one user at a time, but these reports have gained popularity within my organization. If more than one user uses it at the same time they get overlapping data.
Current setup is using a c# application that uses crystal reports to view info from a MSSQL database table. The problem is that they all use the same table. The application gahters data from a couple of databases, makes some decisions based on the information gathered, and writes all of the data to this one table.
I'm running into a wall trying to make this more dynamic. Any ideas on how I can give each user their own data to work with?
Jeff Guerrero
|
|
|
|
|
|
Odds are the startup project in your solution is set to a class library project, and not an executable project.
As the message indicates, you can't execute a class library - there's nowhere for your application to start (e.g. a Main method).
In Solution Explorer, right click on an executable project and set it as the startup project.
Hope this helps.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Yes that seems to have worked. There was a Main method in one of the projects.
What get me is
1. Why this was not defined as the startup project in the .sln file.
2. Why I had to do this manually. Why does VS not look for the Main menhod and set that to the startup project?
Thanks. I now know what do in the future!!
Liam
|
|
|
|
|
My guess is that, since the startup project is only relevant to debugging (unless people normally double-click on .DLL files and sit there wondering why they didn't execute), and the person executing the solution for debugging should be able to figure out which project they'd like to execute, and should know that class libraries are not executable, the VS team opted not to add the feature.
For instance, what if your project had 20 console applications, and no class libraries at all? Should Studio randomly choose one of the console apps as the startup project? Select them all?
The startup project is actually saved in the solution options file (*.SUO), so unless you delete the file or it becomes invalid, you should only have to set it once.
I just did a little experiment with a console application and class library on my desktop. Killing the SUO file and reopening the solution resulted in the console application being chosed for startup by default every time, even if I explicitly chose the class library previously, and doesn't appear to rely on which project was added to the solution first, so I'm guessing there is at least a little intelligence in Studio for choosing...
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Hi all experts,,,,
i have a problem,that i have developed a module(window application) in which
there is a tree control.In tree control there are items in nodes of tree control.I want to select the item and do right click on that item and i got a popmenu.means that as the menu we use in our common applications which contain cut,copy etc.
Plz help me as soon as possible.
With regards
Ishtiaq Ahmed
|
|
|
|
|
Do as under:
1. In the designer mode, drag a ContextMenu control from the ToolBar to the Form (on which your TreeView control is placed). It is named as ContextMenu1.
2. Add items (as per your requirement) to this ContextMenu instance in the space provided therein (with the prompt of "Type here") as you would while building a normal menu.
3. In the designer mode itself, now select your instance of TreeView control and in its Properties window, select the ContextMenu property and assign the value of the aforesaid instance "ContextMenu1" which you have just designed.
4. Now, just compile and run it. When you right-click on a node, you'll see a popup menu with the items you just placed as above.
5. For adding functionality to the menu items in the aforesaid ContextMenu, use the eventhandler for the click event of the particular menu item.
|
|
|
|
|
hi every body,
i want to create multifile assembly that contain (c# class and access database )
c# class read some data from the database and view it by any way
i tray to make this but....
when use the dll (multifile assembly ) in another project the dll was not feel with the database that already contained in the dll........
<<< abo hassan >>>
|
|
|
|
|
The database file is not part of the compiled assembly, even if you added the file to the solution explorer. When you move the assembly to a different location, you need to move the database with it or provide a central location where the database may be accessed (a file share or something).
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
I've been trying to figure out how much of the CPU a process has been using within a time span. I need to know its usage as well as any child processes that are spawned. To get the process tree I used WMI so I can query the processes with a parent process Id.
Trouble is, I'm getting insane results. Here's my code:
<br />
<br />
Process pTool = ....<br />
<br />
ManagementScope oMs = new ManagementScope();<br />
UInt64 iPreviousTime = 0;<br />
DateTime dtPreviousTimestamp = DateTime.Now;<br />
<br />
pTool.Start();<br />
<br />
while (!pTool.HasExited)<br />
{<br />
pTool.Refresh();<br />
UInt64 iCurrentTime = (UInt64)pTool.TotalProcessorTime.Milliseconds;<br />
<br />
iCurrentTime += GetProcessTime(oMs, (uint)pTool.Id);<br />
<br />
DateTime dtNow = DateTime.Now;<br />
<br />
UInt64 iDiff = iCurrentTime - iPreviousTime;<br />
TimeSpan tsDiff = dtNow - dtPreviousTimestamp;<br />
<br />
float fPercent = (float)(iDiff) / (float)tsDiff.Milliseconds;<br />
<br />
string strDebug = string.Format("Elapsed time: {0}\tProcess time: {1} ({2})",<br />
tsDiff.TotalMilliseconds, iDiff.ToString(), fPercent.ToString());<br />
Debug.WriteLine(strDebug);<br />
<br />
iPreviousTime = iCurrentTime;<br />
dtPreviousTimestamp = dtNow;<br />
<br />
System.Threading.Thread.Sleep(1000);<br />
}<br />
<br />
private UInt64 GetProcessTime(ManagementScope oMs, uint iParentId)<br />
{<br />
ObjectQuery oQuery = new ObjectQuery("select Name,ProcessId,UserModeTime,KernelModeTime from win32_process where ParentProcessId=" + iParentId.ToString());<br />
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);<br />
ManagementObjectCollection oReturnCollection = oSearcher.Get(); <br />
UInt64 iTotalTime = 0;<br />
foreach (ManagementObject oReturn in oReturnCollection)<br />
{<br />
string strName = oReturn["Name"].ToString();<br />
uint iProcessId = uint.Parse(oReturn["ProcessId"].ToString());<br />
<br />
UInt64 iUserModeTime = UInt64.Parse(oReturn["UserModeTime"].ToString()) / 10000;<br />
UInt64 iKernelModeTime = UInt64.Parse(oReturn["KernelModeTime"].ToString()) / 1000;<br />
<br />
Debug.WriteLine("Parent: " + iParentId.ToString() + "\tProcess: " + iProcessId.ToString() + " (" + strName + ")\tTime: " + (iUserModeTime + iKernelModeTime).ToString());<br />
<br />
UInt64 iChildTime = GetProcessTime(oMs, iProcessId);<br />
<br />
iTotalTime += (iChildTime + iUserModeTime + iKernelModeTime);<br />
}<br />
return iTotalTime;<br />
}<br />
Here's the output I get in the debug window:
Parent: 5248 Process: 5984 (java.exe) Time: 530
Elapsed time: 825.2365 Process time: 576 (0.6981818)
Parent: 5248 Process: 5984 (java.exe) Time: 2046
Parent: 5984 Process: 2744 (mtwrapper.exe) Time: 0
Elapsed time: 1152.217 Process time: 1516 (9.973684)
Parent: 5248 Process: 5984 (java.exe) Time: 2359
Elapsed time: 1043.2235 Process time: 313 (7.27907)
Parent: 5248 Process: 5984 (java.exe) Time: 2421
Parent: 5984 Process: 3216 (ipconfig.exe) Time: 171
Elapsed time: 1074.3645 Process time: 233 (3.148649)
Parent: 5248 Process: 5984 (java.exe) Time: 2468
Elapsed time: 1089.935 Process time: 18446744073709551492 (2.072668E+17)
Parent: 5248 Process: 5984 (java.exe) Time: 2499
Elapsed time: 1027.653 Process time: 31 (1.148148)
As you can see, it starts off fine in the first iteration and then it seems to start going crazy. In the second iteration the java process has over 2 seconds but the elapsed time is just over a second. Further down, the huge number must mean we got a negative result. Also confusing.
Can anyone see anything really dumb that I'm doing? If not, has anyone done something like this before?
Thanks,
Michael Stone
|
|
|
|
|
If anyone's interested, I found the problem. Two stupid mistakes.
First:
<br />
UInt64 iKernelModeTime = UInt64.Parse(oReturn["KernelModeTime"].ToString()) / 1000;<br />
should be:
<br />
UInt64 iKernelModeTime = UInt64.Parse(oReturn["KernelModeTime"].ToString()) / 10000;<br />
ie, missed a zero in the divide.
Second:
<br />
float fPercent = (float)(iDiff) / (float)tsDiff.Milliseconds;<br />
shoud be:
<br />
float fPercent = (float)(iDiff) / (float)tsDiff.TotalMilliseconds;<br />
otherwise we divide by the remainder, not the total number of elapsed milliseconds.
With these changes it works quite well. Hope it's useful to someone.
Michael Stone
|
|
|
|
|