Page 1 of 1 1
Topic Options
#174408 - 2007-03-02 03:05 PM passing arguments to batch file
Ed_Patterson Offline
Fresh Scripter

Registered: 2006-06-29
Posts: 20
I need to pass an argument to a batch file. I have tried
 Code:
$MYDOCS = ReadValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Personal")
Shell "CMD.EXE /C copyNotesID.cmd $MYDOCS"

Nothing happens. I tried having the cmd window ech0 %1%, notta.

I am sure it is a simple matter. I am trying to copy Lotus Notes user.id files to the users my documents folder. Users my documents folders are either local (laptops) or redirected to the server.

The copyNotesID.cmd file is simply a couple of if exist lines.

Ed

Top
#174411 - 2007-03-02 04:13 PM Re: passing arguments to batch file [Re: Ed_Patterson]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Shell "%Comspec% /c copyNotesID.cmd " $MYDOCS
_________________________
Today is the tomorrow you worried about yesterday.

Top
#174416 - 2007-03-02 04:25 PM Re: passing arguments to batch file [Re: Gargoyle]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Gargoyle, I think not.

Ed,
What is in the copyNotesID.cmd file and what are you really trying to do?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#174417 - 2007-03-02 04:49 PM Re: passing arguments to batch file [Re: Les]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
I would make it rather
Shell '%Comspec% /c copyNotesID.cmd "' + $MYDOCS + '"'
But maybe it is worth trying to convert the cmd-file to native KiX

Top
#174420 - 2007-03-02 05:10 PM Re: passing arguments to batch file [Re: Witto]
Ed_Patterson Offline
Fresh Scripter

Registered: 2006-06-29
Posts: 20
Here is the batch file (written before I knew there was an exist in kix)
[code]
@echo off
if exist "c:\lotus\notes\data\*.id" echo "They are in c:\lotus\notes\data!"
if exist "c:\program files\lotus\notes\data\*.id" echo "They are in c:\program files\lotus\notes\data!"
[\code]
I'll try making it native kix using the examples above. I gave up on native when I (mistakenly) thought that if exist in kix did not support wildcards.

Ed

Top
#174421 - 2007-03-02 05:17 PM Re: passing arguments to batch file [Re: Ed_Patterson]
Ed_Patterson Offline
Fresh Scripter

Registered: 2006-06-29
Posts: 20
For my next trick I will submit the actual file that does more than trouble shooting. I am so ashamed...
 Code:
@echo off
if exist "c:\lotus\notes\data\*.id" copy "c:\lotus\notes\data\*.id" %1%
if exist "c:\program files\lotus\notes\data\*.id" copy "c:\program files\lotus\notes\data\*.id" %1%

where %1% is the location of my documents which is passed from kix.
Ed

Top
#174422 - 2007-03-02 05:26 PM Re: passing arguments to batch file [Re: Ed_Patterson]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Exist() is a function and thus needs parens.
What is this %1% stuff?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#174423 - 2007-03-02 05:29 PM Re: passing arguments to batch file [Re: Les]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
With all information you gave untill now, I would try something like
 Code:
;Script Options
If NOT @LOGONMODE
	Break On
Else
	Break Off
EndIf
Dim $RC
$RC = SetOption("Explicit","On")
$RC = SetOption("NoVarsInStrings","On")
$RC = SetOption("NoMacrosInStrings","On")
$RC = SetOption("WrapAtEOL","On")
;Declare Variables
Dim $MyDocs
;Find My Documents folder
$MyDocs = ReadValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Personal")
;Copy stuff
If Exist("c:\lotus\notes\data\*.id")
	Copy "c:\lotus\notes\data\*.id" $MyDocs
EndIf
If Exist("c:\program files\lotus\notes\data\*.id")
	Copy "c:\program files\lotus\notes\data\*.id" $MyDocs
EndIf

Top
#174424 - 2007-03-02 05:51 PM Re: passing arguments to batch file [Re: Les]
Ed_Patterson Offline
Fresh Scripter

Registered: 2006-06-29
Posts: 20
OK Here is the all encompassing, nothing left out, nothing typed in a hurry point, of the message \:\)

I am trying to backup users Lotus Notes id files. They could be in 2 different locations and named just about anything with a .id extension.

notes.kix
 Code:
$MYDOCS = ReadValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Personal")
Shell "CMD.EXE /C copyNotesID.cmd $MYDOCS"

