Showing posts with label NT Scripts. Show all posts
Showing posts with label NT Scripts. Show all posts

Tuesday, June 26, 2007

Kix Copy script with GUI (Kixtart UDF)

Another KIXtart UDF, well the title says it all...

Dependencies:
KiX 4.02 (or higher)
Shell32.dll version 4.71 or later. (Included with: Windows 2000, Windows NT 4.0 with Internet Explorer 4.0, Windows 98, Windows 95 with Internet Explorer 4.0.)

Usage:
GUICopy("source", "destination", "optional flag", "optional flag")
@ERROR " : " @SERROR ?

Optional Flags:
4 - Do not display a progress dialog box.
8 - Give the file being operated on a new name in a move, copy, or rename
operation if a file with the target name already exists.
16 - Respond with "Yes to All" for any dialog box that is displayed.
64 - Preserve undo information, if possible.
128 - Perform the operation on files only if a wildcard file name (*.*) is
specified.
256 - Display a progress dialog box but do not show the file names.
512 - Do not confirm the creation of a new directory if the operation requires
one to be created.
1024 - Do not display a user interface if an error occurs.
2048 - Version 4.71. Do not copy the security attributes of the file.
4096 - Only operate in the local directory. Don't operate recursively into
subdirectories.
8192 - Version 5.0. Do not copy connected files as a group. Only copy the
specified files.


Returns The exitcode of the command in the @ERROR macro.
@ERROR = 0 The operation completed successfully.
@ERROR = 2 The system cannot find the file specified. (Refers to Source file.)
@ERROR = 3 The system cannot find the path specified. (Bad destination path.)
@ERROR = 9 The storage control block address is invalid. (Most likely cancelled copy.)
@ERROR = 10 The environment is incorrect. (Incorrect Shell32.dll version.)
@ERROR = 87 The parameter is incorrect. (Use 0 or 1 to specify Copy or Move.)

Code Snippet:

  1. Function GUICopy($sSrc, $sDest, OPTIONAL $lFlags, OPTIONAL $bMove)
  2. Dim $sVer,$objShell,$objFldr
  3. If Not Exist($sSrc) Exit 2 Endif
  4. If Not Exist($sDest) Exit 3 Endif
  5. If @INWIN=1
  6. $sVer=GetFileVersion(%WINDIR%+"\System32\Shell32.dll","FileVersion")
  7. Else
  8. $sVer=GetFileVersion(%WINDIR%+"\System\Shell32.dll","FileVersion")
  9. Endif
  10. If $sVer<"4.71" Exit 10 Endif
  11. $objShell=CreateObject("Shell.Application")
  12. $objFldr=$objShell.NameSpace($sDest)
  13. If @ERROR<0 Exit VAL("&"+Right(DecToHex(@ERROR),4)) EndIf
  14. Select
  15. Case $bMove=1 $objFldr.MoveHere($sSrc,$lFlags)
  16. Case $bMove=0 $objFldr.CopyHere($sSrc,$lFlags)
  17. Case 1 Exit 87
  18. EndSelect
  19. If @ERROR<0 Exit VAL("&"+Right(DecToHex(@ERROR),4)) EndIf
  20. Exit @ERROR
  21. EndFunction

If at first you fail, call it version 1.0

Kix FTP (Kixtart UDF)

FTP via Kix? Yes!!!

Using Microsoft.XMLHTTP and ADODB.Stream.

Usage:

FTPget("ftp_address", "target_dest_drive", "id", "password")

Code Snippet:

  1. Function FTPget($sURL, $sTargetFile, optional $sUser, optional $sPass)
  2. Dim $oFTP, $oStream $sUser=""+$sUser
  3. $oFTP = CreateObject("Microsoft.XMLHTTP")
  4. if @error
  5. $ftpget=1
  6. exit 1
  7. endif
  8. $oStream = CreateObject("ADODB.Stream")
  9. if @error
  10. $ftpget=2
  11. exit 2
  12. endif
  13. if $sUser
  14. $oFTP.Open("GET", $sURL, not 1, $sUser, $sPass)
  15. else
  16. $oFTP.Open("GET", $sURL, not 1)
  17. endif
  18. if @error
  19. $ftpget=3
  20. exit 3
  21. endif
  22. $oFTP.Send
  23. $oStream.Type = 1
  24. $oStream.Mode = 3
  25. $oStream.open
  26. $oStream.Write($oFTP.responseBody)
  27. if @error
  28. $ftpget=4
  29. exit 4
  30. endif
  31. $oStream.SaveToFile($sTargetFile, 2)
  32. if @error
  33. $ftpget=5
  34. exit 5
  35. endif
  36. $oStream.Close
  37. EndFunction


If at first you fail, call it version 1.0

How to: Enable Reply to All?

Did your company disabled the reply to all option on your Outlook?
And even deployed a noreplyall.dll to remove the icon?

It sucks ain't it? Copying all the address from the previous email instead of just clicking on the Replyall button...

