Hi,
We are using Visual studio 2005 and .NET Framework 2.0
We have created and installed one windows service at following location
E:\XMLService
and on start of service we have called following code
System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory)
We have one "XMLTransfer.EXE" EXE at following location
E:\XMLServiceEXE
The windows service is calling "XMLTransfer.EXE" EXE using
Process.Start("E:\XMLServiceEXE\XMLTransfer.EXE")
There are some folder paths which contains the XML files. The fodlers are
E:\XMLFILES - This contains the XML files
E:\XMLFILES\Log - This contains the log file to write operation of service and "XMLTransfer.EXE" EXE
E:\XMLFILES\Archives - In this folder we copy files from E:\XMLFILES through "XMLTransfer.EXE" EXE
E:\XMLFILES\Error - In this folder we copy files from E:\XMLFILES through "XMLTransfer.EXE" EXE
The problem is when we are starting the service, "XMLTransfer.EXE" EXE not gettng the XMLFILES, Log, Archives and Error folders paths. First time it was worked successfully and "XMLTransfer.EXE" was copying files from E:\XMLFILES to the required locations. But after that it was stopped and "XMLTransfer.EXE" EXE was giving error that Archives fodler is not present though it was present. Its something working abnormally.
When we copy the "XMLTransfer.EXE" EXE at the installed location of windows service i.e. at E:\XMLService and everything was started working fine.
But we want to keep windows service and "XMLTransfer.EXE" EXE paths different. I think this is something related to service assembly path, "XMLTransfer.EXE" EXE path and other folders path.
We had developed such types of applications using .NET 1.1 but we never faced such abnormal behaviour.
Please help us in this if someone has any idea.
Thanks and Regards
Prasad
Loading
Prasad GodbolePosted Dec 22, 2011, 10:19 AM
It looks like that its working for shared path but not mapped path.
We will have to check this. Please let me know if you have any information about this.
Pravin GhadgePosted Dec 22, 2011, 1:58 AM
Try to replace
"System.AppDomain.CurrentDomain.BaseDirectory" with ur exe path folder & then check is it working properly or not.
For eg:
System.IO.Directory.SetCurrentDirectory("\\\\Comp1\\E:\\XMLTransferEXE\\bin\\Debug\\")
Prasad GodbolePosted Dec 22, 2011, 12:54 AM
I tried the mentioned solution but not giving the result.
I think something must be related to
System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory)
in EXE and it is unable to detect the shared folders
Pravin GhadgePosted Dec 21, 2011, 12:21 PM
The filename which u are trying to access from network shared path should be as follows:
For Eg: Your Shared PC Name is: Comp1 & E: is shared drive
then path should be:\\Comp1\E:\XMLFILES
try this, it may work for u.
Prasad GodbolePosted Dec 21, 2011, 8:46 AM
Thanks. But facing one problem :-(
When I created following paths on another machines and made it shared and mapped to network folder and now using these shared paths in the "XMLTransfer.EXE" then its not getting these path though the machine on which these EXE running has access to these paths. So when service is invoking this EXE, the EXE is not getting these paths.
If I directly runs the "XMLTransfer.EXE" without service then EXE is getting these shared path.
Please let me know if you have any idea to fix this problem.
Shared paths :
E:\XMLFILES - This contains the XML files
E:\XMLFILES\Log - This contains the log file to write operation of service and "XMLTransfer.EXE" EXE
E:\XMLFILES\Archives - In this folder we copy files from E:\XMLFILES through "XMLTransfer.EXE" EXE
E:\XMLFILES\Error - In this folder we copy files from E:\XMLFILES through "XMLTransfer.EXE" EXE
Thanks and Regards
Prasad
Pravin GhadgePosted Dec 21, 2011, 7:16 AM
You have made good application.
Just 1 suggestion:
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("XMLTransferEXE")
If Not pProcess Is Nothing Then
If pProcess.Length > 0 Then
For Each p As Process In pProcess
p.Kill()
Next
End If
End If
Plz don't use Kill() method. Becuase it makes OS to respond slowly.
Prasad GodbolePosted Dec 21, 2011, 4:14 AM
I have uploaded the code of service and "XMLTransfer.EXE" EXE.
Now its seems to be working fine now. But please have a look and let us know if there are any loopholes. Because previously first time it was worked and then it was stopped.
So this time it should not happen and we want to take care of this.
The "XMLTransfer.EXE" EXE is transferring XML files over HTTP so it will through error at your end and it should move your file to Error folder.
Please create structure of folders as mentioned above and put some XML files at location
E:\XMLFILES and then test it.
Thanks and Regards
Prasad
Pravin GhadgePosted Dec 21, 2011, 3:55 AM
For removing ur Path dependecy Keep ur Path in Configuration file or any external file.
So that u can access ur path from ur corresponding file.
So we don't have to hardcode in Process.Start.
Pravin GhadgePosted Dec 21, 2011, 3:09 AM
Prasad GodbolePosted Dec 21, 2011, 2:53 AM
We used
Process.Start("D:\XMLServiceEXE\XMLTransfer.EXE")
and also added System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory)
in XMLTransfer.EXE code. So its started working now.
But we want that service and XMLTransfer.EXE should access any location and perform IO operation and both should write the log file at mentioned location. The location may be same OR different. Because we want to provide facility to the user that user can mention complete "XMLTransfer.EXE" path in the configuration file and service will read it and log file location we will mention in the configuration file.
Same type of facility we will give in the XMLTransfer.EXE configuration file to mention and access Archive, Error folders etc.
So we want to develop the applications in such way that there should not be any path dependencies. Please advise if its possible.
Our code is in vb.net will it be fine for you ? Please let us know so that we will post it.
Thanks and Regards
Prasad
Pravin GhadgePosted Dec 21, 2011, 2:28 AM
can u post ur code sniffet.
Prasad GodbolePosted Dec 21, 2011, 2:17 AM
We moved EXE and given following path
Process.Start("D:\XMLServiceEXE\XMLTransfer.EXE")
But still its not working. :-(
One more thing is service is creating log file at E:\ instead of "E:\XMLFILES\Log"
Pravin GhadgePosted Dec 21, 2011, 2:07 AM
Yes u have to make changes in code.
Give any path other that ur "E:" path.
For eg:Process.Start("D:\XMLServiceEXE\XMLTransfer.EXE");
Prasad GodbolePosted Dec 21, 2011, 1:53 AM
Yes we want to keep windows service and "XMLTransfer.EXE" location different but in that case what path we will have to give in Process.Start("") and does it need any changes in code ?
Thanks and Regards
Prasad
Pravin GhadgePosted Dec 21, 2011, 1:34 AM
You are calling ur XMLTransfer.EXE using :
Process.Start("E:\XMLServiceEXE\XMLTransfer.EXE");
So it is neccessary u to keep this exe in XMLServicEXE in E: location.
Yes u can keep path of windows service & "XMLTransfer.EXE" at different location.
But u have to keep care of ur Process.Start location.