Link to home
Start Free TrialLog in
Avatar of essexboy80
essexboy80Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Kix Script Help

Hi,

I am using Kix Scripts to do my logins and map my drives and I am assigned them if user are in a group.

But I want to assign multiple drives to each group, how can I do this?

The code I am using to map a drive a present is here :

;;Map the Executive Drive
? "      Checking 'J Drive' group membership."
If InGroup("JDrive")
      ? "            Applying 'J Drive' group membership."
      $ScriptLog=$ScriptLog + @CRLF + " In J drive group" + @CRLF
      If Exist ( "J:" )
            Use J: /d
            If @Error=0
                  $ScriptLog=$ScriptLog + "    Disconnected J drive OK" + @CRLF
            Else
                  $ScriptLog=$ScriptLog + "    Couldn't disconnect J drive" + @CRLF
            EndIf
      EndIf

      Use J: $FileServer + "\Executive"
      If @Error=0
            $ScriptLog=$ScriptLog + "    Connected J drive OK" + @CRLF
      Else
            $ScriptLog=$ScriptLog + "    Couldn't connect J drive" + @CRLF
      EndIf
Else
      ? "            Not in group."
      $ScriptLog=$ScriptLog + @CRLF + " Not in J drive group" + @CRLF
EndIf
ASKER CERTIFIED SOLUTION
Avatar of robtk
robtk
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Brad Howe
Brad Howe
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of essexboy80

ASKER

Hi,

Thanks for your assistance I agree that maybe I had things over complicated.

I would appreciate your help with a few more points if possible please.

Basically I am writing this KIX Script to replace an existing Batch file that runs commands and calls a lot of PERL.

For Example I have this line in my current login script which calls a PERL script that changes peoples start menus (i have attached the content of the shortcut.pl)

      echo Setting up the shortcuts...
      %PERL% %ROOT%\bin\shortcuts.pl

Is there a better way for me to be doing this sort of thing?

Also printers, what is the best way to do them via KIX, currently I was going to do it like this :

;....
;.... Add new printers based on user group
;....


      ? "      Checking to see If you need printer 'HP 3600'."
If InGroup("HP3600")
      ? "      Adding printer 'HP 3600'."
      $ScriptLog=$ScriptLog + @CRLF + " In HP 3600 Printer group" + @CRLF
      If AddPrinterConnection ( $PrintServer + "\HP3600" ) = 0
            ? "            Added printer OK!"
      Else
            ? "            There was a problem adding this printer"
      EndIf
Else
      ? "            You dont need this printer."
      $ScriptLog=$ScriptLog + @CRLF + " Not in HP 3600 Printer group" + @CRLF
EndIf

      ? "      ."
      ? ""


;....
;.... Set default printers based on user group
;....


      ? "      Looking to set your default printer."
If InGroup("HP3600-Default")
      ? "      Setting default printer to 'HP 3600'."
      $ScriptLog=$ScriptLog + @CRLF + " In HP 3600 Default Printer group" + @CRLF
      If SetDefaultPrinter ( $PrintServer + "\HP Color LaserJet 3600" ) = 0
            ? "      Set default printer OK!"
      EndIf
EndIf

Thanks for all your help and I am sure I will have more questions.

Thanks

Paul


# shortcuts.pl
#
# * ensure users always have an up to date shortcut bar
# * add additional shortcut bar icons for certain users
# * setup any startup shortcuts required
#
use File::Copy;
use File::Basename;
use File::Path;
use Win32::Shortcut;

$user    = lc $ENV{USERNAME};
$profile = lc $ENV{USERPROFILE};
$host    = lc $ENV{COMPUTERNAME};
$windir  = lc $ENV{WINDIR};

$osbdir        = "$profile\\application data\\microsoft\\office\\shortcut bar\\office";
$programsdir   = "$profile\\start menu\\programs";
$startupdir    = "$programsdir\\Startup";
$appsdir       = "$programsdir\\Applications";
$accsdir       = "$programsdir\\Accessories";
$utlsdir       = "$programsdir\\Utilities";

