Question : vbscript exit if file exists

I have a vb script that configures outlook. It runs on roaming profiles
I need it to only run once. If it runs a second time uers lose all there outlook settings.

The file will be:
\\servername\users\username.domainname\Application Data\Microsoft\Outlook\Outlook.NK2

if this file exeists they have already configured outlook.

My script is attached.  SO basically it bypasses what I have if this file exists.

Thanks
1:
2:
3:
4:
5:
6:
7:
' VBScript that will disable outlook profile wizard and create a an outlook profile
'
Set WSHShell = WScript.CreateObject("WScript.Shell")
On Error Resume Next
WshShell.RegDelete "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Setup\FirstRun"
WshShell.RegDelete "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Setup\First-Run"
WSHShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Setup\ImportPRF","c:\outlook.prf","REG_SZ"

Answer : vbscript exit if file exists

If I have misread your requirements, then maybe this is all you need

            SET @CustomOrder = @CustomOrder + 'ISNULL([' + CONVERT(NVARCHAR,@dateFROM,103) + '],999999999) DESC,'

But if the requirements are correct as above, then try the code below.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
ALTER PROCEDURE [dbo].[spGetWeeklyTimesheet]
	@dateFROM datetime,
	@dateTO	datetime,
	@StaffID	nvarchar(5)
AS

DECLARE @sql nvarchar(max)
DECLARE @dateFROMReset datetime
DECLARE @sqlSUM nvarchar(max)
DECLARE @CustomOrder nvarchar(max)	
DECLARE @CustomOrder2 nvarchar(max)	

SET @dateFROMReset = @dateFROM
SET @sqlSUM = ''
SET @CustomOrder = ''
SET @CustomOrder2 = ''

WHILE @dateFROM<=@dateTo
	BEGIN
		SET @CustomOrder = @CustomOrder +
			'case when [' + CONVERT(NVARCHAR,@dateFROM,103) + '] is null then 1 else 0 end,'
		SET @CustomOrder2 = @CustomOrder2 +
			'[' + CONVERT(NVARCHAR,@dateFROM,103) + '],'
		SET @sqlSUM = @sqlSUm + 
		 ' sum( case when CONVERT(NVARCHAR,StartTime,103) = ''' + CONVERT(NVARCHAR,@dateFROM,103) + ''' then hours else NULL end)
			as [' +  CONVERT(NVARCHAR,@dateFROM,103) + '],
			sum( case when CONVERT(NVARCHAR,StartTime,103) = ''' + CONVERT(NVARCHAR,@dateFROM,103) + ''' then overtime else NULL end)
			as [' + CONVERT(NVARCHAR,@dateFROM,103) + '-OVER],'

		IF @dateFROM = @dateTO -- remove last comma.
			SET @sqlSUM =  Left(@sqlSUM, Len(@sqlSUM)-1)
		
		SET @dateFROM = @dateFROM + 1
	END

SET @CustomOrder = @CustomOrder + @CustomOrder2

SET @sql = 'SELECT ' +
@sqlSUM + ', CASE 
            WHEN T.JobID <=0 THEN T.TenderID 
            ELSE T.JobID 
      END as JobTenderID, 
      CASE  
            WHEN T.JobID <=0 THEN Te.TenderNumber 
            ELSE J.Job 
      END as Job, 
T.taskid,T.description,Tk.Task,T.JobID,T.StaffID,S.StaffFullName,Tk.SortCol,T.StartTimeExcel,T.EndTimeExcel,T.AccompaniedBy
FROM timesheet as T
LEFT JOIN Jobs as J ON T.JobID = J.ID 
LEFT JOIN Tasks as Tk ON T.TaskID = Tk.ID
LEFT JOIN Tender as Te ON Te.ID = T.TenderID
LEFT JOIN Staff as S ON T.StaffID = S.ID
WHERE CONVERT(NVARCHAR,StartTime,101) >= '''  + CONVERT(NVARCHAR,@dateFROMReset,101) + '''
 AND  CONVERT(NVARCHAR,StartTime,101) <=  ''' + CONVERT(NVARCHAR,@dateTO,101) + '''
 AND T.StaffID =' + @StaffID + '
GROUP BY t.jobid,t.taskid,t.description,j.job,tk.task,T.TenderID,Te.TenderNumber,T.StaffID,S.StaffFullName,
Tk.SortCol,T.StartTimeExcel,T.EndTImeExcel,T.AccompaniedBy
ORDER BY ' + @CustomOrder + 'tk.SortCol,Job'

print @CustomOrder

exec (@sql)
Random Solutions  
 
programming4us programming4us