Page 1 of 2 12>
Topic Options
#198749 - 2010-06-01 03:53 PM Pinning Shortcuts to taskbar Windows7
nocke62 Offline
Fresh Scripter

Registered: 2005-03-30
Posts: 12
Loc: Ratingen, Germany
Hello,

I'm running in trouble by trying to pin some shortcuts to the win7 taskbar.
The following code is part of of a loginscript. After running the script, the shortcut is created in the folder "C:\temp". But it will not appear in the task bar. There is no error reported.
What may be wrong?

Regards
Wolfgang

 Quote:


; Create shortcut

$rc = wshShortcut("C:\temp\wolfgang.lnk","%systemroot%\system32\notepad.exe")
? "Result: " + $rc + "Error: " + @error + " " + @serror

; pin shortcut to taskbar

$RC=PinTo(c:\temp\wolfgang.lnk,"Taskbar")
? "Result: " + $rc + "Error: " + @error + " " + @serror



Top
#198750 - 2010-06-01 04:14 PM Re: Pinning Shortcuts to taskbar Windows7 [Re: nocke62]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
What are the results of your result lines?

Do you have the two UDFs included in your script. If not, paste them to the bottom of the script.

Top
#198751 - 2010-06-01 05:40 PM Re: Pinning Shortcuts to taskbar Windows7 [Re: Allen]
nocke62 Offline
Fresh Scripter

Registered: 2005-03-30
Posts: 12
Loc: Ratingen, Germany
Yes, both UDFs are included.

The first result line returns
0 Error: 0 Der Vorgang wurde erfolgreich beendet.

the second line returns
1 Error: 0 Der Vorgang wurde erfolgreich beendet.

Because the returncode for no errors in
wshshortcut() is 0 an in pinit()is 1, there are no errors during operation.

Regards Wolfgang

Top
#198752 - 2010-06-01 10:23 PM Re: Pinning Shortcuts to taskbar Windows7 [Re: nocke62]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
If I had to guess it's probably the lauguage differences in OSs.

If you right click on an icon in Win7 you get two options in English, "Pin to Taskbar" and "Pin to Start Menu". Your language is probably different. You might try changing the action lines in the UDF to match what you have.

 Code:
  if instr(@producttype,"Windows 7") and ($action="" or $action="Taskbar")
    $action="Pin to Taskbar"
    $location="\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\" + $shortcut
  else
    $action="Pin to Start Menu"
    $location="\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\" + $shortcut
  endif

Top
#198753 - 2010-06-02 12:09 AM Re: Pinning Shortcuts to taskbar Windows7 [Re: Allen]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
I wonder though if Windows 7 has special folder names for these as well that would remain the same on all OS?

Not updated for Vista/Win7 but something like one of these.
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=84651


Sample: http://msdn.microsoft.com/en-us/library/dd391662%28VS.85%29.aspx


Edited by NTDOC (2010-06-02 12:19 AM)

Top
#198754 - 2010-06-02 12:13 AM Re: Pinning Shortcuts to taskbar Windows7 [Re: NTDOC]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
The folders do exist, but for some reason, when you simply copy/create a shortcut to the folder, they don't show up on the Taskbar, even after a reboot. That's the reason behind the createobject shell nonsense.
Top
#198755 - 2010-06-02 12:21 AM Re: Pinning Shortcuts to taskbar Windows7 [Re: Allen]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
I used something like this on XP, not sure if its needed or can be modified to work on Windows 7 or not.

 Code:
Function AddToMyNetworkPlaces($Name,$Location,Optional $Comment)
  Dim $Nethood,$Shell,$S,$D,$T
  $AddToMyNetworkPlaces=1
  If Exist($Location)
    $Nethood=ReadValue('HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders','NetHood')
    If GetFileAttr($Nethood+'\'+$Name) & 16
    	; 'Link exists already. Exit the function. 
      Exit 80
    EndIf
    MD $Nethood+'\'+$Name
    $D=$Nethood+'\'+$Name+'\'+'Desktop.ini'
    $T=$Nethood+'\'+$Name+'\'+'target.lnk'
    $S = SetFileAttr($Nethood+'\'+$Name,1)
    $S = WriteProfileString ($D,'.ShellClassInfo','CLSID2','{0AFACED1-E828-11D1-9187-B532F1E9575D}')
    $S = WriteProfileString ($D,'.ShellClassInfo','FLAGS','2')
    $S = SetFileAttr($D,6)
    $Shell = CreateObject('wscript.shell')
    If @ERROR Exit @ERROR EndIf
    $S = $Shell.CreateShortcut($T)
    $S.TargetPath = $Location
    $S.WorkingDirectory = $Location
    If $Comment
      $S.Description = $Comment
    EndIf
    $S.Save
    If @ERROR Exit @ERROR Else $AddToMyNetworkPlaces=0 EndIf
  Else
    Exit 3
  EndIf
EndFunction

Top
#198762 - 2010-06-02 01:05 PM Re: Pinning Shortcuts to taskbar Windows7 [Re: nocke62]
nocke62 Offline
Fresh Scripter

Registered: 2005-03-30
Posts: 12
Loc: Ratingen, Germany
Many thanks for your response.
Allens hint put me in the right direction.
It is the difference in the language.
But not only this:
In the english version of Win7 the function is named "Pin to Taskbar"
In the german version the function is named "An Taskleiste anheften"
But in the context menu you found "Anheften an Taskleiste".
Lucky people, whose running the english version.
Thanks for your support.

Top
#198767 - 2010-06-02 03:15 PM Re: Pinning Shortcuts to taskbar Windows7 [Re: nocke62]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
If you get it working, please share.
Top
#198770 - 2010-06-04 09:49 AM Re: Pinning Shortcuts to taskbar Windows7 [Re: nocke62]
nocke62 Offline
Fresh Scripter

Registered: 2005-03-30
Posts: 12
Loc: Ratingen, Germany
Here is what I have changed for the german version:
Replace the "Action" with the correct words, depending on the OS Language.


 Code:
  if instr(@producttype,"Windows 7") and ($action="" or $action="Taskbar")
;    $action="Pin to Taskbar"
    $action="An Taskleiste anheften"
    $location="\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\" + $shortcut
	else
;    $action="Pin to Start Menu"
    $action="An Startmenü anheften"
    $location="\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\" + $shortcut
  endif


Maybe, it's possible to check the OS language and replace the action with language depended content, before running this part of the function.

Top
#198771 - 2010-06-04 03:34 PM Re: Pinning Shortcuts to taskbar Windows7 [Re: nocke62]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
I think a simple check of @SYSLang will do it. I'm willing to update the UDF with other languages if others want to provide their @SYSLang string and the two PinTo strings here.



Edited by Allen (2010-06-04 03:57 PM)

Top
#198774 - 2010-06-05 01:43 AM Re: Pinning Shortcuts to taskbar Windows7 [Re: Allen]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
That's cool and all to do Allen but sure would be nice if MS would just make some of this stuff for "folder" management easier to script regardless of language. Many of these items have an underlying GUID already it's just the shell and methods to access them are not all the same.
Top
#198775 - 2010-06-05 03:56 AM Re: Pinning Shortcuts to taskbar Windows7 [Re: NTDOC]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
Seems in this case MS purposely did this. Based on my google searches, MS wanted the users in control, not programs, putting icons on the taskbar. Seems kind of half-a$$ed to me... If we can do it this way... everyone can.
Top
#198776 - 2010-06-05 08:27 PM Re: Pinning Shortcuts to taskbar Windows7 [Re: Allen]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
@nocke or anyone with a German version of the OS... could you test this. If it doesn't work, please provide what @syslang is in your language. Thanks.

 Code:
Function PinTo($Shortcut, optional $Action)
  dim $Languages[1]
  $Languages[0]="0409English,Pin to Taskbar,Pin to Start Menu"
  $Languages[1]="0407German,An Taskleiste anheften,An Startmenü anheften"

  dim $path,$objshell,$objfolder,$objFolderitem,$colverbs,$objverb,$location,$langid
  $PinTo=1
  if not right($shortcut,3)="lnk"
    $shortcut=$shortcut + ".lnk"
  endif 
  if exist($shortcut)
    if getfileattr($shortcut) & 16
      exit 87
    else
      $path=left($shortcut,instrrev($shortcut,"\"))
      $shortcut=right($shortcut,-instrrev($shortcut,"\"))  
    endif
  else
    exit 2
  endif
  $langid=ascan($languages,@syslang,,,1)
  if $langid>-1
    if instr(@producttype,"Windows 7") and ($action="" or $action="Taskbar")
      $action=split($languages[$langid],",")[1]
      $location="\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\" + $shortcut
    else
      $action=split($languages[$langid],",")[2]
      $location="\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\" + $shortcut
    endif
  else
    exit 1815
  endif
  $objShell=CreateObject("Shell.Application")		
  $objFolder=$objShell.Namespace($path)
  $objFolderItem=$objFolder.ParseName($shortcut)
  $colVerbs=$objFolderItem.Verbs
  for each $objVerb In $colVerbs
    if join(split($objVerb.name,'&'),'')=$action	
      $objVerb.DoIt
      if exist($objShell.Namespace(26).self.path + $location)
        $PinTo=0
      else
        exit 82					 
      endif
    endif
  next
endFunction

Top
#198797 - 2010-06-08 03:48 PM Re: Pinning Shortcuts to taskbar Windows7 [Re: nocke62]
nocke62 Offline
Fresh Scripter

Registered: 2005-03-30
Posts: 12
Loc: Ratingen, Germany
@Allen,

@sylang returns 0409English
May be it depends on, that it is a Lenovo PC with pre installed Windows.
I don't know, if this windows is a "real german" windows, like a box product bought from Microsoft. Or may be it is an englich windows with a german desktop, like a win7 ultimate with mui.

I think we need another way to identify the used language.
Hope this will help you.

Regards,
Wolfgang

Top
#198798 - 2010-06-08 03:57 PM Re: Pinning Shortcuts to taskbar Windows7 [Re: nocke62]
Darknoon Offline
Fresh Scripter

Registered: 2005-03-24
Posts: 9
Hi !
Not working for me, with french Pro W7.
@syslang return "0409English", @error/@serror return 0/l'opération a réussi

in french (but not working) :
$action = Épingler à la barre des tâches
$action = Épingler au menu Démarrer

Top
#198799 - 2010-06-08 03:58 PM Re: Pinning Shortcuts to taskbar Windows7 [Re: Darknoon]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
I wonder what @userlang returns.?

I'll add the french once we sort this out. Thanks.

Top
#198800 - 2010-06-08 04:08 PM Re: Pinning Shortcuts to taskbar Windows7 [Re: Allen]
Darknoon Offline
Fresh Scripter

Registered: 2005-03-24
Posts: 9
@Userlang return 040CFrench for me
Top
#198801 - 2010-06-08 04:24 PM Re: Pinning Shortcuts to taskbar Windows7 [Re: Darknoon]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
ah-ha... so let's try this. I also think I need to check if the pinned icon is already there (add that later). I'm also not sure how well kix handles these special characters in your languages. I guess we'll figure it out.

 Code:
Function PinTo($Shortcut, optional $Action)
  dim $Languages[2]
  $Languages[0]="0409English,Pin to Taskbar,Pin to Start Menu"
  $Languages[1]="0407German,An Taskleiste anheften,An Startmenü anheften"
  $Languages[2]="040CFrench,Épingler à la barre des tâches,Épingler au menu Démarrer"

  dim $path,$objshell,$objfolder,$objFolderitem,$colverbs,$objverb,$location,$langid
  $PinTo=1
  if not right($shortcut,3)="lnk"
    $shortcut=$shortcut + ".lnk"
  endif 
  if exist($shortcut)
    if getfileattr($shortcut) & 16
      exit 87
    else
      $path=left($shortcut,instrrev($shortcut,"\"))
      $shortcut=right($shortcut,-instrrev($shortcut,"\"))  
    endif
  else
    exit 2
  endif
  $langid=ascan($languages,@userlang,,,1)
  if $langid>-1
    if instr(@producttype,"Windows 7") and ($action="" or $action="Taskbar")
      $action=split($languages[$langid],",")[1]
      $location="\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\" + $shortcut
    else
      $action=split($languages[$langid],",")[2]
      $location="\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\" + $shortcut
    endif
  else
    exit 1815
  endif
  $objShell=CreateObject("Shell.Application")		
  $objFolder=$objShell.Namespace($path)
  $objFolderItem=$objFolder.ParseName($shortcut)
  $colVerbs=$objFolderItem.Verbs
  for each $objVerb In $colVerbs
    if join(split($objVerb.name,'&'),'')=$action	
      $objVerb.DoIt
      if exist($objShell.Namespace(26).self.path + $location)
        $PinTo=0
      else
        exit 82					 
      endif
    endif
  next
endFunction



Edited by Allen (2010-06-08 04:32 PM)

Top
#198802 - 2010-06-08 04:30 PM Re: Pinning Shortcuts to taskbar Windows7 [Re: Allen]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
You got some German in the French line. Typo?
Anheften is German as far as I know so I think the French line should be changed to his.

 Code:
$Languages[2]="040CFrench,Épingler à la barre des tâches,Épingler au menu Démarrer"
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 1 of 2 12>


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

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

Generated in 0.317 seconds in which 0.202 seconds were spent on a total of 14 queries. Zlib compression enabled.

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