rmtree($programsdir);
mkpath($programsdir);

$REUTERS = -e "c:\\program files\\reuters" ? 1 : 0;

# setup start menu
#
&shortcut("$profile\\start menu", 'c:\winnt\explorer.exe', '/e,u:\\', 'File Explorer');
&shortcut("$profile\\start menu", 'c:\Program Files\Internet Explorer\IEXPLORE.EXE', '', 'Internet Explorer');
&shortcut("$profile\\start menu", 'c:\winnt\explorer.exe', '::{D6277990-4C6A-11CF-8D87-00AA0060F5BF}', 'Scheduled Tasks');
&shortcut("$profile\\start menu", 'c:\winnt\explorer.exe', "/e,$profile\\recent", 'All Recent Files');

# setup start/programs/startup
#
&cleandir($startupdir);
&shortcut($startupdir, 'C:\Program Files\Sophos SWEEP for NT\ICMON.EXE', '', 'Sophos Anti-virus Intercheck', SW_SHOWMINNOACTIVE, 'C:\Program Files\Sophos SWEEP for NT');
#&shortcut($startupdir, 'f:\tools\bginfo.exe', '/if:\tools\bginfo.bgi /timer:0', 'BG Info');
if (!$REUTERS) {
	if ($ENV{UPDATESGROUP}) {
		&shortcut($startupdir, 'F:\DSWINDOW\DSSCHED.EXE', '', 'Datastream Scheduler');
	}
}

# setup start/programs/utilities
#
&cleandir($utlsdir);
&shortcut($utlsdir, 'f:\scripts\update printers.cmd', '', 'Reconfigure Printers');
&shortcut($utlsdir, 'f:\scripts\update shortcuts.cmd', '', 'Reconfigure Shortcut Bar and Start Menu');
#&shortcut($utlsdir, 'c:\Program Files\lotus\notes\nsd.exe', '-kill', 'Force Lotus Notes to quit','','u:\lotus\notes\data');
#&shortcut($utlsdir, 'C:\Lotus\EasySync Pro\xtndpc.exe', '/S /AN 3CmPlm /PN LtNts4', 'Syncronise Palm Pilot with Lotus Notes','','u:\lotus\notes\data');
&shortcut($utlsdir, 'C:\blp\API\dde\BbAddin.exe', '', 'Add Bloomberg Add-in to Excel');
&shortcut($utlsdir, 'C:\Program Files\Microsoft Office\office10\OSA.EXE', '-o', 'Restart Shortcut Bar');
&shortcut($utlsdir, 'C:\Program Files\Sophos SWEEP for NT\WSWEEPNT.EXE', '', 'Sophos Anti-virus Sweep');


# setup start/programs/accessories
#
&cleandir($accsdir);
&shortcut($accsdir, 'C:\Program Files\Windows NT\Accessories\wordpad.exe', '', 'WordPad');
&shortcut($accsdir, $windir.'\System32\clipbrd.exe', '', 'Clipboard Viewer');
&shortcut($accsdir, $windir.'\System32\mspaint.exe', '', 'Paint');
&shortcut($accsdir, 'C:\Program Files\Windows NT\Accessories\ImageVue\kodakimg.exe', '', 'Imaging');
&shortcut($accsdir, 'C:\Program Files\Windows NT\hypertrm.exe', '', 'Hyper Terminal');
&shortcut($accsdir, $windir.'\System32\charmap.exe', '', 'Character Map');
&shortcut($accsdir, $windir.'\System32\calc.exe', '', 'Calculator');
&shortcut($accsdir.'\Games', $windir.'\System32\sol.exe', '', 'Solitaire');
&shortcut($accsdir.'\Games', 'C:\Program Files\Windows NT\Pinball\PINBALL.EXE', '', 'Pinball');
&shortcut($accsdir.'\Games', $windir.'\System32\winmine.exe', '', 'Mine Sweeper');
&shortcut($accsdir.'\Games', $windir.'\System32\freecell.exe', '', 'FreeCell');
&shortcut($accsdir.'\Games', 'f:\winboard\winboard.exe', '', 'Chess');
&shortcut($accsdir.'\Entertainment', $windir.'\System32\cdplayer.exe', '', 'CD Player');
&shortcut($accsdir.'\Entertainment', $windir.'\System32\sndrec32.exe', '', 'Sound Recorder');
&shortcut($accsdir.'\Entertainment', $windir.'\System32\sndvol32.exe', '', 'Sound Volume');
&shortcut($accsdir.'\Entertainment', '"C:\Program Files\Windows Media Player\mplayer2.exe"', '', 'Windows Media Player');

