|
I don't know if I understand your problem.When you can get list of services,check the name of them if your proper names are there so they are installed,whats the problem with that?
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Hi Mazy,
Thanks for the reply.
It just seems to be a lot of work when I would have expected an exception to be returned by ServiceController to say that the service is not installed.
If you use VBA and the windows API "advapi32.dll" the QueryServiceStatus method returns an error that shows if the service is installed - surely C# has an equivalent - maybe not.
Andy
|
|
|
|
|
Well,When I want to do that I just look up in ServiceController[] which used GetServices().I look just check each ServiceName property for ServiceController[] and if its there so it is installed.Its not that muck hard or caused any expetion.And I can get the status of each service by Status prperty.
Anyway,You can use QueryServiceStatus in C# too.You can use it like the way you use other win32 functions in C# but thats very hard and boring.You can write a DLL with MC++(I GUESS you can do that with VB.NET too) and do this jon in it and then it is REALLY easy to reuse it in C#.If you want to do it in this way I can help you more.
I don't think you have any other choices,there is nothing like that in .Net framework as much as I know.
HTH
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Mazy,
Many thanks for your advice.
You have confirmed my thoughts, it just seems odd that when someone has written a class that gets a service status that one of the status conditions would not be "its not installed".
I am going to opt for using ServiceConroller[].
Regards
Andy
|
|
|
|
|
I completely agree with you. Worse there doesn't seem to be any native .NET way of getting all the information you could normally get using QueryServiceStatus() that is returned in the SERVICE_STATUS structure. .NET needs to replace the ServiceStatus enum with a class.
|
|
|
|
|
This works for me..
public bool IsInstalled()
{
try
{
string str;
ServiceController sc = new ServiceController(myServiceName);
// accessing some property will throw an exception if not installed.
str = sc.ServiceName;
}
catch (Exception)
{
return false;
}
return true;
}
|
|
|
|
|
I've written a tray based application and overridden the OnClosing where I iconify the application instead of closing it. However, when I'm trying to shut down or restart my computer the program wont shut down and the computer wont reboot or shutdown until I exit the program. I know that WIndows sends the message WM_ENDSESSION when the system goes down, but how do I handle this from my hidden application in the traybar? Or is there another simple solution of this problem
|
|
|
|
|
Is that the only method (OnClosing) you wrote an override for?
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
I've overridden OnLoad, OnResize, Dispose (that's default?) and OnClosing.
|
|
|
|
|
I hate to say it, but that's just weird. I have a similar app except minimize (rather than close) puts it in the tray and it doesn't seem to have any problem at all. So there may be something about the OnClosing method that I'm not aware of. Does your code look like this?:
protected void OnClosing(CancelEventArgs e)
{
base.OnClosing(e);
e.Cancel = true;
this.WindowState = FormWindowState.Minimized;
return;
}
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
Is this a normal app with a tray icon, or a system service, because surely the app would shut down normally as any windows form app would. The only thing I can think of is that you havn't disposed the NotifyIcon in the Dispose Override.
If its a system service then I can't help, never written one in C#.
"If you just say porn then you get all manner of chaff and low grade stuff." - Paul Watson, Lounge 25 Mar 03 "But a fresh install - it's like having clean sheets" - C. Maunder Lounge 3 Mar '03
Jonathan 'nonny' Newman
Homepage [www.nonny.com] [^]
|
|
|
|
|
Somewhere on CP there is an article you can use in the Closing event to determine why you are being closed. Use that to handle the case where windows is shutting down to exit your program.
or
pahlsson wrote:
I know that WIndows sends the message WM_ENDSESSION
Your application is still running so it should still get the WM_ENDSESSION message. You'll need to lookup the real value of WM_ENDSESSION, then override WndProc to handle it.
protected override void WndProc(ref Message m)
{
const int WM_ENDSESSION = 0x0016;
switch(m.Msg)
{
case WM_ENDSESSION:
bool sessionEnding = (bool) m.WParam;
m.Result = 0;
break;
default:
base.WndProc(ref m);
}
} However, MSDN says "The application need not call the DestroyWindow or PostQuitMessage function when the session is ending." so I don't think this is a suitable addition without my first suggestion implemented.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Thanks for your answers, you have given me some new ideas to try out. However I have another problem now. When the app is to execute, I get an exception :-/
The exceptions says "Error creating window handle" at the Application.Run(); in main. It didn't yesterday
|
|
|
|
|
Ah, solved it... my misstake
|
|
|
|
|
Hello..
I want to make Directory Dialog Box not File Dialog Box..
(It means I want get Directory name When I select Directory name in the dialog. You Know!!)
However I hardly know How to make it.
Is there anyone can help me?
Thanks..
I'm not who I was
|
|
|
|
|
Using the .Net 1.1 SDK you can just use the
System.Windows.Forms.FolderBrowserDialog.
If you are using the 1.0 SDK you can inherit from
System.Windows.Forms.Design.FolderNameEditor.
This implementation will most likely require that you use a
FolderNameEditor.FolderBrowser.
I have a class already written that can do this job if you like.
Also, I think there is at least one implementation posted here on CP.
Hey don't worry, I can handle it. I took something. I can see things no one else can see. Why are you dressed like that?
- Jack Burton
|
|
|
|
|
By using FolderNameEditor class and FolderBrowser class u can make Directory Dialog Box.
public class DirBrowser : FolderNameEditor
{
FolderBrowser fb = new FolderBrowser();
public string DirectoryPath
{
get
{
return strDirectoryPath;
}
}
public DirBrowser() { }
public DialogResult ShowDialog()
{
fb.Description = "Choose Directory";
fb.StartLocation = FolderBrowserFolder.MyComputer;
fb.Style = FolderBrowserStyles.RestrictToFilesystem;
DialogResult dlgResult = fb.ShowDialog();
if (dlgResult == DialogResult.OK)
strDirectoryPath = fb.DirectoryPath;
else
strDirectoryPath = "";
return dlgResult;
}
private string strDirectoryPath = "";
}
Instaniate DirBrowser class, call ShowDialog function and use DirectoryPath property to get the directory path :-
DirBrowser obDirBrowser = new DirBrowser();
obDirBrowser.ShowDialog ();
txtLogFilePath.Text = obDirBrowser.DirectoryPath ;
Chito.
|
|
|
|
|
http://www.codeproject.com/cs/miscctrl/folderbrowser.asp[^]
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Hi guys,
I want to change title bar color, but I am doing something wrong. So please, if anybody knows what it is, it would be good to let me know.
I declare:
using System.Runtime.InteropServices;
then I import API:
[DllImport("user32.dll")]
public static extern int SetSysColors(int nChanges, int lpSysColor, int lpColorValues);
[DllImport("user32.dll")]
public static extern int GetSysColor(int nIndex);
and then I call it this way:
int iRes = GetSysColor(4);
MessageBox.Show("Result: " + iRes.ToString());
iRes = SetSysColors(0, 4, 14898176);
MessageBox.Show("Result: " + iRes.ToString());
The first message box returns 16777215 which is a color of the menu (number 4 is the constant for menu), so it means GetSysColor function works, but the second function returns 0, which means it failed, and color of the menu does not change.
Why is that? Am I missing something obvious?
Thanks for your answers.
.
|
|
|
|
|
You have two problems. Firstly, the first parameter to SetSysColors is the number of colours you are changing, so it should be 1 instead of 0. Secondly, the second and third parameters should be passed by reference rather than by value (they are actually both pointers to the first element of an array). Changing the declaration to
[DllImport("user32.dll")]<br />
public static extern int SetSysColors(int nChanges, ref int lpSysColor, ref int lpColorValues);
and the call to
int iElement = 4;<br />
int iColor = 13160660;<br />
iRes = SetSysColors(1, ref iElement, ref iColor);
should make things work.
Chris Jobson
|
|
|
|
|
Yes, that worked, the problem was in passing the parameters.
Thanks man.
.
|
|
|
|
|
Hi Everyone,
Forgive the "1st Year Question" but, I have been struggling with this for a few days.
I am trying to build a SQL statment depending on if a Field is Empty of not.
This is the code that I am having trouble with.
It Compiles but it never gets to the "else if" statment.
I have an warning "Unreachable Code Detected" under "this" on the line that builds my sql statment.
[code]
if(("@LName" != "") && ("@City != ""))
{
this.sqlSelectCommand1.CommandText = "Select * from db where name LIKE @LName + \'%\') AND (city = @City) ORDER 5. BY name";
}
else if(("@LName" != "") && ("@City == ""))
{
Here--->this.sqlSelectCommand1.CommandText = "Select * from db where name LIKE @LName + \'%\') ORDER BY name";
}
[end]
Can Anyone tell me what is going on. Or if there is a better way of building SQL statments depending on the Data Entered?
Thank, Vinkoval
|
|
|
|
|
Is some code missing there? You are comparing one string literal to another, so the compiler knows that "@LName" will never equal "" and "@City" will never equal ""* so the first block of the if..else will always be executed.
I expected to see some other code like, if(LName != "" && City != "") where LName and City are variables, THEN the code should work as you assume.
*actually, you have a compiler error there because of an unterminitated string constant.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Thank James,
I hate to be a bother, but....
I tried what you suggested and Im sure it would work if I did it correctly,
but it seems to have the same effect as before i.e Only the First bolc of if..else is executed.
If it wouldn't be too much trouble.. The code that was missing from my previous post is here : http://www.ubtanet.com/example/example.php[^]
If you or anyone else that might be able to help point out the error of my ways.. I would really apprciate it.
Thanks
Vinkoval
|
|
|
|
|
k, the problem is that your if is checking a general case before a specific one; which is why the first part is always executed.
Specifically:
if( ... && City != "" ) the block following this will always be executed, unless City == "" . The first block is executed even when City == null because null and "" are two different values so the first condition is met.
To correct this you need to switch the order of the two if statements. i.e. compare for null first, then compare for the empty string.
HTH,
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|