[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using Scripts to open programs at logon

Posted on 2007-08-08
29
Medium Priority
?
728 Views
Last Modified: 2013-11-05
Hello all,

Currently we use a logon batch file to map network drives on client computers.  I been asked to execute programs at logon time such as a Power Point Slide or a Word Document to relay important info or events happening to our users.

Here is my question:
First off I don't know much about writing windows scripts and second I don't know if I can make the script smart enough so I don't have to administer what is being opened. For example I want to make a folder on our file server where HR and Safety Dept can put their files to be opened at logon time.  Some of these files will need to keep being opened at logon time to inform of some event for a couple of days.  I was thinking maybe in the file name, they can specify how many days to keep opening this file.

Can a script be written so it looks in a folder, opens the content by the somehow specifying a number of days to open, and if it's sees nothing new to open it won't?

Like I said I don't know much about windows scripting and I'm not sure what it can and can't do.  Could you guys advise or point me in the right direction?
0
Comment
Question by:ozzalot
  • 11
  • 10
  • 3
  • +2
29 Comments
 

Author Comment

by:ozzalot
ID: 19654335
Ahh i forgot to mention this is on a Win 2k3 server and XP client computers, opening office 2003 programs.  
0
 
LVL 17

Expert Comment

by:Tony Massa
ID: 19654513
Really, you should set up an intranet site, and open an Internet Explorer session that point to the page...

Having said that, here are a couple examples (VBScript):

Open a Word Doc:

Set objWord = CreateObject("Word.Application")
objWord.Visible = True

Set objDoc = objWord.Documents.Open("\\Server\shared\YourDoc.doc",,TRUE)


Open an Excel Doc:

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True

Set objDoc = objExcel.Documents.Open("\\Server\shared\YourDoc.xls",,TRUE)


-TM
0
 
LVL 17

Expert Comment

by:Tony Massa
ID: 19654563
This script will only open the file, if it exists, else, it won't do anything


Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists("\\Server\shared\YourDoc.doc") Then
      Set objWord = CreateObject("Word.Application")
  objWord.Visible = True
      
      Set objDoc = objWord.Documents.Open("\\Server\shared\YourDoc.doc",,TRUE)
End If


-TM
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:SteveGTR
ID: 19654628
You could do something like this.

The processing uses the file's date and the number of days to keep as being encoded as:

file name.number of day.file extension

So if you had a file name like test.txt it would be formatted as:

temp.1.txt

You'd need to change the baseDir environment variable and the mask to your liking. Also, you'd have to change the command to process the file. Currently it just echo's out the file name:

@echo off

setlocal

set baseDir=c:\temp\temp\test
set fileMask=*.*

call :GETDATEPARTS "%date%"

set cyy=%yy%
set cmm=%mm%
set cdd=%dd%

pushd "%baseDir%"

for /f "tokens=*" %%a in ('dir /b /a-d "%fileMask%" 2^>NUL') do call :PROCESS "%%a" %%~ta

popd

goto :EOF

:PROCESS

set numDays=

for /f "tokens=2 delims=." %%a in ('echo %~n1') do set numDays=%%a

if "%numDays%"=="" goto :EOF

set fileName=%~1

call :GETDATEPARTS "%~2"

set fileDate=%yy%%mm%%dd%

set yy=%cyy%
set mm=%cmm%
set dd=%cdd%

call :SUBTRACTDAYS %numDays%

if /i "%yy%%mm%%dd%" GTR "%fileDate%" goto :EOF

REM ** Change command here
echo Do processing on %fileName%

goto :EOF

:GETDATEPARTS

set dt=%~1
set tok=1-3

if "%dt:~0,1%" GTR "9" set tok=2-4

set yyyy=

for /f "tokens=%tok% delims=.:/-, " %%a in ('echo %~1') do (
  for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do set %%x=%%a&set %%y=%%b&set %%z=%%c
)

if not "%yyyy%"=="" set yy=%yyyy%

if 1%yy% LSS 1000 (if %yy% LSS 70 (set yy=20%yy%) else (set yy=19%yy%))
if 1%mm% LSS 100 set mm=0%mm%
if 1%dd% LSS 100 set dd=0%dd%

goto :EOF

:SUBTRACTDAYS

set dayCnt=%1

if "%dayCnt%"=="" set dayCnt=1

REM Substract your days here
set /A dd=1%dd% - 100 - %dayCnt%
set /A mm=1%mm% - 100

:CHKDAY

if /I %dd% GTR 0 goto DONESUBTRACT

set /A mm=%mm% - 1

if /I %mm% GTR 0 goto ADJUSTDAY

set /A mm=12
set /A yy=%yy% - 1

:ADJUSTDAY

if %mm%==1 goto SET31
if %mm%==2 goto LEAPCHK
if %mm%==3 goto SET31
if %mm%==4 goto SET30
if %mm%==5 goto SET31
if %mm%==6 goto SET30
if %mm%==7 goto SET31
if %mm%==8 goto SET31
if %mm%==9 goto SET30
if %mm%==10 goto SET31
if %mm%==11 goto SET30
REM ** Month 12 falls through

:SET31

set /A dd=31 + %dd%

goto CHKDAY

:SET30

set /A dd=30 + %dd%

goto CHKDAY

:LEAPCHK

set /A tt=%yy% %% 4

if not %tt%==0 goto SET28

set /A tt=%yy% %% 100

if not %tt%==0 goto SET29

set /A tt=%yy% %% 400

if %tt%==0 goto SET29

:SET28

set /A dd=28 + %dd%

goto CHKDAY

:SET29

set /A dd=29 + %dd%

goto CHKDAY

:DONESUBTRACT

if /I %mm% LSS 10 set mm=0%mm%
if /I %dd% LSS 10 set dd=0%dd%

goto :EOF
0
 

Author Comment

by:ozzalot
ID: 19654636
Thanks for your your examples TM.  The biggest question i have is if it can open files by the number of days the file needs to be opened, otherwise don't open anything, instead of specifying the file name.  i have a simple batch file that can do that but i have to specify the file name.  This is where i was saying maybe in the file name it could specify between what days to open, i.e.  "20070808_20070810_event.doc" or something to that effect.  The script would see that it needs to open this file during these days.
0
 
LVL 3

Expert Comment

by:vladh
ID: 19654744
Try the following VBscript.
You can launch it through a GPO (if you're using Active Directory or through some other startup mechanism. Copy this to a text file and use

cscript scriptfile.vbs

to start it

'-------------------------------------------8<-----------------------------------------------------------------------
' this is your file to open. Make sure to open it with the correct app
strfiletorun = "c:\testfile.txt"
strCommandLine = "c:\windows\notepad.exe c:\testfile.txt"

' This is the number of days to keep opening the file since it was
' created. Note that if the file was created Monday, and the user
' logs in Friday for the first time that week, it won't show -
' you need a mechanism to track the actual user views as opposed to
' just comparing dates
intDaysToOpen = 3


Set WshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strfiletorun)

Wscript.Echo "Date file created: " & objFile.DateCreated
dtCreationDate = objFile.DateCreated
      
if DateDiff("d", Now, dtCreationDate ) <= intDaysToOpen then
      wscript.echo "Date Difference: " & DateDiff("d", Now, dtCreationDate )
      Set oExec = WshShell.Exec(strCommandLine )
end if

set objFSO = nothing
set WshShell = nothing
'-------------------------------------------8<-----------------------------------------------------------------------



0
 

Author Comment

by:ozzalot
ID: 19654755
Steve could you point to somewhere where I can research what you posted? i like the code you posted, but only partially understand it.  you have the right idea as to what i wanted to with the file name.  I hate just coping other people's code and would rather understand it and maybe modify it or write my own.
0
 
LVL 3

Expert Comment

by:vladh
ID: 19654776
ozzalot:

you can easily parse file names to check for specific date ranges embedded in the file name string... As long as you're consistent with the naming of your files, of course.  Give me an example of the format you'd like to use and I can script that for you.

Vlad
0
 

Author Comment

by:ozzalot
ID: 19654876
thanks vlad,

File name format would probably be "filename.numberofdays.extension"

What my manager was suggesting was "filename.daystobeopened.extension" where daystobeopened would be yyyymmdd-yyyymmdd or something to that effect. that way they can place a file in this folder but it wouldn't be opened unless the actual date matched the time frame specified in the filename, but i don't know if something like this would be possible.
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 19654881
Each command offers help at the command line. I use it all the time. It took me a while to understand the for statement.

for /?

if /?

I find it a good exercise to write simple little batch files that help me to understand what something is doing.
0
 
LVL 17

Expert Comment

by:Tony Massa
ID: 19654975
Just change the first two lines to specify the date range when you'd like to run the file(s)



'Change the dates below
dtmStartDate = #8/1/2007#
dtmEndDate = #8/9/2007#
dtmTargetDate = Date()

Set objFSO = CreateObject("Scripting.FileSystemObject")

'Continue if the current date falls within the current specified range
If dtmTargetDate >= dtmStartDate AND dtmTargetDate <= dtmEndDate Then
      
'Check to see if file exists first, then open
      If objFSO.FileExists("\\Server\Share\YourDoc.doc") Then
        Set objWord = CreateObject("Word.Application")
        objWord.Visible = True
        Set objDoc = objWord.Documents.Open("\\Server\Share\YourDoc.doc",,TRUE)
      End If
End If
0
 
LVL 3

Expert Comment

by:vladh
ID: 19655537
ozzalot:

here's your script. May I suggest you change your file naming date portion to 2007 Aug 08 instead of 20070808
It's more descriptive for you and easier to code for me :)

'-------------------------------- 8< --------------------------------

' this assumes the file is named
' filename.daterange.ext
' DOT is used as a separator (important!)
' Date range should be specified in the following format:
' yyyy mmm dd-yyyy mmm dd
'
' where mmm is the 3-character month abbreviation such as Aug
'
' example filename:
'
' "Weekly news.2007 Aug 5-2007 Aug 9.doc"
'


strFileToOpen = ""
strCommandLine = ""

' a flag to set if the filename is within range
blWithinRange = false


dtTodaysDate = DateValue(Date())

Set WshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")

' C:\files is where your files are. Change it to your location
Set f = fso.GetFolder("C:\files")
Set fc = f.Files
   For Each f1 in fc

      ' extract date range and extention from filename
      tempArray = split(f1.name, ".")
          strDateRange = temparray(1)
      strType = temparray(2)
      
      tempArray2 = split( StrDateRange, "-")
      dtStartDate = DateValue( tempArray2(0) )
      dtEndDate = DateValue( tempArray2(1) )

      
      If dtTodaysDate >= dtStartDate AND dtTodaysDate <= dtEndDate Then
            blWithinRange =TRUE
      else
            blWithinRange =FALSE
      end if
'      wscript.echo blWithinRange
      

      ' if date within range, determine the type of app and form command line
      if blWithinRange=TRUE then
            if UCase(strType) = "DOC" then
                  strCommandLine = "C:\Program Files\Microsoft Office\Office10\winword.exe " & Chr(34) & f1.path & Chr(34)
            elseif UCase(strType) = "PPT" then
                  strCommandLine = "C:\Program Files\Microsoft Office\Office10\powerpnt.exe " & Chr(34) & f1.name & Chr(34)
            elseif UCase(strType) = "XLS" then
                  strCommandLine = "C:\Program Files\Microsoft Office\Office10\EXCEL.EXE "  & Chr(34)& f1.name & Chr(34)
            end if

'            wscript.echo strCommandLine

            ' run the app
            Set oExec = WshShell.Exec(strCommandLine )


      end if
   next


set FSO = nothing
set WshShell = nothing

'--------------------------------------------------8< ---------------------------------
0
 

Author Comment

by:ozzalot
ID: 19656598
thank you for your code vladh.  I will try it out and post my results
0
 

Author Comment

by:ozzalot
ID: 19657172
Hey vladh, your code seems to work pretty good recognizing the dates of when the file should be opened. thank you.

I have some questions tho,  do you have to declare what program to open the file with?

I couldn't open a power point slide show so i copied/paste part of the code and modified it a bit like so:
 elseif UCase(strType) = "PPS" then
                  strCommandLine = "C:\Program Files\Microsoft Office\Office11
\pptview.exe " & Chr(34) & f1.name & Chr(34)

But i keep getting an error in power point saying it can't find the file "weekly report.2007 aug 6-2007 aug 9.pps"  If add a .ppt file it opens up.  Keep in mind I somewhat understand the script but I don't know how any of the syntax should be.

Is it possible to skip a file if it is not in the correct format?  i had trouble running the script since i had it in the same folder until it dawned on me that it was looking at that as well.

0
 
LVL 3

Expert Comment

by:vladh
ID: 19658032
ozzalot, I rewrote the script to check for file type first and if the file is not one of the recognized types, it will ignore it. PowerPoint now opens the file properly (had to specify full path to file)

if you want to add another file type, all you need to do is copy and paste these lines:
      elseif UCase(strType) = "PPT" then
            strCommandLine = "C:\Program Files\Microsoft Office\Office10\powerpnt.exe " & Chr(34) & f1.path & Chr(34)

into the IF statement and modify them as required. As you can see strCommandLine contains the path to the program to execute and its parameters, filename to open being one of them. Chr(34) puts a quote mark in the file name (can not use the character itself because VB thinks its a string marker)


Please try it and let me know if it works for you
Thanks
Vlad

'--------------------------------------------------8<----------------------------------------------
' Date range should be specified in the following format:
' yyyy mmm dd-yyyy mmm dd
'
' where mmm is the 3-characted month abbreviation such as Aug
'
' example filename:
'
' "Weekly news.2007 Aug 5-2007 Aug 9.doc"
'


strFileToOpen = ""


' a flag to set if the filename is within range
blWithinRange = false


dtTodaysDate = DateValue(Date())

Set WshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")

' C:\files is where your files are. Change it to your location
Set f = fso.GetFolder("C:\files")
Set fc = f.Files
   For Each f1 in fc

      ' extract date range and extention from filename
      tempArray = split(f1.name, ".")
      strType = temparray(UBound(tempArray))

      strCommandLine = ""

      if UCase(strType) = "DOC" then
            strCommandLine = "C:\Program Files\Microsoft Office\Office10\winword.exe " & Chr(34) & f1.path & Chr(34)
      elseif UCase(strType) = "PPT" then
            strCommandLine = "C:\Program Files\Microsoft Office\Office10\powerpnt.exe " & Chr(34) & f1.path & Chr(34)
      elseif UCase(strType) = "XLS" then
            strCommandLine = "C:\Program Files\Microsoft Office\Office10\EXCEL.EXE "  & Chr(34) & f1.path & Chr(34)
      end if

'      wscript.echo strCommandLine
      if strCommandLine<>"" then
                strDateRange = temparray(1)
            tempArray2 = split( StrDateRange, "-")
            dtStartDate = DateValue( tempArray2(0) )
            dtEndDate = DateValue( tempArray2(1) )

      
            If dtTodaysDate >= dtStartDate AND dtTodaysDate <= dtEndDate Then
                  blWithinRange =TRUE
            else
                  blWithinRange =FALSE
            end if
'            wscript.echo blWithinRange
      

            ' if date within range, determine the type of app and form command line
            if blWithinRange=TRUE then
                  ' run the app
                  Set oExec = WshShell.Exec(strCommandLine )
      
            end if
      end if
   next


set FSO = nothing
set WshShell = nothing

'------------------------------------------8<---------------------------------------------------------
0
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 200 total points
ID: 19659841
Hi vladh, your code look to do the job, but rather than worry about which program needs to open which file, can you just use:

Set objShell = CreateObject("WScript.Shell")
objShell.Run """c:\temp\Corporate Calendar - Strategic Planning.xls""", 1, False

for all files, and let Windows handle the program choosing?

Regards,

Rob.
0
 

Author Comment

by:ozzalot
ID: 19661530
Vladh your code works great!!

I like Rob's idea of letting windows handle opening the file.  I don't understand your code rob, I can put that in, in place of the statements saying what program to open the file with?
0
 
LVL 3

Accepted Solution

by:
vladh earned 1800 total points
ID: 19662624
here's V.3.0 - simplified and incorporates Robs suggestion to let Windows pick the app based on file type. I actually tried this approach with WshShell.Exec and it complained - "not a valid Win32 app"... But  WShShell.Run works just fine.


'------------------------------------------8<---------------------------------------------------------
' this assumes the file is named
' filename.daterange.ext
' DOT is used as a separator (important!)
' Date range should be specified in the following format:
' yyyy mmm dd-yyyy mmm dd
'
' where mmm is the 3-characted month abbreviation such as Aug
'
' example filename:
'
' "Weekly news.2007 Aug 5-2007 Aug 9.doc"
'

dtTodaysDate = DateValue(Date())
Set WshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")

' C:\files is where your files are. Change it to your location
Set f = fso.GetFolder("C:\files")
Set fc = f.Files
   For Each f1 in fc
      ' extract date range and extention from filename
      tempArray = split(f1.name, ".")
      strType = temparray(UBound(tempArray))

      strCommandLine = ""

      if       UCase(strType) = "DOC" OR _
            UCase(strType) = "PPT" OR _
            UCase(strType) = "XLS" then
                  strCommandLine = Chr(34) & f1.path & Chr(34)
      end if
'      wscript.echo strCommandLine
      if strCommandLine<>"" then
                strDateRange = temparray(1)
            tempArray2 = split( StrDateRange, "-")
            dtStartDate = DateValue( tempArray2(0) )
            dtEndDate = DateValue( tempArray2(1) )
      
            ' if date within range, then run the app
            If dtTodaysDate >= dtStartDate AND dtTodaysDate <= dtEndDate Then
                  WshShell.Run strCommandLine, 1, False
            end if
      end if
   next

set FSO = nothing
set WshShell = nothing
'------------------------------------------8<---------------------------------------------------------

0
 
LVL 3

Expert Comment

by:vladh
ID: 19662806
and yes - thanks Rob ;)
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 19666663
@vladh, no problem ;-)

