Page 1 of 1 1
Topic Options
#81975 - 2002-10-21 06:46 AM File Operations
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Handy File operations in KiXtart
{Edit - 03-April-2003 Use EXIST instead of GETFILEATTR)

  • 1. Getting a major file version
  • 2. Check for Existence of directory
  • 3. Check for Existence of a file
  • 3a. Check for Existence of a file with folder check
  • 4. Test for Drive existence with notification
  • 5. Adding a Program Group and Item
  • 6. Adding a shortcut to the desktop
1. Getting a major file versionI am running Program version 9.0.0.2416.. How do I just get the 9 or the Major version?
code:
 $regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE"
$outlookexe = READVALUE($regkey,"")
$outver = GETFILEVERSION($outlookexe)
$pos = INSTR($outver, ".")-1
$outmaj = SUBSTR($outver, 1, $pos)
?$outmaj

2. Check for Existence of directory
Note: We don't need to look for a file, but rather a directory or folder
code:
 IF 0=EXIST("C:\ScriptTest")
MD "C:\ScriptTest"
ENDIF

3. Check for Existence of a file
Note: This assumes the Folder C:\ScriptTest exists first
code:
 IF 0=EXIST("C:\ScriptTest\Program.exe")
COPY @lserver+"Programs\Program.exe" "C:\ScriptTest"
ENDIF

3a. Check for Existence of a file with folder check
code:
 IF 0=EXIST("C:\ScriptTest\Program.exe")
IF 0=EXIST("C:\ScriptTest")
MD "C:\ScriptTest"
ENDIF
COPY @lserver+"Programs\Program.exe" "C:\ScriptTest"
ENDIF

4. Test for Drive existence with notification
code:
:htest
; -- BLAT.EXE (freeware) is found at - http://www.interlog.com/~tcharron/blat.html
$subnet=ltrim(SubStr(@ipaddress0,5,3))

; -- Check for H: Drive
IF $subnet = "xx" OR $subnet = "yyy" OR @userid = "temp" ; -- If someone is on VPN, don't touch 'em
RETURN
ELSE
IF 0=EXIST("H:\")
$mailhost = 'smtp.server.com'
$recipient = 'admin@@server.com'
$sender = @userid+'@@server.com'
$mailLine = @ldrive+'Programs\blat.exe - -to $recipient -server $mailhost -subject "No H: drive" '
$mailLine = $mailLine+'-body "H: Drive is not found for @userid (@fullname)" -f $sender -q'
SHELL $mailLine
RETURN
ELSE
RETURN
ENDIF
ENDIF

5. Adding a Program Group and Item
Note: ADDPROGRAMGROUP/ADDPROGRAMITEM should work for Local user Logging in.. However, All Users if the User logging in has Admin Rights under NT.
Note 2: ADDPROGRAMITEM will only create items for an "Active" Program Group.
code:
 BREAK ON CLS
$path = READVALUE("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Programs")
$windir = READVALUE("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion","SystemRoot")
$notepad = $windir+"\notepad.exe"
$calc = $windir+"\System32\calc.exe"
$grouptest = "$path\Group Test"

IF 0=EXIST("$grouptest\WindowsNotepad.lnk") OR 0=EXIST("$grouptest\WindowsCalculator.lnk")
IF 0=EXIST($grouptest)
$rc = ADDPROGRAMGROUP ("Group Test")
SLEEP 1
$rc = SETFOCUS("Group Test")
$rc = SENDKEYS("~{F4}")
ELSE
$rc = SHOWPROGRAMGROUP ("Group Test", 1 )
SLEEP 1
$rc = SETFOCUS("Group Test")
$rc = SENDKEYS("~{F4}")
ENDIF
$rc = ADDPROGRAMITEM ($notepad, "WindowsNotePad", "", 0, "C:\")
$rc = ADDPROGRAMITEM ($calc, "WindowsCalculator", "", 0, "")
RETURN
ELSE
RETURN
ENDIF

6. Adding a shortcut to the desktop
Note: Shortcut.exe is available from the NT Resource Kit.
This can also be done with WshShortCut - Create shortcuts programatically with WSH
code:
 BREAK ON CLS
$desktop = READVALUE("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Desktop")
$windir = READVALUE("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion","SystemRoot")
$notepad = $windir+"\notepad.exe"

IF 0=Exist("$desktop\WindowsNotepad.lnk")
$shortcutprg = @ldrive+"Reskit\shortcut.exe"
; -- Info is from - http://www.is-it-true.org/nt/atips/atips273.shtml
RUN '$shortcutprg -f -t $notepad -n "$desktop\WindowsNotePad.lnk" -i "$notepad" -x 0 -d C:\'
RETURN
ELSE
RETURN
ENDIF



[ 03. April 2003, 18:00: Message edited by: kdyer ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#81976 - 2002-10-28 08:50 PM Re: File Operations
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
BXN has a comment on this code in the birthplace of this thread. Since he cannot reply here, I am including a link on his behalf.

Topic: Best options/best way?


Edited by kdyer (2003-12-09 08:31 AM)
_________________________
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, Radimus, Glenn Barnas, Allen, Arend_, ShaneEP, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 645 anonymous users online.
Newest Members
Raoul, Timothy, Jojo67, MaikSimon, kvn317
17875 Registered Users

Generated in 0.156 seconds in which 0.119 seconds were spent on a total of 14 queries. Zlib compression enabled.

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