# setup office shortcut bar and start/programs/applications
# 
foreach $dir ($osbdir, $appsdir) {
	&cleandir($dir);
	if (!$REUTERS) {
    		&shortcut($dir, 'C:\Program Files\Microsoft Office\office11\Excel.exe', '', 'Excel');
        		&shortcut($dir, 'C:\Program Files\Microsoft Office\office11\Winword.exe', '', 'Word');
#      		&shortcut($dir, 'C:\Program Files\lotus\notes\notes.exe', '=u:\lotus\notes\data\notes.ini', 'Lotus Notes');
        		&shortcut($dir, 'C:\Program Files\Microsoft Office\office11\Powerpnt.exe', '', 'PowerPoint');
                &shortcut($dir, 'C:\Program Files\Microsoft Office\office11\MSPUB.exe', '', 'Publisher');
                &shortcut($dir, 'C:\Program Files\Microsoft Office\office11\OUTLOOK.exe', '', 'Outlook');
                &shortcut($dir, 'C:\Program Files\Microsoft Office\office12\Excel.exe', '', 'Excel');
        		&shortcut($dir, 'C:\Program Files\Microsoft Office\office12\Winword.exe', '', 'Word');
        		&shortcut($dir, 'C:\Program Files\Microsoft Office\office12\Powerpnt.exe', '', 'PowerPoint');
			                &shortcut($dir, 'C:\Program Files\Microsoft Office\office12\MSPUB.exe', '', 'Publisher');
                &shortcut($dir, 'C:\Program Files\Microsoft Office\office12\OUTLOOK.exe', '', 'Outlook')
	}

	&shortcut($dir, 'C:\Program Files\Adobe\Acrobat 4.0\Acrobat\Acrobat.exe', '', 'Adobe Acrobat', SW_SHOWMAXIMIZED);
	&shortcut($dir, 'C:\Program Files\Adobe\Acrobat 5.0\Acrobat\Acrobat.exe', '', 'Adobe Acrobat', SW_SHOWMAXIMIZED);
	&shortcut($dir, 'C:\Program Files\Adobe\Acrobat 6.0\Acrobat\Acrobat.exe', '', 'Adobe Acrobat', SW_SHOWMAXIMIZED);
	&shortcut($dir, 'C:\Program Files\Adobe\Photoshop 6.0\Photoshp.exe', '', 'Adobe Photoshop');
	&shortcut($dir, 'C:\Program Files\Adobe\InDesign CS\InDesign.exe', '', 'Adobe InDesign');
	&shortcut($dir, 'C:\Program Files\Internet Explorer\IEXPLORE.EXE', '', 'Internet Explorer');
	&shortcut($dir, 'F:\vim\vim62\gvim.exe', '-y', 'Vim Advanced Text Editor');
    &shortcut($dir, 'C:\Program Files\Citrix\ICA Client', '', 'Citrix Program Neighbourhood');

	# perf tools
	#
	&shortcut($dir, 'C:\FACTSET\FDSW32.EXE', '', 'Factset');
	&shortcut($dir, 'C:\Program Files\FactSet\fdsw32.exe', '', 'Factset');
	&shortcut($dir, 'C:\Program Files\Internet Explorer\IEXPLORE.EXE', 'http://www.spfundinsight.com', 'SP Fund Insight','','','f:\icons\spinsight.ico') if $ENV{INSIGHTGROUP};
	&shortcut($dir, 'C:\Program Files\PerTrac Financial Solutions\PerTrac\PerTrac.exe', '', 'PerTrac');
	&shortcut($dir, 'C:\Program Files\Morningstar\Direct\MStarAWD.exe', '', 'MorningStar');
	&shortcut($dir, 'C:\PerTrac\PerTrac Reporting Studio 1.0.exe', '', 'PerTrac Reporting Studio');

	# data vendors
	#
	&shortcut($dir, 'C:\blp\Wintrv\wintrv.exe', '', 'Bloomberg Console');
	&shortcut($dir, 'C:\Program Files\CQG\CQGNet\Bin\logcln32.exe', '', 'CGQ');
	&shortcut($dir, 'F:\dswindow\dswindow.exe', '', 'Datastream');
	&shortcut($dir, 'C:\Program Files\datastream\datastream advance\advance.exe', '', 'Datastream Advance');
	&shortcut($dir, 'C:\Program Files\Code Red\Red Alerts\RedAlerts.exe', '', 'Code Red - Red Alerts');

	&shortcut($dir, 'C:\Program Files\Microsoft Office\office11\EXCEL.EXE', '"C:\Program Files\Reuters\PowerPlus\Ppp.xla"', 'PowerPlus Pro') 
		if -f  'C:\Program Files\Reuters\PowerPlus\Pppro.exe';
	&shortcut($dir, 'C:\Program Files\Reuters\kobra\Program\kobra.exe', '', 'Kobra');
	&shortcut($dir, 'C:\Program Files\Reuters\RG\Graphics.exe', '', 'Graphics Professional');
	&shortcut($dir, 'C:\Program Files\eSignal\winsig.exe', '', 'eSignal');
	&shortcut($dir, 'C:\Program Files\Refined Elliott Trader\RET.exe', '', 'Refined Elliott Trader');

	# risk analysis
	#
	&shortcut($dir, 'C:\Program Files\QuantalPRO\QuantalPRO.exe', '', 'Quantal PRO', '', '', 'C:\Program Files\QuantalPRO\QuantalPRO.ico');
	&shortcut($dir, 'C:\Program Files\Quantal_PRO_2.0\QuantalPRO_2.0.exe', '', 'Quantal PRO V2', '', '', 'C:\Program Files\Quantal_PRO_2.0\QuantalPRO_2.0.ico');

	# sav
	# 
	&shortcut($dir, 'C:\Program Files\Omgeo\AutoMatch\OGAutomatch.exe', '', 'Omgeo Automatch');
	&shortcut($dir, 'C:\ESGDesktop\Tuner\Castanet Tuner\Tuner.exe', '-start http://169.141.250.6:5282/Alert31 updateLaunch C true', 'Omgeo Alert', '', '', '');
    &shortcut($dir, 'C:\Goldman\GSPro\GSPro.exe', '', 'Goldman Pro');

	# trading
	#
	&shortcut($dir, 'C:\Program Files\TradeSmart\bin\TradeSmart.exe','','TradingScreen TradeSmart');
    &shortcut($dir, 'C:\Program Files\Macro Express3\macexp.exe','','MacroExpress');

	&shortcut($dir, 'C:\Program Files\Eze Castle Software\Client\Bin\EzeOMS.exe','','EZE OMS');
    &shortcut($dir, 'C:\Program Files\Eze Castle Software\Client\Bin\PMC.exe','','EZE PMC');

	# marketing
	#
	&shortcut($dir, 'l:\gmw5.exe', "/U:".$ENV{'USERNAME'}, 'Frontrange Goldmine');

	# admin
	#
	&shortcut($dir, 'C:\LITE\Bbm24win.exe', '', 'Barclays Online');
    &shortcut($dir, 'c:\Program Files\HansaWorld Enterprise 5.1\HansaWorld.exe', '', 'HansaWorld');
x
	# device apps
	#
	&shortcut($dir, 'C:\Program Files\NewSoft\BizCard 4.0 Eng\Bcr40.exe', '', 'Presto BizCard');
	&shortcut($dir, 'C:\Program Files\Iomega HotBurn Pro\Iomega HotBurn Pro.exe', '', 'Iomega HotBurn');
	&shortcut($dir, 'C:\Program Files\Agfa\ScanWise 1_40\scanwise.exe', '', 'Scanwise');
	&shortcut($dir, 'C:\Program Files\CeQuadrat\WinOnCD\WINONCD.EXE', '', 'WinOnCD');
	&shortcut($dir, 'C:\Program Files\Corex\CardScan\cs.exe', '', 'CardScan');
	&shortcut($dir, 'C:\Program Files\Windows NT\Accessories\ImageVue\kodakimg.exe', '', 'Imaging for Scanner') if $ENV{SCANGROUP}; 
	
	# bs db
	#
    &shortcut($dir, 'f:\mysqlcc\mysqlcc.exe', '', 'MySQL Control Centre') if $ENV{MYSQLCCGROUP};
	&shortcut($dir, $windir.'\explorer.exe', 'X:\db\Access Databases', 'All Databases', '', 'u:', 'C:\Program Files\Microsoft Office\office11\MSACCESS.exe', 4) if $ENV{ALLDSNGROUP};
	&shortcut($dir, 'C:\Program Files\Microsoft Office\office11\MSACCESS.exe', '"X:\db\Access Databases\cachedb.mdb"', 'Feed Cache Database', '', 'u:') if $ENV{CACHEDBGROUP};
	&shortcut($dir, 'C:\Program Files\Microsoft Office\office11\MSACCESS.exe', '"X:\db\Access Databases\perfdb.mdb"', 'Performance Database', '', 'u:') if $ENV{PERFDBGROUP};

	# bs apps
	#
	&shortcut($dir, 'f:\scripts\instdb.exe', '', 'Instrument Database');
	if ($ENV{BLOTTERGROUP} && -f 'C:\blp\Wintrv\wintrv.exe') { 
		&shortcut($dir, 'f:\scripts\blotter.exe', '', 'Blotter Application');
	}
  &shortcut($dir, 'f:\scripts\perfum.exe', '', 'Website User Manager') if $ENV{PERFUMGROUP};

	# morgan stanley sav apps
	# intalled 11th May 2004
	&shortcut($dir, 'C:\INSIGHT\BIN\INFOSTAT.EXE', '', 'Insight');
	&shortcut($dir, 'C:\INSIGHT\IS\CDSW\CDSW.EXE', '', 'Reporter 4.1');
		
	# admin apps
	#
	if ($ENV{ROOTGROUP}) {
		&shortcut($dir, 'F:\tools\putty.exe', '', 'Putty SSH Client');
		&shortcut($dir, 'F:\tools\vncviewer.exe', '', 'VNC Viewer');
		&shortcut($dir, 'F:\scripts\AD.msc', '', 'Active Directory Console', '', '', 'c:\winnt\system32\SHELL32.dll', 17);
    &shortcut($dir, 'f:\tools\netcon.exe', '', 'Network Information');
    &shortcut($dir, 'C:\WINNT\system32\mstsc.exe', '', 'RDP');
		&shortcut($dir, 'c:\Program Files\Scintilla Text Editor\SciTE.exe', '', 'Scintilla Text Editor');
        &shortcut($dir, 'c:\Program Files\Radmin\radmin.exe', '', 'Radmim');
	}
}

