Page 1 of 1 1
Topic Options
#209660 - 2014-11-19 03:41 PM Basic script question from a noob
Kevin_Wandtke Offline
Just in Town

Registered: 2014-11-19
Posts: 3
Loc: WI
So have run across KIX but never worked with it. I'm now under the gun to use it to do what I think should be a simple task... replace drive mappings. I personally hate them but the place I'm at has run them forever and you know how users can get .. if it's not on the "L:" drive they have no clue. Now, corporate security (and I've been at this game too long not to see a big stick that I can wield) has said "get rid of drive maps .. now!" . Seems too many have gotten burned with various forms of crypto locker & variants.

Anyway, been told to make this happen .. started looking at KIX and am already seeing things I'd like to try but I need this basic thing very fast and hope somebody could send me one example or steer me in the right direction to get me started. Our login scripts do nothing but map drives .. 6 to be precise ... and a "Z:" to the users home folder ... so all I want to do is replace the NET USE G: \\server\public with a shortcut on their desktop .. I guess using an ICON of some sort (maybe if I can make it look nice they'll complain less? .. naaa)

Thanks up front ....

Top
#209661 - 2014-11-19 04:21 PM Re: Basic script question from a noob [Re: Kevin_Wandtke]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
If it is really this simple, you should be able to do something like the following for each of the mapped drives. Keep in mind that shortcuts will be over-written to the desktop every time they log in with the way the code is below.

 Code:
if exist("G:\")
  USE G: \\server\public /delete /persistent
endif
$RC=wshshortcut("Public on Server","\\server\public")


You will need the UDF
WshShortCut -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=84115#Post84115

How to use UDFs -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=81943#Post81943

The rest of the UDFs are here -
http://www.kixtart.org/forums/ubbthreads.php?ubb=postlist&Board=7&page=1

Top
#209662 - 2014-11-19 04:38 PM Re: Basic script question from a noob [Re: Allen]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
A simple fix to avoid multiple shortcuts for the same and to make sure it points to the correct drive (user can do strange things).

 Code:
If Exist("G:\")
	Use G:\\server\public /delete /persistent
EndIf

$desktop = ExpandEnvironmentVars(%userprofile%)
$desktop = $desktop + "\Desktop"

If Exist($desktop + "\Public on server.lnk")
	Del $desktop + "\Public on server.lnk"
EndIf
$RC = wshshortcut("Public on Server", "\\server\public")
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#209663 - 2014-11-19 04:40 PM Re: Basic script question from a noob [Re: Mart]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Mart, The code I posted will just overwrite the existing Shortcut, and only recreate it if the shortcut has been deleted or renamed.
Top
#209664 - 2014-11-19 04:55 PM Re: Basic script question from a noob [Re: Allen]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Oh ok. I thought it just created a shortcutname (2) style shortcut if it already exists. Learned something.

BTW: if it are shortcuts to drives then setting a nice drive icon for the shortcut will make the transition easier for the users. Just a cosmetic remark not a requirement.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#209665 - 2014-11-19 05:08 PM Re: Basic script question from a noob [Re: Mart]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
FYI - My Universal Login Script can do drive mappings, shortcuts, or both. With this, you can transition from drives to both to just shortcuts.

GUI management, free and commercial support, and lots of ways to manage resource mapping, including AD attribute, network subnet, user or computer OU in addition to the usual by-Group control.

More info is available here.

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

Top
#209667 - 2014-11-19 11:23 PM Re: Basic script question from a noob [Re: Allen]
Kevin_Wandtke Offline
Just in Town

Registered: 2014-11-19
Posts: 3
Loc: WI
Well I thought it was simple ..
I did this ... copied the UDF to this below Exit 1 ... and ran it. It puts a file on my desktop OK .. named G .. but it's not a .lnk .. it's a file and if you click on it the system prompts you as to what to open it with. So what did I miss?

 Code:
if exist("G:\")
  USE G: \\frafile\shared /delete /persistent
endif
$RC=wshshortcut("G:_Drive","\\frafile\shared")

Exit 1

function wshShortCut($shortcutname,$targetpath,optional $arguments, optional $startdir, optional $iconpath, optional $style,optional $description,optional $hotkey)
  dim $shell, $desktop, $shortcut, $index, $iconinfo, $iconindex,$scdir,$rc
  $wshshortcut=1
  $shell = createobject("wscript.shell")
  if $shell
    if ucase(right($shortcutname,4))=".URL" or ucase(right($shortcutname,4))=".LNK"
      ;do nothing 
    else
      if ucase(left($targetpath,5))="HTTP:" or ucase(left($targetpath,6))="HTTPS:" or ucase(left($targetpath,4))="FTP:"
        $shortcutname=$shortcutname + ".url"
      else
        $shortcutname=$shortcutname + ".lnk"
      endif
    endif
    if right($targetpath,2)=",1"
      $targetpath=left($targetpath,-2)
    else
      if instr($shortcutname,".lnk") and not exist($targetpath)
        exit 2
      endif
    endif
    if instr($shortcutname,"\")=0
      $Desktop = $shell.SpecialFolders("Desktop")
      $shortcutname=$desktop + "\" + $shortcutname
    else
      $scdir=substr($shortcutname,1,instrrev($shortcutname,"\"))
      if not exist($scdir)
        md $scdir
        if @error
          exit @error
        endif
      endif
    endif
    $shortcut = $shell.createshortcut($shortcutname)
    if $shortcut
      $shortcut.targetpath = $targetpath
      if $iconpath and instrrev($shortcutname,".lnk")
        $shortcut.iconlocation = $iconpath
      endif
      if $arguments
        $shortcut.arguments = $arguments
      endif
      if $startdir
        $shortcut.workingdirectory = $startdir
      endif
      if $style
        $shortcut.windowstyle = $style
      endif
      If $description and instrrev($shortcutname,".lnk")
	  $shortcut.description = $description
      EndIf
      if $hotkey
        $shortcut.hotkey = $hotkey
      endif
      $shortcut.save
      if @error
        exit @error
      endif
      if instrrev($shortcutname,".url") and $iconpath
        $index=instrrev($iconpath,",")
        if $index=0
          $iconindex=0
        else
          $iconindex=split($iconpath,",")[1]
          $iconpath=split($iconpath,",")[0]
        endif
        $rc=writeprofilestring($shortcutname,"InternetShortcut","IconFile",$iconpath)
        $rc=writeprofilestring($shortcutname,"InternetShortcut","IconIndex",$iconindex)
      endif
      $shortcut = 0
      $wshshortcut=0
    else
      exit @error
    endif 
  else
    exit @error
  endif 
endfunction


Edited by Mart (2014-11-20 09:32 AM)
Edit Reason: Please use code tags when posting code.

Top
#209668 - 2014-11-20 12:11 AM Re: Basic script question from a noob [Re: Kevin_Wandtke]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Are you sure its not a link? Might you open a command prompt and navigate to %userprofile%\desktop directory and do a dir *.lnk to see if it is there, or just a dir to see what kind of file it is.

Also, noticed a bug in the sample code... this line
USE G: \\frafile\shared /delete /persistent
should have quotes around the server path
USE G: "\\frafile\shared" /delete /persistent

Top
#209669 - 2014-11-20 12:12 AM Re: Basic script question from a noob [Re: Allen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Oh... its the ":". Not a valid character for file names.
Top
#209670 - 2014-11-20 01:02 AM Re: Basic script question from a noob [Re: Allen]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
 Originally Posted By: Allen


or http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Board=7&Number=82930 \:\)
_________________________
!

download KiXnet

Top
#209682 - 2014-11-23 04:27 PM Re: Basic script question from a noob [Re: Lonkero]
Robdutoit Offline
Hey THIS is FUN
***

Registered: 2012-03-27
Posts: 363
Loc: London, England
I am a bit late to the question and I don't think that my solution would help you with cases like cryptolocker etc.

But if you are interested I created code to add libraries to the windows 7 libraries and pointed them to locations on the server! I also redirected existing libraries to locations on the server. I suspect that cryptolocker would be able to affect libraries so probably not any use to you, but if you just want to get rid of mapped drives - I could find my code for you!

Top
#209684 - 2014-11-24 07:49 PM Re: Basic script question from a noob [Re: Allen]
Kevin_Wandtke Offline
Just in Town

Registered: 2014-11-19
Posts: 3
Loc: WI
 Originally Posted By: Allen
Oh... its the ":". Not a valid character for file names.


So with the other answers I'm looking at the rest and then I saw this one and I said .. ":"? .. then .. sure that was it it now works perfect .. Thank you guys ....

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
2 registered (morganw, mole) and 414 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.058 seconds in which 0.024 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