@ ozzalot,
To try to explain my code:
' This just creates a reference to the Windows Shell object, which exposes
' such methods as Run and Exec, allowing you to run programs, using the
' Windows Shell.  I'm not really sure why the Exec method, as vladh had tried,
' did not work, but I guess it's just not designed that way.
' From this link to the Run method: http://msdn2.microsoft.com/en-US/library/d5fk67ky.aspx
' comes this: "If a file type has been properly registered to a particular program,
' calling run on a file of that type executes the program. For example, if Word is installed
' on your computer system, calling Run on a *.doc file starts Word and loads the document."
Set objShell = CreateObject("WScript.Shell")
' This line below just calls the Run method mentioned above, with the second parameter
' meaning the window should be visible (0 to be hidden, there are others)
' and the False meaning the script will not wait for the application to finish before continuing.
objShell.Run """c:\temp\Corporate Calendar - Strategic Planning.xls""", 1, False


So, that's the two lines explained, I hope that makes sense.

Regards,

Rob.
0
 

Author Comment

by:ozzalot
ID: 19669254
Sorry i've been away.  thanks for program and explanation it makes a bit more sense to me.

What I don't understand is how arrays work here.

From the little C++ knowledge i have i'm used to accessing array elements by their index, but it doesn't seem like you do that here, as in the case when it check what kind of extension it is .doc, .ppt, or .xls.  It looks to me that as long as it's a one of the mentioned extensions it puts it in this "strCommandLine" string to be opened.  It doesn't matter what the name scheme is just as long as it meets the extension requirements.  I'd like to maybe put some condiitions that it checks for 2 "dots" and maybe a date scheme, but i'm having trouble understanding how arrays work here.  Can you guys advise?
0
 
