#94581 - 2002-10-20 04:57 AM
Best options/best way?
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Looking for the best ways/arguments to do the following operations in KiXtart..
1. Getting a major file version Short version
code:
$RegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE" $outmaj = SUBSTR((GETFILEVERSION(READVALUE($RegKey,""))), 1, (INSTR(GETFILEVERSION(READVALUE($RegKey,"")), ".")-1)) ?$outmaj
Long version
code:
$RegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE" $outver = (GETFILEVERSION(READVALUE($RegKey,""))) $pos = (INSTR(GETFILEVERSION(READVALUE($RegKey,"")), ".")-1) $outmaj = SUBSTR($outver, 1, $pos) ?$outmaj
2. Check for Existence of direcotry Option one, look for the attributes
code:
IF GetFileAttr( "C:\ScriptTest" ) & 16 ELSE MD "C:\ScriptTest" ENDIF
Using EXIST to test for a folder
code:
IF (EXIST("C:\ScriptTest\nul") <> 1) MD "C:\ScriptTest" ENDIF
3. Look for a file existence Option 1
code:
IF EXIST("C:\ScriptTest\Program.exe") ELSE COPY @LSERVER+"Programs\Program.exe" "C:\ScriptTest" ENDIF
Option 2
code:
IF (1 <> EXIST("C:\ScriptTest\Program.exe")) COPY @LSERVER+"Programs\Program.exe" "C:\ScriptTest" ENDIF
Option 3
code:
IF (EXIST("C:\ScriptTest\Program") <> 1) COPY @LSERVER+"Programs\Program.exe" "C:\ScriptTest" ENDIF
Thanks,
Kent [ 20. October 2002, 08:06: Message edited by: kdyer ]
|
Top
|
|
|
|
#94584 - 2002-10-20 06:29 AM
Re: Best options/best way?
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
ah - yup - ok - im on the same page as you guys now - maybe scripts then ?
item 1 no comment
item 2 - agree with Les, use NOT or the second option ... i would avoid the reverse logic in option one - or turn the expression around like this:
code:
IF (GetFileAttr( "C:\ScriptTest" ) & 16) = 0 MD "C:\ScriptTest" ENDIF
item 3 - use NOT or option 3
my 2 cents cdn. [ 20. October 2002, 06:29: Message edited by: Shawn ]
|
Top
|
|
|
|
#94585 - 2002-10-20 08:00 AM
Re: Best options/best way?
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
The reason I bring this up is that we are overhauling our logon scripts and I was trying think of how do things more efficiently or the best way..
I think I have the answers I need..
#1 - Option 1. It was merely an experiment to see how well Kix handles nested FUNCTIONS. You could Use WINWORD.EXE, or IEXPLORE.EXE as alternatives. The way I have this presented it would be very difficult to debug if there was something wrong with the script.
#2 - #3, I like the IF..ELSE..ENDIF Logic. We have our clients up on 4.02.. So, sure the NOT operator would be fine. However, when we are creating FAQs, and responses to forum posts the scripts we should create these for all target audiences, right?
Thanks!
Kent [ 20. October 2002, 08:01: Message edited by: kdyer ]
|
Top
|
|
|
|
#94587 - 2002-10-21 06:52 AM
Re: Best options/best way?
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
This has been added in as an FAQ - File Operations
With some modifications.
Thanks!
Kent
|
Top
|
|
|
|
#94589 - 2002-10-29 05:34 PM
Re: Best options/best way?
|
Bxn
Getting the hang of it
Registered: 2002-06-05
Posts: 63
Loc: Alpha Centauri
|
Prepare your riot guns guys !
I hope my previous post was not too dry ... To correct this eventuality, I hope you'll be pleased with this illustration.
You will now be allowed to shoot at me for the reason you prefer : this code is faulty, misconstructed, puzzling for newbees, makes easy things harder, or whatever you'll find !
code:
;Trying To Create A Folder If Necessary $FolderNameToCheck = "C:\ScriptTest" $Result = -1
If Exist($FolderNameToCheck) If GetFileAttr($FolderNameToCheck) & 16 $Result = 1 Else $Result = -2 EndIf Else MD $FolderNameToCheck $CommandError = @Error $CommandSError = @SError If $CommandError = 0 $Result = 0 Else $Result = -3 $CommandError = CStr($CommandError) EndIf EndIf
Select Case $Result = 0 ? "Folder " + $FolderNameToCheck + " Successfully Created" Case $Result = 1 ? "Folder " + $FolderNameToCheck + " Already Exists" Case $Result = -2 ? "Can't create Folder " + $FolderNameToCheck ? "Duplicated File/Folder Name" Case $Result = -3 ? "An Error Has Occured During " + $FolderNameToCheck + " Folder Creation" ? "[" + $CommandSError + "] " + $CommandSError Case 1 ? "UnExpected Result" EndSelect
If $Result >= 0 ? "Ok, We Can Go On" Else ? "Something Has Happend, We Have To Check " EndIf
That was my attempt to prevent unexpected errors in my own scripts. I'm sure you'll find easier, safer or more pertinent ways and I'd be glad to hear from you ...
|
Top
|
|
|
|
#94590 - 2002-10-30 04:58 PM
Re: Best options/best way?
|
Bxn
Getting the hang of it
Registered: 2002-06-05
Posts: 63
Loc: Alpha Centauri
|
Almost Two days without reaction ... Please, let me know if I smell Camembert, and I won't pollute the board anymore ...
|
Top
|
|
|
|
#94592 - 2002-10-30 05:09 PM
Re: Best options/best way?
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Since I started this...
I will respond..
Kent
|
Top
|
|
|
|
#94599 - 2002-10-31 08:19 AM
Re: Best options/best way?
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Did some testing and here is what I was able to throw together..
bxn, you are correct about error 183.
This hopefully addresses point one.
We'll just focus on the file/folder existence thingy.
First way - using fso:
code:
; - Test environment: Windows XP ; - Kix Version: 4.12 ; - Kent Dyer ; - 30-October-2002 ; - version .8 ; - Test: Create a simple text file called ScripTest and insert some text in it ; - Findings: a file name and folder name of the same name cannot exist on the same volume ; - Thanks: to bxn from http://kixtart.org for pointing out the error 183 when a file exists with ; - same name as the folder
; - using fso per Les BREAK ON CLS ;Trying To Create A Folder as Necessary $foldernametocheck = "C:\ScriptTest" $lenfolder = Len($foldernametocheck) $foldername = substr($foldernametocheck,4,$lenfolder)
; - First check to see if this is a file IF EXIST($foldernametocheck) AND NOT (GETFILEATTR($foldernametocheck) & 16) ? $foldernametocheck + " appears to exist as a file" ?'Press Y and <ENTER> to continue and rename the file and create the folder' ?'Press N and <ENTER> to exit' ?'>' GETS $k IF $k = 'Y' SHELL "%comspec% /c ren " + $foldernametocheck + " " + $foldername + "1" ReportFolderStatus($foldernametocheck) ELSE RETURN ENDIF ELSE ?$foldernametocheck + " Appears to exist as a folder." SLEEP 2 ENDIF
FUNCTION ReportFolderStatus($fldr) ; - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jsmthFolderExists.asp DIM $fso, $msg $fso = CreateObject("Scripting.FileSystemObject") IF ($fso.folderexists($fldr)) ?$fldr + " exists." ELSE ?$fldr + " doesn't exist." ?"Creating now" MD $foldernametocheck IF @error <> 0 ?@error SLEEP 2 ENDIF ENDIF ENDFUNCTION ? "File/folder checks complete" ? "Press any Key to exit" GET $l
Second way - using Kixtart:
code:
; - Test environment: Windows XP ; - Kix Version: 4.12 ; - Kent Dyer ; - 30-October-2002 ; - version .8 ; - Test: Create a simple text file called ScripTest and insert some text in it ; - Findings: a file name and folder name of the same name cannot exist on the same volume ; - Thanks: to bxn from http://kixtart.org for pointing out the error 183 when a file exists with ; - same name as the folder ; ; - using Kixtart commands BREAK ON CLS ;Trying To Create A Folder as Necessary $foldernametocheck = "C:\ScriptTest" $lenfolder = Len($foldernametocheck) $foldername = substr($foldernametocheck,4,$lenfolder)
; - First check to see if this is a file IF EXIST($foldernametocheck) AND NOT (GETFILEATTR($foldernametocheck) & 16) ? $foldernametocheck + " appears to exist as a file" ?'Press Y and <ENTER> to continue and rename the file and create the folder' ?'Press N and <ENTER> to exit' ?'>' GETS $k IF $k = 'Y' SHELL "%comspec% /c ren " + $foldernametocheck + " " + $foldername + "1" ?"Creating "+ $foldernametocheck + " now" MD $foldernametocheck IF @error <> 0 ?@error SLEEP 2 ENDIF ELSE RETURN ENDIF ENDIF IF EXIST($foldernametocheck) AND (GETFILEATTR($foldernametocheck) & 16) ?$foldernametocheck + " Appears to exist as a folder." SLEEP 2 RETURN ELSE ?"Creating " + $foldernametocheck + " now" MD $foldernametocheck IF @error <> 0 ?@error SLEEP 2 ENDIF ENDIF ? "File/folder checks complete" ? "Press any Key to exit" GET $l
Thank bxn for pointing the error condition out..
Thanks Les for pointing out the option for fso.
Now, to look at the Program existence thing.
Cheers,
Kent [ 03. November 2002, 18:00: Message edited by: kdyer ]
|
Top
|
|
|
|
#94600 - 2002-10-31 08:37 AM
Re: Best options/best way?
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Folder/Program check..
This hopefully addresses point two and three.
Here is the corrected version:
code:
; - Test environment: Windows XP ; - Kix Version: 4.12 ; - Kent Dyer ; - 30-October-2002 ; - version .8 ; - Test: Create a Folder in a sub-directory with the name of Program.exe ; - Findings: a file name and folder name of the same name cannot exist on the same volume ; - Thanks: to bxn from http://kixtart.org for pointing out the error 183 when a file exists with ; - same name as the folder ; ; - using Kixtart commands BREAK ON CLS ;Trying To Create A Folder and copy a file as Necessary $folder = "C:\ScriptTest" $program = "Program.exe"
IF (GETFILEATTR($folder) & 16) ; - Check to not only see if the file exists, but the folder too IF EXIST($folder + "\" + $program) IF EXIST($folder + "\" + $program) AND (GETFILEATTR($folder + "\" + $program) & 16) ?$folder + "\" + $program + " appears to be a folder - please correct" SLEEP 2 RETURN ELSE ?$folder + "\" + $program + " appears to be correct" ENDIF ELSE COPY @lserver+"Programs\"+ $program $folder IF @error <> '0' ?@error ENDIF ENDIF ELSE ?'Press Y and <ENTER> to continue and create the folder and copy the file' ?'Press N and <ENTER> to exit' ?'>' GETS $k IF $k = 'Y' MD $folder IF @error <> '0' ?@error + ' Error while creating the directory' ENDIF COPY @lserver+"Programs\"+ $program $folder IF @error <> '0' ?@error ENDIF ELSE RETURN ENDIF ENDIF ? "File/folder checks complete" ? "Press any Key to exit" GET $l
Thanks again,
Kent [ 31. October 2002, 09:06: Message edited by: kdyer ]
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 265 anonymous users online.
|
|
|