You could delete these two (2) keys in the registry then restart your Outlook.
Customize your Toolbar , search for the Actions category and enable the ReplytoAll button.

  • HKEY_CURRENT_USER\Software\Policies\Microsoft\Office\11.0\Outlook\DisabledCmdBarItemsList
  • HKEY_CURRENT_USER\Software\Policies\Microsoft\Office\11.0\Outlook\DisabledShortcutKeysList

If you have GPO applied, this settings will not be retained after you logoff or reboot your machine...

Well a short NT script on your startup can bring it back...


Code Snippet:
  1. @Echo Off
  2. > "%Temp%.\EnableRep2All.reg" Echo Windows Registry Editor Version 5.00
  3. >> "%Temp%.\EnableRep2All.reg" Echo
  4. >> "%Temp%.\EnableRep2All.reg" Echo [-HKEY_CURRENT_USER\Software\Policies\Microsoft\Office\11.0\Outlook\DisabledCmdBarItemsList]
  5. >> "%Temp%.\EnableRep2All.reg" Echo [-HKEY_CURRENT_USER\Software\Policies\Microsoft\Office\11.0\Outlook\DisabledShortcutKeysList]
  6. >> "%Temp%.\EnableRep2All.reg" Echo
  7. START /WAIT REGEDIT.EXE /S "%Temp%.\EnableRep2All.reg"
  8. DEL "%Temp%.\EnableRep2All.reg"
  9. Exit



If at first you fail, call it version 1.0

Monday, June 18, 2007

ADSI Kixtart UDF for Citrix login

Having a mixed mode environment gave us a lot of hassle when logging in to NT and querying group membership in AD... Specially in our case, we have nested OU's...

Ifmember.exe is useful for this problem but it does cause a slight delay in the login process and the users are complaining on the slow login session, some couldn't wait and cancels the connection... catastrophic experience ends up as a global complain... hmmm... some people are just impatient...

So to be able to execute an ADSI query through kix login script the function below can be inserted anywhere in the login script to perform InGroup query... or this can fully replace the built in InGroup function in kixtart.


Code Snippet:

  1. Function fnInGroupAD($sGroup,Optional $bComputer)
  2. Dim $objSys,$objTarget,$aMemberOf,$sMemberOf
  3. $objSys = CreateObject("ADSystemInfo")
  4. $objTarget = GetObject("LDAP://"+Iif($bComputer,$objSys.ComputerName,$objSys.UserName))
  5. $aMemberOf = $objTarget.GetEx("memberOf")
  6. For Each $sMemberOf in $aMemberOf
  7. If InStr($sMemberOf,"CN="+$sGroup+",")
  8. $fnInGroupAD = Not 0
  9. Exit
  10. EndIf
  11. Next
  12. $fnInGroupAD = NOT 1
  13. EndFunction

If at first you fail, call it version 1.0

Wednesday, June 13, 2007

String manipulation in NT scripts

I was working on a Citrix Login script and found out most clients are not able to perform WMI queries to get session information from the server or just simple evironment variable expansion... or is it just our GPO is just too tight?

Instead of using vbscript for the string manipulation, I opted to the old school NT scripting, since the built in usrlogon script in PS4 is native to NT.

So I searched the help files and the net for old DOS commands for string manipulation as my goal for this script is to get the first 2 characters from the environment variable %CLIENTNAME%. If the machine name's first 2 characters are "UK", then a certain drive is required to be mapped.

Now, It is possible to retrieve specific characters from a string variable.

Syntax:
%variable:~num_chars_to_skip%
%variable:~num_chars_to_skip,num_chars_to_keep%

This can include negative numbers:
%variable:~num_chars_to_skip, -num_chars_to_skip%
%variable:~-num_chars_to_skip,num_chars_to_keep%

A negative number will count backwards from the end of the string. In Windows NT 4 the syntax for negative numbers was not supported.

Examples:
The variable _test is used for all the following examples:

SET _test=123456789abcdef0

::Extract only the first 5 characters

SET _result=%_test:~0,5%
ECHO %_result% =12345

::Skip 7 characters and then extract the next 5

SET _result=%_test:~7,5%
ECHO %_result% =89abc

::Skip 7 characters and then extract everything else

SET _result=%_test:~7%
ECHO %_result% =89abcdef0

::Extract only the last 7 characters

SET _result=%_test:~-7%
ECHO %_result% =abcdef0

::Extract everything BUT the last 7 characters

SET _result=%_test:~0,-7%
ECHO %_result% =123456789

::Extract between 7 from the front and 5 from the end

SET _result=%_test:~7,-5%
ECHO %_result% =89ab

::Go back 7 from the end then extract 5 towards the end

SET _result=%_test:~-7,5%
ECHO %_result% =abcde

::Extract between 7 from the end and 5 from the end

SET _result=%_test:~-7,-5%
ECHO %_result% =ab

And this is the final script:
SET _CNAME=%CLIENTNAME%
CALL SET _ORIGIN=%_CNAME:~-0,2%

IF %_ORIGIN% EQU UK (
NET USE R: \\UKFILSERVER\CITRIX$
) ELSE (
GOTO Done
)

:Done

If at first you fail, call it version 1.0