exit; 

########

sub shortcut # <destdir> <path> <args> <desc> <showcmd> <workdir> <icon> <icon no>
{
	return if ! -f $_[1];
	if (! -e $_[0]) {
		mkdir $_[0];
	}
	my $L = new Win32::Shortcut();
	my $workdir = $_[5] eq '' ? dirname($_[1]) : $_[5];
	my $name = $_[3] eq '' ? basename($_[1]) : $_[3];
	$L->Set("\"$_[1]\"", "$_[2]", $workdir, $_[3], $_[4], '', $_[6], $_[7]);
	$L->Save("$_[0]\\$name.lnk");
	$L->Close();
}

sub cleandir {
	if (! -e $_[0]) {
		mkdir $_[0];
	}
	opendir DIR, $_[0];
	my @files = grep  { /\S+\.lnk/i && -f "$_[0]\\$_" } readdir(DIR);
	closedir DIR;
	foreach my $f (@files) {
		unlink "$_[0]\\$f"
	}
}

Open in new window

Hi to add printers it is the same process.
 ;===============================================================================
; Script for assigning printers to DOMAIN-GROUP.
;===============================================================================
If InGroup("DOMAIN-GROUP")
If AddPrinterConnection ("\\printerserver\HP3600") = 0
? "Added printer connection...."
If SetDefaultPrinter ("\\printerserver\HP3600") = 0
? "Set default printer to \\printerserver\HP3600"
Endif
EndIf
EndIf
So you setup is fine.
If the PERL script works properly, why rebuild the wheel at the moment? With that said, if you have time, you could use the WshShortCut option to achieve the same results possibly.
ex : WshShortCut("%userprofile%\desktop\my notepad.lnk","c:\winnt\system32\notepad.exe")
Are you using an script.ini file with your script.kix?
 -Hades666