LVL 3

Expert Comment

by:vladh
ID: 19669372
here's the line-by-line explanation:

 ' extract date range and extention from filename by splitting the filename onto different substrings with a "." (DOT) as a separator.

      tempArray = split(f1.name, ".")

' Here I am accessing the LAST item in the array:  UBound (tempArray) since I know that the extention comes last in the filename. I then use the resulting string to determine if I should open this file or ignore it
      strType = temparray(UBound(tempArray))

' here I clear the command line string. I later use it as a flag to see if I should ignore a file or execute it
      strCommandLine = ""


' lets see if the file type is the one I want to run:
      if       UCase(strType) = "DOC" OR _
            UCase(strType) = "PPT" OR _
            UCase(strType) = "XLS" then

' and if it is, build a command line consisting of the full file path enclosed in double quotes. Otherwise strCommandLine remains empty and used in the next test to determine whether to open that file or not
                  strCommandLine = Chr(34) & f1.path & Chr(34)
      end if
'      wscript.echo strCommandLine

' so if it isn't empty, that means I have the file I want.
      if strCommandLine<>"" then

' now I am accessing the second (1) element of the temparray (arrays start counting at 0) to get the date range string - please be consistent with the naming of your files or the script may break here
                strDateRange = temparray(1)

' here I use the same technique and split the date range on two substrings with "-" as a  separator
            tempArray2 = split( StrDateRange, "-")

