xpanmanxxpanmanx
Starting to like KiXtart
Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
Greetings,
I am writing a script for a client, who wants to make it simple for his field staff to reconfigure workstations as they move between sites.
I want to keep a separate .INI file for each site, but the quantity of INIs may vary by workstation. I need for my script to display a numbered list of all the .INI filescan a static directory, and accept a keypress to continue execution using the specified .INI.
Would some kind sould please jump-start me on this?
My code thus far is below. Note that I am running with a static .INI file as a variable. Also please forgive the lengthy (but very clear) variable names; this was a requirement of my client. I've also included a sample .INI .
Best regards,
Tim ==
Code:
;turn on the break key.if this command is not present, and the operator halts execution, the operator will be forcibly logged off. Break on ? @scriptname SetOption('wrapateol','on') SetOption('explicit','on') Dim $dummy,$location_ini,$windows_default_printer,$location_name,$ie_proxy_enable,$ie_automatically_detect_settings, $ie_use_automatic_configuration_script,$ie_use_a_proxy_server_for_your_lan,$ie_do_not_use_proxy_server_for_addresses_beginning_with, $fwc_enable,$fwc_manual_isa_server_name,$fwc_enable_browser_configuration
$ie_proxy_enable = ReadProfileString($location_ini,'ie proxy server settings','enable (true or false)') $ie_automatically_detect_settings = ReadProfileString($location_ini,'ie proxy server settings', 'automatically detect settings (true or false)') $ie_use_automatic_configuration_script = Ucase(ReadProfileString($location_ini,'ie proxy server settings', 'use automatic configuration script (url or false)')) $ie_use_a_proxy_server_for_your_lan = Ucase(ReadProfileString($location_ini,'ie proxy server settings', 'use a proxy server for your lan (name:port or false)')) $ie_do_not_use_proxy_server_for_addresses_beginning_with = Ucase(ReadProfileString($location_ini,'ie proxy server settings', 'do not use proxy server for addresses beginning with ( and/or urls seperated by commas)'))
$fwc_enable = ReadProfileString($location_ini,'fwc settings','enable (true or false)') $fwc_manual_isa_server_name = Ucase(ReadProfileString($location_ini,'fwc settings', 'manual isa server name (fq server name or ip or false)')) $fwc_enable_browser_configuration = ReadProfileString($location_ini,'fwc settings','enable browser configuration (true or false)')
$windows_default_printer = UCASE(ReadProfileString($location_ini,'printer settings','default printer (local name unc or false)'))
[IE proxy server settings] Enable (TRUE or FALSE)=TRUE Automatically detect settings (TRUE or FALSE)=FALSE Use automatic configuration script (URL or FALSE)=FALSE Use a proxy server for your LAN (NAME:PORT or FALSE)=PROXY:80 Do not use proxy server for addresses beginning with ( and/or URLS seperated by commas)=
[FWC settings] Enable (TRUE or FALSE)=TRUE Manual ISA Server name (FQ Server Name or IP or FALSE)=PROXY Enable browser configuration (TRUE or FALSE)=False
[Printer settings] Default printer (Local name UNC or FALSE)=\\server\lj4Code:
NOTE: Code has been modified by NTDOC to remove LONG LINES Code is no longer as the poster intended it to look
#139537 - 2005-05-1102:13 AMRe: Need a jump start...
NTDOCNTDOC Administrator
Registered: 2000-07-28
Posts: 11634
Loc: Space
Please break the long lines in your code so that it can be read easier.
Also, what specifically do you mean reconfigure between sites? What do you want to change? Do you mean an Active Directory site or some other type of site? What version of KiXtart are you using? What client types are there?
#139538 - 2005-05-1106:39 PMRe: Need a jump start...
xpanmanxxpanmanx
Starting to like KiXtart
Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
Thanks, NTDOC...but I don't need anyone to review my existing code. I provided it only to show that I'm capable of thinking for myself :->
This is a IE proxy settings and MS Firewall Client reconfiguration tool.
If I could figure out how to edit my OP, I'd break the long lines for you. I'd also post the changes which I've recently made.
By sites, I mean "physical sites", or businesses, hotels and coffee shops. My client's field staff are constantly on the go and they need a very simple way to reconfigure their browsers and printers as they move from site to site.
I am using KiXtart 4.50 beta 2a.
There are only WinXP clients, but they are a mix of RTM, SP1 and SP2.)
What I need is a function that will enumerate all of the .INI files in a folder, then generate a numbered menu of those files for the operator to choose, and exit with the name of the file as a new variable.
I freely admit that this is quite beyond my skill and experience; hence the title of the thread.
I'd prefer for the solution to run in a KiXtart DOS box, as I have very little VB, and no KiXforms, experience.
?" Please enter the number associated with the image to be applied :" Gets $NUMBER
Select Case $NUMBER=1 $IMAGE="Cashier" Case $NUMBER=2 $IMAGE="Fasttrack" Case $NUMBER=3 $IMAGE="Infoconn" Case $NUMBER=4 $IMAGE="Msoffstd" Case $NUMBER=5 $IMAGE="Msoffpro" Case $NUMBER=6 $IMAGE="odbc16bit" Case $NUMBER=7 $IMAGE="outlook97" Case $NUMBER=8 $IMAGE="phonedisc" Case $NUMBER=9 $IMAGE="registryprn" Case $NUMBER=10 $IMAGE="system" Case $NUMBER=11 $IMAGE="jetforms" EndSelect
Run "\\blah\blah\blah\blah\sysdiff.exe /apply /m \\blah\blah\blah\blah\$image.img"
Exit 1
This is a sample code but should give you some ideas. Hope this helps
Aaron
_________________________
If at first you don't succeed, try again. Then quit. There's no use being a damn fool about it. - W.C Fields
#139540 - 2005-05-1204:57 PMRe: Need a jump start...
xpanmanxxpanmanx
Starting to like KiXtart
Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
Thanks, Aaron - what I'm hoping for is a function which discovers and enumertes the .INI files, rather than a list of specified filenames.
The INIs may not always be of the same name, or quantity. For instance, if a user creates a .INI for his home network, and a few for some hotels which he frequents, I want the function to be able to pick up those filenames, and present them for selection, "automagically".
#139544 - 2005-05-1309:14 AMRe: Need a jump start...
NTDOCNTDOC Administrator
Registered: 2000-07-28
Posts: 11634
Loc: Space
Thanks to Richard H. for a better solution to the loop then I originally had.
Okay here is a version that should get you started. It will gather a list of all the .INI files in a given folder and then present them on screen for the user to make a choice.
This current code was tested using a folder named C:\CONTROL Which had 14 .INI files in the folder.
Which configuraton file do you want to use? 1. AdminSetup 2. Baltimore 3. Chicago 4. Dallas 5. Glendale 6. HongKong 7. Hotel 8. Leatherhead 9. London 10. LosAngeles 11. Montreal 12. Paris 13. Tokyo 14. WorkShop
Enter a number between 1 and 14, or '99' to quit: 8 You chose the configuration file Leatherhead
Please let us know if this script works okay for you or if you were wanting something else.
#139549 - 2005-05-1603:56 AMRe: Need a jump start...
xpanmanxxpanmanx
Starting to like KiXtart
Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
Thank you very much NTDOC! I was hoping for a pointer in the right direction, not the complete TripTik
All I did was replace the c:\control value with @SCRIPTDIR, and pass off the result to the rest of my script.
From the first read through your code, it is obvious that you have saved me from a singular hell: While I'm sure this amounted to a minor flexing of your coding muscle, it is clearly something that would've taken me at least a couple of dozen hours to construct.
#139550 - 2005-05-1603:59 AMRe: Need a jump start...
xpanmanxxpanmanx
Starting to like KiXtart
Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
Ahhhhhhhhhhh now this is elegant. And again, above and beyond the call. Thank you very much for giving so much of your weekend to my cause
Sadly, my knowledge of KiXforms is very limited. I'm going to have to learn this from the ground up, but my interest will be held fast by this real-world example you've given me.
#139551 - 2005-05-1605:16 AMRe: Need a jump start...
xpanmanxxpanmanx
Starting to like KiXtart
Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
Whoo hoo! Got it goin' on with KiXforms.
I copied my script verbatim into NTDOC's KiXforms code, where his comment indicated that I should.
I even learned enough (Baby steps, Bob, baby steps...) to change some simple UI settings in NTDOC's code.
As far as passing the INI location through to my original code, well, I monkeyed around with @SCRIPTDIR for a while, but it didn't work correctly after the script was packaged, then @SCRIPTDIR becomes the user's temporary folder!
So I used KiXscripts Editor's $EXEParams variable, instead. I added a quick syntax check and VOILA!
Thanks again, NTDOC. You're a lifesaver.
Here's my 1st production version. I hope you can figure out where NTDOC's code stops, and mine begins
Code:
;Turn on the break key. If this command is not present, and the operator halts execution, the operator will be forcibly logged off. Break on Color c+/n ? @scriptname $dummy = SetOption('wrapateol','on') ;dummy = SetOption('explicit','on')
@crlf + @crlf
$dummy = SetTitle (@scriptname)
;=============================================================================================== ;Syntax check If $exeparams = '' Color r+/n ? 'Syntax: site configuration.exe [path to inis]' ? 'example: c:\site configuration.exe c:\program files\site configuration' Color c+/n Beep Sleep 5 Exit EndIf ;===============================================================================================
If $sKiXVer < $sKiXMin $sMsg = MessageBox('This Script requires at least KiXtart '+$skiXMin,'Version Check',4112) Quit 1 EndIf
If @ERROR OR CheckKiXformsVersion($sKFMin) < $sKFMin $sMsg = MessageBox('This Script requires at least KiXforms '+ $sKFMin+@CRLF+'Current version is: '+CheckKiXformsVersion(),'Version Check',4112) Quit 1 EndIf
For $iIndex = 0 To Ubound($Choices) $ComboBox.AddItem($Choices[$iIndex]) Next
$Form.Show While $Form.Visible $=Execute($Form.DoEvents()) Loop Exit 0
Function SelectItem() Dim $Msg $Label.Text = 'The system will now be configured for '+$ComboBox.Text + '. Please click Ok when DONE is displayed.' $Label.Visible = 1 ;=============================================================================================== ;=============================================================================================== ;=============================================================================================== ;=============================================================================================== ;=============================================================================================== ;=============================================================================================== ;=============================================================================================== ;=============================================================================================== ;=============================================================================================== ;=============================================================================================== ;=============================================================================================== ;=============================================================================================== ;=============================================================================================== ;=============================================================================================== ;=============================================================================================== ;=============================================================================================== ;=============================================================================================== ;===============================================================================================
If $windows_default_printer <> 'FALSE' Gosub PRINTER_CONFIGURE EndIf
? ? Color B/W+ 'Done.' Color c+/n ?
Return
;=============================================================================================== :READ_LOCATION_INI Color y/n ? '======================================' Color c+/n
? 'Reading ' + $location_ini ? '---'
If NOT Exist ($location_ini) Color r+/n ? $location_ini + ' could not be found. Exiting.' Color c+/n Beep Exit EndIf
$ie_proxy_enable = ReadProfileString($location_ini,'ie proxy server settings','enable (true or false)') $ie_automatically_detect_settings = ReadProfileString($location_ini,'ie proxy server settings','automatically detect settings (true or false)') $ie_use_automatic_configuration_script = Ucase(ReadProfileString($location_ini,'ie proxy server settings','use automatic configuration script (url or false)')) $ie_use_a_proxy_server_for_your_lan = Ucase(ReadProfileString($location_ini,'ie proxy server settings','use a proxy server for your lan (name:port or false)')) $ie_do_not_use_proxy_server_for_addresses_beginning_with = Ucase(ReadProfileString($location_ini,'ie proxy server settings','do not use proxy server for addresses beginning with ( and/or urls seperated by commas)'))
$fwc_enable = ReadProfileString($location_ini,'fwc settings','enable (true or false)') $fwc_manual_isa_server_name = Ucase(ReadProfileString($location_ini,'fwc settings','manual isa server name (fq server name or ip or false)')) $fwc_enable_browser_configuration = ReadProfileString($location_ini,'fwc settings','enable browser configuration (true or false)')
$windows_default_printer = Ucase(ReadProfileString($location_ini,'printer settings','default printer (local name or unc or false)'))
;=============================================================================================== :FWC_CONFIGURE ? '...configuring ISA Server 2004 Firewall Client.'
If $fwc_enable = 'FALSE' Shell '"c:\program files\microsoft firewall client 2004\fwctool.exe" disable' Color y/n ? '======================================' Color c+/n Return Else Shell '"c:\program files\microsoft firewall client 2004\fwctool.exe" enable' EndIf
Function CheckKiXformsVersion(optional $KFMin) Dim $KFDll,$KFVer,$objSystem,$Main If NOT $KFMin $KFMin="2.3.0.45" EndIf $KFDll=ReadValue('HKCR\CLSID\{F89DF848-618A-46F9-8A1C-396EA442BDD3}\InprocServer32','') If @ERROR $CheckKiXformsVersion=@ERROR Exit $CheckKiXformsVersion EndIf $KFVer=GetFileVersion($KFDll,'BinFileVersion')+GetFileVersion($KFDll,'SpecialBuild') If @ERROR $CheckKiXformsVersion=@ERROR Exit $CheckKiXformsVersion EndIf If $KFVer < $KFMin Exit 13 EndIf $objSystem = CreateObject("Kixtart.System") $Main=$objSystem.Form() If @ERROR $CheckKiXformsVersion=@ERROR Exit $CheckKiXformsVersion EndIf $CheckKiXformsVersion=$KFVer EndFunction
Function ChangeSettings($Folder,$Type) Dim $File $File = Dir($Folder+'\'+$Type) While NOT @ERROR If NOT (GetFileAttr($File) & 16) $ChangeSettings = $ChangeSettings+'*'+Left($File,-4) EndIf $File = Dir() Loop $ChangeSettings=SubStr($ChangeSettings,2) EndFunction
#139552 - 2005-05-1609:23 AMRe: Need a jump start...
NTDOCNTDOC Administrator
Registered: 2000-07-28
Posts: 11634
Loc: Space
xpanmanx, You're quite welcome for the code.
Couple other issues/questions though.
This looks almost like you're expecting this to launch during a logon script. You're mixing code that would show on a DOS CONSOLE window which is one of the reasons for using KiXforms is to do away with that stuff.
You should normally not be showing anything except what can be seen in a GUI format within KiXforms using this method.
Questions:
1. Do you want the Admins to be able to make choices? (if so that can be done within KiXforms as well)
2. If you want the Admin to make a choice then why have different .ini files?
3. Why would you have the .ini configuration files in the same folder as the script unless they are isolated from other .ini files? Currently you're not filtering out specific ones so ALL .ini files would show up in the list.
Personally I would choose one way or the other. Either DO NOT give the Admin a choice beyond picking which configuration (then have the script automatically perform all tasks listed in the ini file) OR - Setup the KiXform to show/allow the choices that will be possible to change.
In any case I would remove or silence all code that attempts to ouput to a DOS window and setup the form to run from a shortcut on their desktop and use a COMMON folder on all systems.
Also, I would use a registry read for the firewall and other programs and not HARD CODE the path. If you need help or suggestions further in that area please let us know.