Page 1 of 1 1
Topic Options
#197929 - 2010-03-01 03:04 PM New Script
wmb Offline
Fresh Scripter

Registered: 2010-02-25
Posts: 9
Loc: UK
Hello

We I've just managed to write my very first script. \:D

My script is below. I would like this to be desplayed when the users logs on and I would also like to show the connection of the drive when it happens or a line which shows, " your home drive has now been connected. what do I need to add to the script so that this can happen. At present the box runs minimised

 Code:
CLS
Small
Color b+/n
Box (0,0,24,90,GRID) ; 'background grid'
Color b/n
Box (8,21,18,71,Å) ; 'shadow' of the box
Color g+/n
Box (7,20,17,70,FULL)
;
Color w+/n
AT ( 9,25) "Userid : " ; display some text strings
AT (10,25) "Full name : "
AT (11,25) "Privilege : "
AT (12,25) "Workstation : "
AT (13,25) "Domain : "
;
Color y+/n
AT ( 9,45) @userid ; ...and some macro's
AT (10,45) @fullname
AT (11,45) @priv
AT (12,45) @wksta
AT (13,45) @domain
SetConsole("show")

If InGroup ("desktop")
	Use H: "\\servername\%username%$"
EndIf


also can you set a default printer based on a computer. We have computers in different room and we would like to set default printer based on the computer not the user


Edited by Glenn Barnas (2010-03-01 03:56 PM)
Edit Reason: Add code tags

Top
#197930 - 2010-03-01 03:48 PM Re: New Script [Re: wmb]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Are you running an AD Domain? If so, no script should be necessary to map home drives, unless you're still manually sharing individual user folders (which is so 1990's).

A single "USERS" share is all that is necessary. Defining the user share in their profile creates the folder AND sets proper permissions all in one step.

There are several methods of setting the printer - you can put computers into specific OUs or Groups based on the room they are in. UDFs exist to perform these InOU or InComputerGroup tests.

The commercial login script available on our web site will do this, and even provide per-computer default setting based on a table in the configuration file. No coding needed.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#197933 - 2010-03-01 04:42 PM Re: New Script [Re: Glenn Barnas]
wmb Offline
Fresh Scripter

Registered: 2010-02-25
Posts: 9
Loc: UK
I am sorry, I should have put more information. I used "use H:" as an example, but in fact I have a number of drive letters I want to mapp hence the question

Wayne


Edited by wmb (2010-03-01 04:51 PM)

Top
#197934 - 2010-03-01 06:10 PM Re: New Script [Re: wmb]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
There are several issues in play here - you are using individual admin shares for each user. This is very "old schoool" and not really a good practice anymore. That aside, you must map the drive with a UNC path that includes a "$" - this is a reserved identifier in Kix. Thus, your command
 Code:
Use H: "\\servername\%username%$"
is actually being interpreted as
"connect the H: drive to the share called %USERNAME% (plus the contents of the $ variable, which is likely empty)". The point is - the command doesn't do what you think and the connection likely fails.

One way to make this work is to use a double "$", but that isn't good practice. A better way is to include a
 Code:
$Rc = SetOption('NoVarsInStrings', 'On')
option in your script. This tells Kix not to process any "$" inside of strings.

Further, if your script window isn't being displayed, it's likely due to default policy settings. We generally recommend that login scripts be "run visible" via GPO settings. The default is to run minimized.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#197935 - 2010-03-01 07:34 PM Re: New Script [Re: Glenn Barnas]
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
 Code:
if ingroup('somegroup')
net use x: '\\server\share'
if not @error
$nul=sendmessage(@wksta, 'x: drive connected')
endif
endif
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#197944 - 2010-03-02 01:29 PM Re: New Script [Re: Radimus]
wmb Offline
Fresh Scripter

Registered: 2010-02-25
Posts: 9
Loc: UK
Ok, I've tried everthing and I cannot get it to work.

My display box pops up and shows the user name, domain, date, like I've asked in the script, but I just cannot get it to display a message to the user that the drives have been connected, even though the drives have been connect, showing the mail part of my script is working.