' and convert the dates (please be consistent with the file naming! ;)
            dtStartDate = DateValue( tempArray2(0) )
            dtEndDate = DateValue( tempArray2(1) )

and the rest is easy... if the date is within range, fire it up, else move along, nothing to see here....

hope that clears it up a bit
Vlad
0
 

Author Comment

by:ozzalot
ID: 19670608
thanks for the explanation.  It makes more sense now.  Somethings are still a bit fuzzy but i can probably do a google search and answer them.  Any book or website you recommend to teach myself vbscript?

I remember from C++ i could see how the variables were changing or manipulated.  Here kinda like in batch files, i'm kind of flying blind and trying to debug off the errors i get after i run the program.  Is there anyway I can check that?

lastly, I just started as a network admin. I have no real experience in this field, hell I didn't even study this, but somehow i am keeping this network up and running.  How important is it to know VBscript?  I'm trying to learn as much as i can and separating time to focus on different aspects of networking.   I'm not sure if i will use another VBscript again.  I'm just wondering if they are used alot in networking and if it would be wise to know it?  I kinda got off lucky by you guys writing the program for me, but I don't want to rely on that.  can you guys advise?
0
 
LVL 3

Expert Comment

by:vladh
ID: 19670818
VBScript is VERY useful in managing MS$ systems. It should be fairly easy for you to learn VBScript especially because you have some C++ experience. Google is your friend and there are TONS of VBScript resources, including ready scripts and tips - your only problem will be "which link do I click on first"... ;)
Here are some for starters (and the ones I use on a regular basis:)


