|
Thanks Vega02,
I think the root cause is, I do not know GetFields will not return methods before.
regards,
George
|
|
|
|
|
Can any body tell me how to add new windows service
wasim khan
|
|
|
|
|
You mean to say, how to install a window service or you want to create a service?
Parwej Ahamad
R & D with IIS 5.0/6.0
|
|
|
|
|
hi i have a service that is created by my friend in VB and now i want to add it my Computer Services by C# code how will i do this
wasim khan
|
|
|
|
|
You can use the ServiceInstaller class. It's part of the BCL.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Well there are certain ways to add a service to your windows registered services.
1) You can use the InstallUtil tool that comes with the .Net Framework;Go to the Visual Studio Command prompt and there type InstallUtil Path-to-Assembly-to-be-installed-as-service
This is a manual procedure.
2) Create a new setup project using the Visual Studio Setup Wizard and then under the "File System Editor" add the output (the assembly that you want to install as service", after this go to "Custom Actions Editor", you will see four folders there, 1- Install, 2- Commit, 3- Rollback and 4- Uninstall, right click on Install and click on "Add Custom Action" from the resulting menu, under the result dialog, locate the application folder and locate the assembly of the service that you just added in Application Folder, double click on this assembly.
Now when you run the setup project, the service will be added to your windows services if everything goes well.
For both the procedures, you would need to go to windows services console and start the service manually.
Muhammad Talha
|
|
|
|
|
thanx for ur breif Answere i think that will help me
wasim khan
|
|
|
|
|
Talha can u tell me about how can i add service using C# code
and thnax for ur first replay it really work
wasim khan
|
|
|
|
|
Well I also looked a sample on Code Project for this which calls the InstallUtil utility through code, I guess if you search this site for Dynamic Windows Service Installer, you will come across that....
anyway the code is as:
<br />
using System;<br />
using System.Diagnostics;<br />
using System.Net;<br />
using System.IO;<br />
<br />
namespace ServiceInstaller<br />
{<br />
public enum WindowsServiceAccountType<br />
{<br />
LocalService,<br />
NetworkService,<br />
LocalSystem,<br />
User<br />
}<br />
public class WindowsServiceInstallInfo<br />
{<br />
#region "FIELDS"<br />
<br />
private System.String _windowsServiceName;<br />
private System.String _wsDescription;<br />
private readonly string _windowsServicePath;<br />
private readonly string _windowsServiceAssemblyName;<br />
private WindowsServiceAccountType _wsAccountType;<br />
private readonly string _wsAccountUserName;<br />
private readonly string _wsAccountPassword;<br />
<br />
#endregion<br />
<br />
#region "CONSTRUCTOR"<br />
public WindowsServiceInstallInfo(string windowsServicePath, string windowsServiceAssemblyName, WindowsServiceAccountType wsAccountType)<br />
: this("", windowsServicePath, windowsServiceAssemblyName, wsAccountType) { }<br />
<br />
public WindowsServiceInstallInfo(string windowsServiceName, string windowsServicePath, string windowsServiceAssemblyName, WindowsServiceAccountType wsAccountType)<br />
: this(windowsServiceName, "", windowsServicePath, windowsServiceAssemblyName, wsAccountType) { }<br />
<br />
public WindowsServiceInstallInfo(string windowsServiceName, string description, string windowsServicePath, string windowsServiceAssemblyName, WindowsServiceAccountType wsAccountType)<br />
: this(windowsServiceName, description, windowsServicePath, windowsServiceAssemblyName, wsAccountType, "", "") { }<br />
<br />
public WindowsServiceInstallInfo(string windowsServicePath, string windowsServiceAssemblyName, string wsAccountUserName, string wsAccountPassword)<br />
: this("", windowsServicePath, windowsServiceAssemblyName, wsAccountUserName, wsAccountPassword) { }<br />
<br />
public WindowsServiceInstallInfo(string windowsServiceName, string windowsServicePath, string windowsServiceAssemblyName, string wsAccountUserName, string wsAccountPassword)<br />
: this(windowsServiceName, "", windowsServicePath, windowsServiceAssemblyName, wsAccountUserName, wsAccountPassword) { }<br />
public WindowsServiceInstallInfo(string windowsServiceName, string description, string windowsServicePath, string windowsServiceAssemblyName, string wsAccountUserName, string wsAccountPassword)<br />
: this(windowsServiceName, description, windowsServicePath, windowsServiceAssemblyName, WindowsServiceAccountType.User, wsAccountUserName, wsAccountPassword) { }<br />
<br />
private WindowsServiceInstallInfo(string windowsServiceName, string description, string windowsServicePath, string windowsServiceAssemblyName, WindowsServiceAccountType wsAccountType, string wsAccountUserName, string wsAccountPassword)<br />
{<br />
_windowsServiceName = windowsServiceName;<br />
_wsDescription = description;<br />
_windowsServicePath = windowsServicePath;<br />
_windowsServiceAssemblyName = windowsServiceAssemblyName;<br />
_wsAccountType = wsAccountType;<br />
_wsAccountUserName = wsAccountUserName;<br />
_wsAccountPassword = wsAccountPassword;<br />
<br />
if (_wsAccountType == WindowsServiceAccountType.User && _wsAccountUserName == "")<br />
{<br />
throw new Exception("Username must be provided if AccountType to start the Windows Service is USER");<br />
}<br />
}<br />
#endregion<br />
<br />
#region "PROPERTIES"<br />
public System.String WindowsServiceName<br />
{<br />
get<br />
{<br />
return _windowsServiceName;<br />
}<br />
set<br />
{<br />
_windowsServiceName = value;<br />
}<br />
}<br />
public string WindowsServiceDescription<br />
{<br />
get<br />
{<br />
return _wsDescription;<br />
}<br />
set<br />
{<br />
_wsDescription = value;<br />
}<br />
}<br />
public string WindowsServicePath<br />
{<br />
get<br />
{<br />
return _windowsServicePath;<br />
}<br />
}<br />
public string WindowsServiceAssemblyName<br />
{<br />
get<br />
{<br />
return _windowsServiceAssemblyName;<br />
}<br />
}<br />
public WindowsServiceAccountType wsAccountType<br />
{<br />
get<br />
{<br />
return _wsAccountType;<br />
}<br />
}<br />
public string wsAccountUserName<br />
{<br />
get<br />
{<br />
return _wsAccountUserName;<br />
}<br />
}<br />
public string wsAccountPassword<br />
{<br />
get<br />
{<br />
return _wsAccountPassword;<br />
}<br />
}<br />
#endregion<br />
}<br />
<br />
public class WindowsServiceInstallUtil<br />
{<br />
public static string InstallUtilPath = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();<br />
<br />
protected WindowsServiceInstallInfo _wsInstallInfo;<br />
<br />
public WindowsServiceInstallUtil(WindowsServiceInstallInfo wsInstallInfo)<br />
{<br />
_wsInstallInfo = wsInstallInfo;<br />
}<br />
private static bool CallInstallUtil(string installUtilArguments)<br />
{<br />
Process proc = new Process();<br />
proc.StartInfo.FileName = Path.Combine(InstallUtilPath, "installutil.exe");<br />
proc.StartInfo.Arguments = installUtilArguments;<br />
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;<br />
proc.StartInfo.RedirectStandardOutput = true;<br />
proc.StartInfo.UseShellExecute = false;<br />
<br />
proc.Start();<br />
<br />
string outputResult = proc.StandardOutput.ReadToEnd();<br />
proc.WaitForExit();<br />
if (proc.ExitCode != 0)<br />
{<br />
return false;<br />
}<br />
return true;<br />
}<br />
public bool Install()<br />
{<br />
return Install("");<br />
}<br />
public virtual bool Install(string logFilePath)<br />
{<br />
string installUtilArguments = GenerateInstallUtilInstallArgs(logFilePath);<br />
return CallInstallUtil(installUtilArguments);<br />
}<br />
<br />
protected string GenerateInstallUtilInstallArgs(string logFilePath)<br />
{<br />
string installUtilArguments = " /account=\"" + _wsInstallInfo.wsAccountType + "\"";<br />
if (_wsInstallInfo.WindowsServiceName != "")<br />
{<br />
installUtilArguments += " /name=\"" + _wsInstallInfo.WindowsServiceName + "\"";<br />
}<br />
if (_wsInstallInfo.WindowsServiceDescription != "")<br />
{<br />
installUtilArguments += " /desc=\"" + _wsInstallInfo.WindowsServiceDescription + "\"";<br />
}<br />
if (_wsInstallInfo.wsAccountType == WindowsServiceAccountType.User)<br />
{<br />
installUtilArguments += " /user=\"" + _wsInstallInfo.wsAccountUserName + "\" /password=\"" + _wsInstallInfo.wsAccountPassword + "\"";<br />
}<br />
<br />
installUtilArguments += " \"" + Path.Combine(_wsInstallInfo.WindowsServicePath, _wsInstallInfo.WindowsServiceAssemblyName) + "\"";<br />
<br />
if (logFilePath.Trim() != "")<br />
{<br />
installUtilArguments += " /LogFile=\"" + logFilePath + "\"";<br />
}<br />
<br />
return installUtilArguments;<br />
}<br />
<br />
public bool UnInstall()<br />
{<br />
return UnInstall("");<br />
}<br />
<br />
public virtual bool UnInstall(string logFilePath)<br />
{<br />
string installUtilArguments = GenerateIntallUtilUnInstallArgs(logFilePath);<br />
return CallInstallUtil(installUtilArguments);<br />
}<br />
<br />
protected string GenerateIntallUtilUnInstallArgs(string logFilePath)<br />
{<br />
string installUtilArgs = " /u ";<br />
if (_wsInstallInfo.WindowsServiceName != "")<br />
{<br />
installUtilArgs += " /name=\"" + _wsInstallInfo.WindowsServiceName + "\"";<br />
}<br />
installUtilArgs += " \"" + Path.Combine(_wsInstallInfo.WindowsServicePath, _wsInstallInfo.WindowsServiceAssemblyName)+"\"";<br />
if (logFilePath.Trim() != "")<br />
{<br />
installUtilArgs += " /LogFile=\"" + logFilePath + "\"";<br />
}<br />
return installUtilArgs;<br />
}<br />
}<br />
}<br />
let me know if you need further assisstance.
Muhammad Talha
|
|
|
|
|
thnax Talha i think that is enough for me
wasim khan
|
|
|
|
|
hi !
i have two project in one solution , form1 from project 1 is running and i m calling from this to prject2 form 2 like that
project2.form2 f = new project2.form2();
f.show();
on the buton of form1 call this and form is opening succesfully but when i closed the form2 then its back to form 1 , becouse form 1 is already opend then my question is that which event is fire when i got back to form1 , i checked Activated event is not working may b cumming from other project , may what is differnce b/w show and showdailogue() , when i call like f.showdailogue() ; then its just open and closed automatically .
Further Detail :
i have a image on form1 i move this image to form2 and edit that image and then save and when i return back to form1 then its should automatically update but its not updated , when i found the event then on that event in form1 i just reload the image to given path .
|
|
|
|
|
You should have to code on FormClosing event of form2 to notify your form1 that form2 is closed and than... on recieving notification u can reload your image.
|
|
|
|
|
yah i coded to on form closing event or form2 but still when i come to form1 then there is no difference in form1 picturebox control i coded like this on form2 closed event
project1.form1 g = new project1.form1();
g.picturebox.Image = null;
g.picturebox.Image = Image.FromFile(@"C:\Temp\Temp2.jpg");
g.picturebox.Refresh();
but after this coded still no differnce in form1 picture box , but when i came to form1 then i made here update button when i pressed it then its update on update button i coded
g.picturebox.Image = Image.FromFile(@"C:\Temp\Temp2.jpg");
g.picturebox.Refresh();
but i want its directly update and refresh image when i closed form2 and come to form1 .
|
|
|
|
|
nomi wrote: but after this coded still no differnce in form1 picture box
Yes, there is, but you can't see it. You have created a new instance of form1, in which you are changing the picture box.
If you want to change the picture box in the existing instance of form1, you need a reference to it in form2. Add a private variable of the type form1 to form2, and a parameter in the constructor of form2 of the type form1. Send a reference to form1 (Me) when you create the form2 instance, and in the constructor you store that in the private variable.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
please tell me the code becouse i m new in c#
|
|
|
|
|
The reason it's not updating bcz u r making a new instance.. on formclosing event but u need the already open instance.
|
|
|
|
|
mery dost i didnt i just make the object of the from and just giving the path again of the image when form2 is closed then form1 is already opened i dont do anything from form2 like this , form1.show() etc
|
|
|
|
|
you need to see your code again... u r creating a new instance of form1 instead of working with the instance in which u r expecting to see the change.
|
|
|
|
|
here is the code on project 2 form2 closed event :
CC13 is my frist project and i want to send image or update image in frmedit now tell me plz whats the problem image still not update:
protected override void OnClosed(EventArgs e)
{
if (this.appWorkspace.ActiveDocumentWorkspace != null)
{
appWorkspace.ActiveDocumentWorkspace.SetTool(null);
}
base.OnClosed(e);
//n send image to frmedit in cc13
CCI3.Forms.frmEdit s = new CCI3.Forms.frmEdit();
// s.mSetPicture(PictureBox, "true");
//s.VarEditImg
//s.VarEditSig
s.PicImage.Image = null;
s.PicImage.Image = Image.FromFile(@"C:\Temp\Temp1.jpg");
s.PicImage.Refresh();
s.picSig.Image = null;
s.picSig.Image = Image.FromFile(@"C:\Temp\Temp2.jpg");
s.picSig.Refresh();
//s.Con
s.Showimg();
CCI3.Myimg g = new CCI3.Myimg();
g.Showimg2();
//CCI3.Forms.frmEdit ss = new CCI3.Forms.frmEdit();
//ss.setEditPictures(@"C:\Temp\Temp1.jpg", @"C:\Temp\Temp2.jpg");
}
|
|
|
|
|
CCI3.Forms.frmEdit s = new CCI3.Forms.frmEdit();
above line in your code makes a new instance. i'm saying it again u need to get a already opened instance reference.
new keyword always make a new instance.
|
|
|
|
|
meri jan ma bhi yeh hi keh rha hon there is no any more instance Except of this yaaaar y u r not getting my point i only make object or instance one time and its that i send u
|
|
|
|
|
hello nomi
do not use f.show();
project2.form2 f = new project2.form2();
f.show();
use f.showDialog();
by using this ur form2 will be shown as dialog box so that u would no switch to form one until u finish ur work n form2 .
after u close form2 u will be back to ur position f.showDialog()
and just after that refresh ur image. and please do not do this think in
form activated event becoz there will be loading problem.
if this answere is helpfull then donot forget to mark
wasim khan
|
|
|
|
|
Well I guess a simple solution to the problem would be to declare a public event (say OnEditFormClosing) and when you create an instance of the Form2 (the Image Edit Form), register that event (Handler of the event) in Form1 (Original Form).
Now when you close Form2 (Edit Form), handle its 'Close Event' and from there Invoke the event (OnEditFormClosing), this will notify your Form1 that Form2 closed, as a result you can refresh the image in picture box may be by reloading or whatsoever procedure you adapt.
Regards
Muhammad Talha
|
|
|
|
|
I downloaded a file from the Internet which had 3500 lines in the file. My program consistantly stops around 2400 lines. I assume it must be a buffer problem. How can I have my program automatically adjust to the buffer size needed.
Stream data = webClient.OpenRead(downloadAddress);
StreamReader reader = new StreamReader(data);
String line;
// Read and display each line from the file by segment
while ((line = reader.ReadLine()) != null)
{
etc.,
}
I appreciate any help,
Michael
|
|
|
|
|
I have been trying to send my program as a gift to my sister, but when she tries to install the program it says that not all the files are their. I've copied all the files down to the very root part. /publish.
How do i make this work, I have tried unchecking Create Manifest in the Project Properties before you publish it and it still creates one.
This is a bad question and i can't really explain it any better. The last time i asked, about a year ago when i was scripting more often I was told to stop sending them to friends. Not really a good answer for what i really needed.
"Windows Client Error" is what my sister says the program is saying when you start setup.
|
|
|
|
|