Page 1 of 1 1
Topic Options
#203425 - 2011-11-01 07:43 PM Shortcut on Desktop for Home Directory
lespaul_flame Offline
Fresh Scripter

Registered: 2011-07-13
Posts: 6
Loc: Phoenix
Sorry kind of new to this.... I have a simple script to create a home directory and I need a shortcut automatically added to the users desktop. Any ideas?

 Code:
:start

$user = @USERID ? "$user"
$userDir = "\\byte\Home\$user" 


if EXIST ("$userDir") and INGROUP("MCCCD-ORG\PVC-All-Employees")
	
	USE H: ("\\byte\Home\$user") 
	
	
else 
	md ("$userDir")
ENDIF



:end


Edited by Mart (2011-11-02 09:40 PM)
Edit Reason: Please use code tags when posting code.

Top
#203426 - 2011-11-01 08:13 PM Re: Shortcut on Desktop for Home Directory [Re: lespaul_flame]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
There is already a function written just for that task, called wshShortCut(). I've included an example of it below along with your existing code to show how it works. The Function code can be placed anywhere in your script, it is only executed if it is called. I usually keep all functions at the end of my scripts.

The function can be found here...
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=84115

 Code:
$user = @USERID
? $user
$userDir = "\\byte\Home\"+$user

If EXIST($userDir) and INGROUP("MCCCD-ORG\PVC-All-Employees")
   USE H: ("\\byte\Home\$user")
Else
   MD ($userDir)
ENDIF

$nul = wshShortcut("Home Directory",$userDir)



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

Top
#203427 - 2011-11-01 08:17 PM Re: Shortcut on Desktop for Home Directory [Re: lespaul_flame]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Also see How to use UDFs if you have any problems with functions.
Top
#203428 - 2011-11-01 08:36 PM Re: Shortcut on Desktop for Home Directory [Re: ShaneEP]
lespaul_flame Offline
Fresh Scripter

Registered: 2011-07-13
Posts: 6
Loc: Phoenix
Thanks so Much!!!
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 525 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 1.468 seconds in which 0.014 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