http://msdn2.microsoft.com/en-us/library/t0aew7h6.aspx

http://msdn2.microsoft.com/en-us/library/ms950396.aspx

http://www.devguru.com/Technologies/vbscript/quickref/functions.html

http://www.microsoft.com/technet/scriptcenter/createit.mspx
The above link has a few VERY useful downloadables - look for "Portable Script Center" and "Windows Scripting Technologies" - these two are a must...

http://www.activexperts.com/activmonitor/windowsmanagement/scripts/

This should give you a good start....
0
 
LVL 3

Expert Comment

by:vladh
ID: 19670842
and as far as the errors... what errors do you get?
0
 

Author Comment

by:ozzalot
ID: 19672568
well for example i didn't know how its accesses the elements in the array, or how you are doing the comparison.  if i had a file called "news.ppt" it would try to open it because it passed your check extension condition and i would get an error on this line:

dtStartDate = DateValue( tempArray2(0) )

I interpret the above line as saying you are changing what is in tempArray2 at index 0 or start of the array and converting to DateValue data type and then assigning this value to the dtStartDate variable.  again this is from my the little i know of c++

This is why I wanted to somehow check to make sure  the file to be opened had the right name scheme, otherwise just skip it, no matter if it was a .doc .ppt or .xls.

Again I know vbscript and i'm used to having to declare stuff before using it. I just read that, that is not the case in vbscript.  
0
 