copyNotesID.cmd which is located in the same directory as kix32.exe and notes.kix
 Code:
@echo off
if exist "c:\lotus\notes\data\*.id" copy "c:\lotus\notes\data\*.id" %1%
if exist "c:\program files\lotus\notes\data\*.id" copy "c:\program files\lotus\notes\data\*.id" %1%

It has been suggested that I need to change notes.kix to
 Code:
$MYDOCS = ReadValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Personal")
Shell '%Comspec% /c copyNotesID.cmd "' + $MYDOCS + '"'

The best idea of all has been to make it kix native which I have done by using
 Code:
/* KixTart script For copying Notes user ID's to the
** current location of their My Documents directory
*/
$MYDOCS = ReadValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Personal")
If Exist ("c:\lotus\notes\data\*.id")
	Copy "c:\lotus\notes\data\*.id" $MYDOCS
EndIf 
If Exist ("c:\program files\lotus\notes\data\*.id")
	Copy "c:\program files\lotus\notes\data\*.id" $MYDOCS
EndIf

It is now working just fine but would not be with out the assistance I received here.

Any ways to make it more efficient?

Ed

Top
#174425 - 2007-03-02 05:53 PM Re: passing arguments to batch file [Re: Witto]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I see a problem with assuming the User's ID file name and location. In reality, it could be different and there could be several. You need to fine the notes.ini file and determine what and where from that.

If the ID file is referenced without a full path, it is inferred to be in the data folder and there needs to be logic to ferret that detail out. I started to write a script to back it and other stuff up but ran into resistance from our Notes Administrator who thought she had exclusivity in that area and so it went nowhere. None the less, here is the work in progress that died.
 Code:
Break On
Dim $RC,$LastRun,$CurCTime,$CABFile,$IsNotesInstalled
Dim $Index,$NotesIniPath,$Directory,$NotesBAK
Dim $KeyFilename,$FileNames[8],$File
$RC=SetOption('WrapAtEOL','On') ;FOR TESTING ONLY, COMMENT OUT FOR PRODUCTION
$RC=SetOption('Explicit','On')
$RC=SetOption('NoVarsInStrings','On')
   /*
   The script checks for LastRun and only runs if LastRun is more than one week old.
   One week in CTime = 604800
   LastRun Saved in CTime format to:
      HKCU\Software\KiXtart\Weekly
      LastRun
      e.g. "1139417456" = 2006/02/08 10:50:56 TZ -6	
   */