Hi,

Thanks I will give that a go, quick question though.

If you want to assign multiple printers to a group would you do it as follows :

If InGroup("DOMAIN-GROUP")
If AddPrinterConnection ("\\printerserver\HP3600") = 0
? "Added printer connection...."
If AddPrinterConnection ("\\printerserver\HP4600") = 0
? "Added printer connection...."
If AddPrinterConnection ("\\printerserver\HP5600") = 0
? "Added printer connection...."
If SetDefaultPrinter ("\\printerserver\HP4600") = 0
? "Set default printer to \\printerserver\HP4600"
Endif
EndIf
EndIf

What does the = 0 signify?

The PERL script works but at the moment I have a SET PERL = at the top of my batch file, how would I do this in kix?

No .ini file, should I be?

Thanks again

Paul
Yes.
The =0 signifies "IF PRINT IS NOT PRESENT"
Have you read the KIX Manual? The Kixtart.ini contains sections [YOUR GROUPS], which can include an entry for each domain or workgroup that is to be enabled for use of KiXtart. you can use this for printers, servernames everything. Think of it as a variable page.
http://www.kixtart.org/manual/
In KIX you can't do that, you would either make a VBS script to do it or BATCH.
Does this work for you?
Hades666
 
 
Hi,

This is one of my printer bits, it only maps the first printer and not the rest

If InGroup("12UGS-3rd")
If AddPrinterConnection ("\\Philby\OKI_B6300_1")
? "Added printer connection...."
If AddPrinterConnection ("\\Philby\fl3cl")
? "Added printer connection...."
If AddPrinterConnection ("\\Philby\3rdFloorSAV")
? "Added printer connection...."
If AddPrinterConnection ("\\Philby\CanonC5045")
? "Added printer connection...."
If AddPrinterConnection ("\\Philby\CanonC5045PS")
? "Added printer connection...."
If SetDefaultPrinter ("\\Philby\3rd Floor Large")
? "Set default printer to \\Philby\3rd Floor Large"
Endif
EndIf
EndIf
Endif
EndIf
EndIf
EndIf

Thanks

Paul
Hi,

Okay I have sorted the printers out now.

Anotehr question, it seems when you add a user to a group for the first time even if you re-run the login script they don't get the group until they reboot.

WHy is this?

Paul
When adding a user to a new group, the user must log out and log back in for it to take affect. While a reboot will accomplish that, it should not be required.
This is normal for windows as the user identity is cached when logged in.
Hades666
thanks all, got it working now.

Paul
perfect