LVL 3

Expert Comment

by:vladh
ID: 19672650
You can add a simple check for the number of elements in temparray (under your naming scheme there should be 3 (coded as Ubound(TempArray)=2) - descriptive name, date range and extention all separated by dots)...  It could look something like

      if (strCommandLine<>"") and (UBound(tempArray)=2)  then  

As far as variable declaration, you can use "Option Explicit" directive at the beginning of your code and then you will need to declare each variable before using it with Dim statement. If you don't use "Option Explicit" then you can declare the variables as you use them
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 19680535
Also, for VBScript examples, have a look at the Hey, Scripting Guy articles on the Microsoft website.  And, for editing scripts, you can't go past VBSEdit 3.3 from www.vbsedit.com for a free, terrific editor, which includes all of the MSDN examples, and plenty of helping scripts.

You can pay for VBSEdit and unlock the debugger in it, which help you "track" the manipulation of variables similar to a C++ IDE, or if you're paying, you can check out PrimalScript as well.

Also, as I don't use a debugger, I just place "MsgBox variablename" at various points throughout the script, where I know they will change....

Regards,

Rob.
0
 

Author Comment

by:ozzalot
ID: 19683170
thanks for all your help guys. I'll try to modify it a bit and see what I can come up with. One big problem i didn't even think about what how windows handles multiple people accessing the same file.  Anyway thanks for the help.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question