#82027 - 2003-08-13 07:34 AM
Best Practices and Methods
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
KIX32/WKIX32
- KIX32.EXE - Standard, console version of KiXtart
- WKIX32.EXE - Console-less version of KiXtart, used to not generate a "DOS" Window. Also used with KIXFORMS
The use of the /i switch is not necessary with properly written code. The "hiding" should be automatic. FilenamesWhat are the file names and extensions used when working with KiXtart and related files? In the Documentation, it is mentioned that .SCR files can be used for KiXtart. SCR could be used for a script extension, however, it is already in use for Windows screen savers UDF extension is also being used by SQL Server.
code:
.KIX, .KXS = KiXtart script .KXF = KiXtart user-defined function (single function of the same name) .KXL = KiXtart UDF library (multiple UDFs). Functions can also be read in like an INCLUDE file for later use .KX* = KiXtart script (s), UDF (f), udf lib (l), (or KXS,KXF,KXL, respectively) .INI = text file for use with READPROFILESTRING/WRITEPROFILESTRING .TXT = text file used to store information about the file(s) you are working with, for example README.TXT. However, this type of file can be used with READLINE/WRITELINE. .BAT = Batch script to invoke the Command Interpreter (COMMAND.COM/CMD.EXE) to start other processes/programs and/or KiXtart itself. Common Batch files are - NTLOGON.BAT (in the NETLOGON share). AUTOEXEC.BAT (Root of the client drive) .CMD = See batch script. Also called a "Windows NT Command Script". Usually include advanced features of command scripting like FOR..tokens. IF, etc.
Coding- Start with a UDF-like header (What does the script do, who wrote it, change history etc.)
- Use break on until the script is finished
- Use SetOption('NoVarsInStrings','ON') en SetOption('Explicit','ON')
- Comment your code
- Let the script be tested by someone who does not know or understand how to code script.
- Never use GOTO/GOSUB!!! These are considered "old school" and with properly written code, you can work around (even with older versions of KiXtart). With newer versions of KiXtart, you can replace with a DO/UNTIL or WHILE, a FUNCTION
Answering common questions using Macros and string manipulationcode:
$os = split(@ProductType)[1] $csd = val(right(@csd,1)) $admin = ingroup('@wksta\'+sidtoname('S-1-5-32-544'))-1+@INWIN
To explain.. $os = split(@ProductType)[1] What OS, specifically? $csd = val(right(@csd,1)) What service pack is installed? $admin = ingroup('@wksta\'+sidtoname('S-1-5-32-544'))-1+@INWIN Is the Current logged in user an Admin? This is read from the inside out.. (1) sidtoname with this specific SID (or Security IDentifier) (2) ingroup > Is the current user in this group based on the SID test performed in (1) KiXtart Constantscode:
$OS = split(@ProductType)[1] $CSD = val(right(@csd,1)) $ADMIN = ingroup('@wksta\'+sidtoname('S-1-5-32-544'))-1+@INWIN $HKLMSCCS ="HKLM\SYSTEM\CurrentControlSet" $HKCUSMWCV ="HKCU\Software\Microsoft\Windows\CurrentVersion" $HKLMSMWCV ="HKLM\Software\Microsoft\Windows\CurrentVersion" $HKLMSMWNTCV ="HKLM\Software\Microsoft\Windows NT\CurrentVersion" $HKCUSMWNTCV ="HKCU\Software\Microsoft\Windows NT\CurrentVersion" $Desktop =readvalue($HKCUSMWCV+"\Explorer\Shell Folders",'Desktop') $StartMenu =readvalue($HKCUSMWCV+"\Explorer\Shell Folders",'Start Menu') $Favorites =readvalue($HKCUSMWCV+"\Explorer\Shell Folders",'Favorites') $alldesktop =expandenvironmentvars(readvalue($HKLMSMWCV+"\Explorer\User Shell Folders","Common Desktop")) $allstartmenu=expandenvironmentvars(readvalue($HKLMSMWCV+"\Explorer\User Shell Folders","Common Start Menu")) $DomainLDAP ="LDAP://"+@domain+"/"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")
Desktop or Laptopcode:
BREAK ON $case =iif(keyexist('HKLM\SYSTEM\CurrentControlSet\Services\Compbatt'),'Laptop','Desktop') ?$case get $
There maybe a caveat to the above code looking for a battery - quote: If you have a smartUPS plugged in, this key will exist
may have to include PCMCIA ports also.
Desktops may have one or the other but rarely both...
SHELL vs. RUN SHELL - Will Shell or leave temporarily the script to execute a DOS-Based Program - EXIT is used to come back into the script.
- %COMSPEC% - What is that? %COMSPEC% is an environment variable set for the system.. You can do a ECHO %COMSPEC% to see what is set for this
RUN - Similar to going to START/RUN from your Windows Session. This is to start a program, for example NOTEPAD.EXE. $cmd VariableWant to run a COMMAND/CMD and set it globally? $cmd= '%comspec% /c '
make sure the trailing space is in there.
shell $cmd+'ping server >c:\tmp.txt'
'/e:1024 ' or whatever other environment parameters you prefer can be added to it as well...
If you want to re-use a PING Command for example: $ShellCMD = '%comspec% /c '+'ping server >c:\tmp.txt'
Then you can either just dump it to the console with:
$ShellCMD ?
or let her rip with:
shell $ShellCMD [ 22. September 2003, 19:34: Message edited by: kdyer ]
|
Top
|
|
|
|
Moderator: Jochen, Radimus, Glenn Barnas, Allen, Arend_, ShaneEP, Mart
|
0 registered
and 686 anonymous users online.
|
|
|