What am I missing : (


Edited by wmb (2010-03-02 01:30 PM)

Top
#197946 - 2010-03-02 02:36 PM Re: New Script [Re: wmb]
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
Look closely at line 14 and make sure the 3rd parameter is correct
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#197947 - 2010-03-02 03:00 PM Re: New Script [Re: Radimus]
wmb Offline
Fresh Scripter

Registered: 2010-02-25
Posts: 9
Loc: UK
I really don't understand, 3rd parameter???? on line 14???
Top
#197948 - 2010-03-02 04:06 PM Re: New Script [Re: wmb]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
wmb, can you re-post what you are currently working with?
Top
#197952 - 2010-03-02 08:23 PM Re: New Script [Re: BradV]
wmb Offline
Fresh Scripter

Registered: 2010-02-25
Posts: 9
Loc: UK
Sure here it is, I know it a basic script but this is all new to me

 Code:
;************************************************************************* 
; Script Name: Logon.kix
; Author: WMB 
; Date: 01/03/2010
; Last Ammended: 01/03/2010
; Description: Logon Script for EVault Corp. 
;************************************************************************* 
;************************** 
Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')
;************************** 

CLS
Small
Color b+/n
Box (0,0,24,90,GRID) ; 'background grid'
Color b/n
Box (8,21,18,71,Å) ; 'shadow' of the box
Color g+/n
Box (7,20,17,70,FULL)
Color w+/n
AT ( 9,25) "Userid : " ; display some text strings
AT (10,25) "Full name : "
AT (11,25) "Privilege : "
AT (12,25) "Workstation : "
AT (13,25) "Domain : "
Color y+/n
AT ( 9,45) @userid ; ...and some macro's
AT (10,45) @fullname
AT (11,45) @priv
AT (12,45) @wksta
AT (13,45) @domain
SetConsole("show")
Use "*" /DELETE
Use X: "\\server\sound"
If InGroup ("desktop") or InGroup ("temp_users")
Use H: "\\server\%username%$"

EndIf
If InGroup ("staff") or InGroup ("tusers")
Use Z: "\\server\share1"
EndIf

If InGroup ("HR") = 1
Use p: "\\server\share"
EndIf

If Exist("C:\documents and settings\%USERNAME%\desktop\HR.lnk")
DEL "C:\documents and settings\%USERNAME%\desktop\HR.lnk"

If Exist("C:\documents and settings\%USERNAME%\desktop\HR1.lnk") = 0
Copy "P:\HR\hr1.lnk" "C:\documents and settings\%USERNAME%\desktop"
EndIf

If  InGroup ("HR") = 0
If Exist("C:\documents and settings\%USERNAME%\desktop\HR1.lnk")
DEL "C:\documents and settings\%USERNAME%\desktop\HR1.lnk"
EndIf
EndIf

If InGroup ("web")
Use w: "\\server\web"
EndIf
	
If InGroup ("LIS")
Use s: "\\server\share1"
Use w: "\\server\share2"
Use Y: "\\server\share3"
Endif

If InGroup ("reg")
Use u: "\\server\reg"
EndIf

If InGroup ("student") or InGroup ("coursework") or InGroup ("lectures") or InGroup ("course")
Use Y: "\\server\coursework"
EndIf

If InGroup ("data")
Use o: "\\server\data$"
EndIf

If InGroup ("Students")
	Use s: "\\server\tempshare"
	Use Y: "\\server\coursework"
	Use h: "\\server\%username%$"
EndIf


Edited by Allen (2010-03-02 09:48 PM)
Edit Reason: added code tags

Top
#197953 - 2010-03-02 09:52 PM Re: New Script [Re: wmb]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
Missing Endif here:

 Code:
If Exist("C:\documents and settings\%USERNAME%\desktop\HR.lnk")
  DEL "C:\documents and settings\%USERNAME%\desktop\HR.lnk"
Endif

Top
#197954 - 2010-03-02 10:34 PM Re: New Script [Re: Allen]
wmb Offline
Fresh Scripter

Registered: 2010-02-25
Posts: 9
Loc: UK
Hello there

It's not a problem to say thank you as I always do when I post to forums. I have posted my script as it is still not doing what I would like it to do and I was asked to post so I can gain some more help.

I wanted the box which pops up to display to the user when the drive is mapped

wayne

ps thank you for your comments on adding the endif, but I have added and endif as a double endif on line 61 and 62 \:\)


Edited by wmb (2010-03-02 10:40 PM)

Top
#197956 - 2010-03-02 10:40 PM Re: New Script [Re: wmb]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
 Quote:
It's not a problem to say thank you as I always do when I post to forums. I have posted my script as it is still not doing what I would like it to do and I was asked to post so I can gain some more help.


I assume you are responding to my signature... if so, it's generic to every post I make... so it's not personal. \:\)

