When running my program everything works fine. I then created a service and it seems like the Dir() function does not work when running in a windows service.
You can find the code underneath, using a service I never get the line 'In Do While" Running it as a normal program, everything works
Dim a As New IO.FileStream("C:\debug\MovePDF.htm", IO.FileMode.Append) Dim s As New IO.StreamWriter(a) Dim sPathOfOrigin As String = "\\becuga1\rootas400\USERS\DOCENTER\tempOrders\" Dim FileNameOrigin As String
s.WriteLine("Timer Elapsed<br>") FileNameOrigin = Dir(sPathOfOrigin) Do While FileNameOrigin <> "" s.WriteLine("In Do While<br>")
Are you sure that you don't get any exception, like a security issue ?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
Try
Dim a As New IO.FileStream("C:\debug\MovePDF.htm", IO.FileMode.Append)
Dim s As New IO.StreamWriter(a)
Dim sPathOfOrigin As String = "\\becuga1\rootas400\USERS\DOCENTER\tempOrders\"
Dim FileNameOrigin As String
s.WriteLine("Timer Elapsed<br>")
FileNameOrigin = Dir(sPathOfOrigin)
Do While FileNameOrigin <> ""
s.WriteLine("In Do While<br>")
catch ex as exception
messagebox.show ex.tostring()
end try
Under which account does the service run ? (administrative tools - services) Under your account, or under local system, ... ? If it's not running under your account, try to set it under your account and try again. If it works then, there is certainly a problem with the security-settings !
Setting my account in the service process installer to user, building the solution and trying to install, I get prompted to enter a user to install the service. Both my account (I am a member of the group administrators) and the Administrators account fail to install. According to this information (underneath) the accountname or password are wrong, but I'm sure the are correct.
logfile = c:\debug\movepdf.InstallLog Installing service MovePDF... Creating EventLog source MovePDF in log Application...
An exception occurred during the Install phase. System.ComponentModel.Win32Exception: De accountnaam is ongeldig of bestaat niet , of het wachtwoord is ongeldig voor de opgegeven accountnaam
The Rollback phase of the installation is beginning. See the contents of the log file for the c:\debug\movepdf.exe assembly's progres s. The file is located at c:\debug\movepdf.InstallLog. Rolling back assembly 'c:\debug\movepdf.exe'. Affected parameters are: logtoconsole = assemblypath = c:\debug\movepdf.exe logfile = c:\debug\movepdf.InstallLog Restoring event log to previous state for source MovePDF.
The Rollback phase completed successfully.
The transacted install has completed. The installation failed, and the rollback has been performed.