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 ]