Top
#197957 - 2010-03-02 10:45 PM Re: New Script [Re: Allen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
I don't see any code where you are trying to display the drive information. Which drive(s) do you want to display info on?
Top
#197959 - 2010-03-02 11:14 PM Re: New Script [Re: Allen]
wmb Offline
Fresh Scripter

Registered: 2010-02-25
Posts: 9
Loc: UK
Hi

I tried what someone suggested above but it did not work, what I would like to happen - If a user is in a group and the drive is mapped I would like the use to see a message like, " Z: drive had now been connected to your computer" but I want this message only if a drive is connected. Also I would like to launch a text file when the script starts so I can show a message of the day

Thanks for your help

wayne

Top
#197960 - 2010-03-02 11:58 PM Re: New Script [Re: wmb]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
I can tell you based on experience, most users will not even read these types of messages. However to add this info you would do something like the following. (I did not test)

Please see the FAQs - http://www.kixtart.org/forums/ubbthreads.php?ubb=postlist&Board=5&page=1, specifically find "how to use a UDF."

 Code:
$x=14
$y=45

If InGroup ("desktop") or InGroup ("temp_users")
  mapdrive("H:","\\server\%username%$$",$x,$y)
EndIf

$x=$x+1  ;move down one line
If InGroup ("staff") or InGroup ("tusers")
  mapdrive("Z:","\\server\share1",$x,$y)
EndIf

$x=$x+1  ;move down one line
If InGroup ("HR")
  mapdrive("p:","\\server\share",$x,$y)
EndIf



The code below is a UDF (User defined function) Copy this code to the bottom of your script so the code above will work.
 Code:
function mapdrive($letter,$share, optional $locationX,$locationY)
  use $letter $share
  if @error=0
    if $locationX
      at($locationX, $locationY) + "Drive " + $letter + " Mapped"
    endif
  endif
endfunction 

Top
#197961 - 2010-03-03 01:11 AM Re: New Script [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Allen hasn't yet learned that IT is a thankless job! \:D ;\)

Honestly, you'd be surprised how many times we provide a solution and never hear back that it worked. The feedback is important, because what works in one environment may not work in others, especially in an international community. That feedback makes us all smarter (and somtimes more humble).

In terms of your script, you're getting hung up with the AT formatting / positioning.. it's a common feature that new scripters employ. You'll find, however, that once you approach the limits of the console window size, AT becomes difficult to manage. I understand that you want the first part of the message indented a bit, and the next part pushed over a bit more.. Simply padding with spaces will accomplish your goal in a single line, and allow the screen to scroll when necessary. Consider the following adaptation:
 Code:
Color w+/n
Right("                         Userid : ", 25) Color y+/n @USERID ?
Right("                         Full name : ", 25) Color y+/n @FULLNAME ?
Right("                         Privilege : ", 25) Color y+/n @PRIV ?
Right("                         Workstation : ", 25) Color y+/n @WKSTA ?
Right("                         Domain : ", 25) Color y+/n @DOMAIN ?
Of course, the Right() isn't needed for this - you could simply insert the appropriate number of spaces to pad the messages so they align. I wanted to show how you can use Right (or Left) to pad a message - especially if the message contains a variable amount of information. For example, if you wanted 3 columns, you could do this to display $A, $B, and $C:
 Code:
$A='Fred'
$B='Smyth'
$C='Programmer'
Right('          ' + $A, 10)
Left(' ' + $B + '          ', 11)
' ' $C @CRLF
This assumes that each variable would be limited to 10 characters, separated with one space.

Just one of many ways to skin the proverbial cat, and you might find it more flexible that using AT commands.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#197962 - 2010-03-03 09:16 AM Re: New Script [Re: Glenn Barnas]
wmb Offline
Fresh Scripter

Registered: 2010-02-25
Posts: 9
Loc: UK
OMG!! you guys I am going to have to sit and really study what you have sent me here. I am a newbe remember I'll get back to you and let you know who it goes

wayne

Top
#197965 - 2010-03-03 11:54 AM Re: New Script [Re: wmb]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
Wayne,

I have to agree with Allen that most users won't even look at the display. Most usually will just log in and then wander off to get coffee or something. The most important thing is that you need to know if a problem happens. You can do this by writing error messages to a log file. Keep a running status variable that tells you if an error has occurred. If so, write the log file to a server share somewhere. You can have an admin script sitting somewhere watching that share and alert you to any problems. But that is starting to get into advanced scripting. \:\)

Regards,

Brad

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 765 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.11 seconds in which 0.064 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org