$LastRun=Val(ReadValue('HKCU\Software\KiXtart\Weekly','LastRun'))
$CurCTime=Val(FlipCTime(@Date,@Time,-6))
;If $CurCTime-$LastRun>604800 ;UNCOMMENT FOR PRODUCTION
If 1 ;FOR TESTING ONLY - RUNS IT EVERY TIME - REMOVE FOR PRODUCTION
  $RC=WriteValue('HKCU\Software\KiXtart\Weekly','LastRun',$CurCTime,'REG_SZ')
    /*
    The script first checks "App Paths" to see if Notes is installed.
    */
  $IsNotesInstalled=ReadValue('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\notes.exe','Path')
    /*
    It then checks for/sets up the folder on O: and purges files older than one week if any
    */
  If Exist('O:') And $IsNotesInstalled<>''
    If Not Exist('O:\do_NOT_use_or_modify') MD 'O:\do_NOT_use_or_modify' EndIf
    $RC=DelOlderThan('O:\do_NOT_use_or_modify',$CurCTime-604800)
    $CABFile='O:\do_NOT_use_or_modify\'+@WKSTA+'.cab'
    If Exist($CABFile) Del $CABFile EndIf
    /*
    The action of the remaining script is to backup key files to a compressed CAB file.
    It must run at logon and has to complete before Notes throws a lock on any of the files.
    If it encounters a locked file, it will quit prematurely with no CAB file created.

    To mitigate, the script will copy the files to a temp folder and MakeCAB() from the copies,
    cleaning up the TEMP files afterward.  The copy will go much quicker than the MakeCAB().
    */
    $NotesBAK=ReadValue('HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders','Local AppData')+'\Notes.BAK'
    If Exist($NotesBAK) RD $NotesBAK EndIf
    MD $NotesBAK
      /*
      The script then locates the notes.ini file from the following reg Key/Value:
        HKCU\Software\Lotus\Notes\6.0
        NotesIniPath
        e.g. "C:\Documents and Settings\LLigetfa\Local Settings\Application Data\Lotus\Notes\Data\notes.ini"

      That method only works on regular client installs.  Administrator installs lack the \6.0 reg key.

      The script then reads the INI file For the following Keys/Values:
        [Notes]
        Directory=
        e.g. "C:\Documents and Settings\LLigetfa\Local Settings\Application Data\Lotus\Notes\Data"

        KeyFilename=
        e.g. "lligetfa.id"

      The first element, initially '' is a placeholder For <yourname>.ID
	    This could Get tricky as it can Exist in different locations.
      The remaining elements are as follows.
      */

    $NotesIniPath=ReadValue('HKCU\Software\Lotus\Notes\6.0','NotesIniPath')
    $Directory=ReadProfileString($NotesIniPath,'Notes','Directory')
    If $Directory<>'' And $NotesIniPath<>''
      $FileNames='',
        'BOOKMARK.NSF',
        'BUSYTIME.NSF',
        'DESKTOP6.NDK',
        'HEADLINE.NSF',
        'NAMES.NSF',
        'NOTES.INI',
        'PERWEB.NSF',
        'USER.DIC'
      $KeyFilename=ReadProfileString($NotesIniPath,'Notes','KeyFilename')
      If InStr($KeyFilename,'\')
        $FileNames[0]=$KeyFilename
      Else
        $FileNames[0]=$Directory+'\'+$KeyFilename
      EndIf
      If Exist($FileNames[0])
        For $Index=1 to UBound($FileNames)
          If Exist($Directory+'\'+$FileNames[$Index])
            $FileNames[$Index]=$Directory+'\'+$FileNames[$Index]
          Else
            $FileNames[$Index]=''
          EndIf
        Next
        $FileNames=ArrayPack($FileNames)
        $RC=Copy2Folder($FileNames,$NotesBAK)
        $FileNames=ArrayDir($NotesBAK)
        $RC=MakeCAB($CABFile,$FileNames)
        If Exist($NotesBAK) RD $NotesBAK EndIf
        '@@Error = '+@Error? ;FOR TESTING ONLY, COMMENT OUT FOR PRODUCTION
        '@@SError = '+@SError? ;FOR TESTING ONLY, COMMENT OUT FOR PRODUCTION
      EndIf
    EndIf
  EndIf
EndIf

;================== Start of UDFs ==================
Function MakeCab($Cab,$Files)
  Dim $[0],$X,$maker
  If Exist($Cab) Exit 183 EndIf
  If 8=VarType($Files) $[0]=$Files $Files=$ EndIf
  $Maker=CreateObject('MakeCab.MakeCab.1')
  If @Error Exit 120 EndIf
  $MakeCab=$Files
  If @DOS>'5.0'
    $Maker.CreateCab($Cab,0,0,Not 1)
  Else
    $Maker.CreateCab($Cab,0,0)
  EndIf
  For $=0 to UBound($Files)
    If Not Exist($Files[$])
      $MakeCab[$]=2
    Else
      $X=Split($Files[$],"\")
      $Maker.AddFile($Files[$],$X[UBound($X)])
      If @Error
        $MakeCab[$]=156
      Else
        $MakeCab[$]=0
      EndIf
    EndIf
    $Files[$] ? ; FOR TESTING  ONLY - REMOVE FOR PRODUCTION
    'Iteration #'+$ ? ; FOR TESTING  ONLY - REMOVE FOR PRODUCTION
  Next
  $Maker.CloseCab
  If Not UBound($MakeCab) $=$MakeCab $MakeCab=$[0] EndIf
EndFunction

Function FlipcTime($Date,$Dime,Optional $TZ,$Epoc)
  Dim $Y,$M,$D
  $TZ = Val($TZ)
  $Date = Split($Date,'/')
  If UBound($Date)<>2 Exit 1 EndIf
  $Y=Val($Date[0]) $M=Val($Date[1]) $D=Val($Date[2])
  If $M<3
    $M=$M+12
    $Y=$Y-1
  EndIf
  $Date=CDbl($D)+(153*$M-457)/5+365*$Y+$Y/4-$Y/100+$Y/400-306
  If $Epoc
    $Epoc=Split($Epoc,'/') If UBound($Epoc)<>2 Quit 1 EndIf
    If 0+$Epoc[1]<3
      $Epoc[1]=0+$Epoc[1]+12
      $Epoc[0]=0+$Epoc[0]-1
    EndIf
    $Epoc=0+$Epoc[2]+(153*$Epoc[1]-457)/5+365*$Epoc[0]+$Epoc[0]/4-$Epoc[0]/100+$Epoc[0]/400-306
  Else
    $Epoc=719163
  EndIf
  $Time=Split($Time,':')
  Select 
    Case UBound($Time)=1
      ReDim Preserve $Time[2]
      $Time[2]=0
    Case UBound($Time)=2
    Case 1
      Exit 1
  EndSelect
  $Time = (Val(CDbl($Time[0]))*3600)+(Val($Time[1])*60)+Val($Time[2])
  $FlipCTime = IIf(Val($TZ),(($Date-$Epoc)*86400+$Time)-($TZ*3600),($Date-$Epoc)*86400+$Time)
EndFunction

Function Copy2Folder($FileNames,$Folder)
  Dim $File
  For Each $File in $FileNames
    $File ? ;FOR TESTING - REMOVE FOR PRODUCTION
    Copy $File $Folder+'\'
  Next
EndFunction

Function ArrayPack($array)
  Dim $Loop, $Element
  Dim $ArrTemp[0]

  If Not VarType($Array)&8192 Exit 1 EndIf
  $loop=-1

  For Each $Element in $Array
    If $Element>' '
      $Loop=$Loop+1
      ReDim Preserve $ArrTemp[$Loop]
      $ArrTemp[$Loop]=$Element
    EndIf
  Next
  If UBound($ArrTemp)=-1 Exit 2 EndIf
  $ArrayPack=$ArrTemp
EndFunction

Function ArrayDir($Folder)
  Dim $I,$Files[10]
  $I=0
  $Files[$I]=$Folder+'\'+Dir($Folder)
  While @ERROR=0
    If Not (GetFileAttr($Files[$I])&16)
      $I=$I+1
    EndIf
    $Files[$I]=$Folder+'\'+Dir()
  Loop
  ReDim Preserve $Files[$I-1]
  $ArrayDir=$Files
EndFunction

Function DelOlderThan($Folder,$OlderThan)
  Dim $File
  $File=Dir($Folder)
  While @ERROR=0
    If Not (GetFileAttr($File)&16)
      If $OlderThan<Val(FlipCTime(Split(GetFileTime($Folder+'\'+$File),' ')[0],Split(GetFileTime($Folder+'\'+$File),' ')[1],-6))
        Del $Folder+'\'+$File
      EndIf
    EndIf
    $File=Dir()
  Loop
EndFunction
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#174427 - 2007-03-02 06:28 PM Re: passing arguments to batch file [Re: Les]
Ed_Patterson Offline
Fresh Scripter

Registered: 2006-06-29
Posts: 20
In my case it is a safe assumption. We use disk duplication for all of our roll outs and users do not have the ability to install software. To date no one has changed the location of their user.id. It is the technicians that preform the install that get creative. They may name the id file what ever they wish as long as it ends in .id. Since for the most part they enjoy their jobs it has not been an issue.

The only reason I even bother is that is apparently impossible to generate a new user.id file so users can access their mail.

When it comes to Notes I am strictly a user and I like it that way.

Ed

Top
#174431 - 2007-03-02 09:01 PM Re: passing arguments to batch file [Re: Ed_Patterson]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
We don't care for roaming profiles so the users' settings are tied to a particular PC. I also have a problem where it seems every one of my coworkers sets up Notes differently and ID files could be just about anywhere. Add to that, some users learned that they can carry their ID around on a floppy or stick it on a network share to get at their email from other PCs. Then on top of all that, coworkers make copies of the wrong one and people lose some of their certs. It's a bloody mess. That is one reason I wanted to create a backup that is compressed and hidden in a CAB file so that there is one less copy to worry about. IMHO there should only be one copy and it should be in their network home folder unless they have a laptop.

BTW, the Notes server does keep a copy of their most current ID complete with the default password but for obvious reasons, it is kept secure on the server and not all coworkers have access. My backup was more for the other files like their personal address book etc.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 369 anonymous users online.
Newest Members
rrosell, PatrickPinto, Raoul, Timothy, Jojo67
17877 Registered Users

Generated in 0.043 seconds in which 0.017 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org