Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with a "Pin-to-taskbar"-Script 1

Status
Not open for further replies.

CheckzenFiive

Technical User
Apr 28, 2011
16
DE
Hello there :- )


I´ve got a problem:

I´ve written a script that pins applications to the taskbar.

It looks like this:

___________________________________________________________________

on error resume next
Set objShell = CreateObject("Shell.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
set ArgObj = wscript.Arguments

dim PfadEXE
dim PinModus
dim Sprache
dim DebugMode

Debugmode = 1
PfadEXE = argobj(0)
PinModus = argobj(1)
Sprache = argobj(2)

if DebugMode = 1 then
msgbox "-" & PfadEXE & "- -" & PinModus & "- -" & Sprache & "-"
end if


strlPath = PfadEXE
strFolder = objFSO.GetParentFolderName(strlPath)
strFile = objFSO.GetFileName(strlPath)
Set objFolder = objShell.Namespace(strFolder)
set objFolderItem = objFolder.ParseName(strFile)
Set colVerbs = objFolderItem.Verbs
For each itemverb in objFolderItem.verbs
if Sprache = 1 Then
if PinModus = 1 Then
If Replace(itemverb.name, "&", "") = "An Taskleiste anheften" Then itemverb.DoIt
end if
if PinModus = 0 Then
If Replace(itemverb.name, "&", "") = "Von Taskleiste lösen" Then itemverb.DoIt
end if
End if
if Sprache = 0 then
if PinModus = 1 then
If Replace(itemverb.name, "&", "") = "Pin to taskbar" Then itemverb.DoIt
End if
if PinModus = 0 then
If Replace(itemverb.name, "&", "") = "Unpin this program from taskbar" Then itemverb.DoIt
End if
end if
next
___________________________________________________________________



So the script works like this:

Open cmd.exe -> Insert Script -> Insert applicationpath -> 1 / 0 for pin or unpin -> 1 / 0 for german / english.

Example: "C:\Users\Desktop\pin.vbs" "C:\Windows\Explorer.exe" 1 1


My problem is that I want to pin the applications with arguments/parameters like "explorer.exe -e".


Does anyone have an idea how I can realize this?



Thanks in advance,


CheckzenFiive



 
Collect the arguments and iterate them through a select case.

Also, your Arguments object (ArgObj) should follow that same naming convention as your other objects/vars

example
Code:
...
set objArgs = Wscript.Arguments

if (objArgs.count) then
    for i = 0 to objArgs.count - 1
        select case lcase(objArgs(i))
            case "-german" : intLanguage = 1
            case "-english" : intLanguage = 0
            case "-pin" : boolPin = true
            case "-unpin" : boolPin = false
            case "-o" : strObjectToPin = objArgs(i + 1)
        end select
    next
else
    msgbox "You didn't pass any arguments"
end if
...

pin.vbs -english -unpin -o "c:\path\to\taskbar\pinnedObject"


-Geates


"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom
 
Hello Geates,

thanks a lot for your help.
But I can´t get it to work.
Might you deploy it into my program? :- )


Cheers
Checkzen
 
can you be more specific? what can't you get to work? what command are using?

-Geates

Future Note:
Also, this is not a solution. It's a consideration. It's written "generically", not specific for your program. It's up to you to figure out how to implement it.


"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom
 
Well,

I´m completly new to scripting.
And I don´t know how to implement your code into my program.

Thanks for the suggestions anyway :- )



Cheers
Checkzen
 
The code you've provided would indicate that you have some knowledge with coding. Implementation should be fairly straight forward.

Simply change the name of the vars to reflect the ones you use.
Then replace you code that reads arguments with the code I posted.

Code:
on error resume next
set objShell = CreateObject("Shell.Application")
set objFSO = CreateObject("Scripting.FileSystemObject")
set objArgs = wscript.Arguments

dim PfadEXE
dim PinModus
dim Sprache
dim DebugMode

Debugmode = 1
[red][s]
PfadEXE = argobj(0)
PinModus = argobj(1)
Sprache = argobj(2)[/s][/red]

[green]
if (objArgs.count) then
    for i = 0 to objArgs.count - 1
        select case lcase(objArgs(i))
            case "-german" : Sprache = 1
            case "-english" : Sprache = 0
            case "-pin" : PinModus = 1
            case "-unpin" : PinModus = 0
            case "-o" : PfadEXE = objArgs(i + 1)
        end select
    next
else
    msgbox "You didn't pass any arguments"
end if
[/green]

if DebugMode = 1 then
msgbox "-" & PfadEXE & "-   -" & PinModus & "-    -" & Sprache & "-"
end if

strlPath = PfadEXE
strFolder = objFSO.GetParentFolderName(strlPath)
strFile = objFSO.GetFileName(strlPath)

Set objFolder = objShell.Namespace(strFolder)
set objFolderItem = objFolder.ParseName(strFile)
Set colVerbs = objFolderItem.Verbs

For each itemverb in objFolderItem.verbs
   if Sprache = 1 Then
      if PinModus = 1 Then
         If Replace(itemverb.name, "&", "") = "An Taskleiste anheften" Then itemverb.DoIt
      end if
      if PinModus = 0 Then
         If Replace(itemverb.name, "&", "") = "Von Taskleiste lösen" Then itemverb.DoIt
      end if
   End if
   if Sprache = 0 then
      if PinModus = 1 then
         If Replace(itemverb.name, "&", "") = "Pin to taskbar" Then itemverb.DoIt
      End if
      if PinModus = 0 then
         If Replace(itemverb.name, "&", "") = "Unpin this program from taskbar" Then itemverb.DoIt
      End if
   end if
next

-Geates


"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Hello again and thanks for the help.
I´ve tried it with the code you provided.

But this isn´t working as well.
If I keep the "debugmode" on, I see that it doesnt pass trough any information.
-> The vars "Sprache", "PinModus" and "PfadEXE" are empty?


Cheers
Checkzen
 
Before you ask:
I don´t get any error when running the script. :- )
 
Okay..
..it´s running now.
I´ve changed all "objargs" to "argobj"
But that´s not what I was looking for.

I still can´t pass any arguments / parameters in the pinned link.

I wanted to link an application to the taskbar with parameters / arguments inside (like C:\Programs\Acrobat Reader.exe abcd.pdf).



Cheers
Checkzen

 
what does your command line look like? Also, throw a couple msgboxs in the argument loop to see what arguments are returned.

Code:
if (objArgs.count) then
    [green]msgbox "I found arguments"[/green]
    for i = 0 to objArgs.count - 1
        [green]msgbox "Arugment #" & i & ":  " & objArgs(i)[/green]
        select case lcase(objArgs(i)
            ...
        end select
    next
else
    msgbox "No arguments"
end if

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
oh, and also remove the "on error resume next" . That doesn't help troubleshooting in the slightest!

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
And, "pin to taskbar" should be "Pin to [red]T[/red]askbar"

Code:
If Replace(itemverb.name, "&", "") = "Pin to Taskbar" Then itemverb.DoIt

-Geates


"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Hey there again.
I think you don´t understand me.

The program runs fine so far.


I´ll try to explain it again:

For example:
If you rightclick Adobe Reader 9 and click on Properties you can add something like "xyz.pdf" so it always opens the xyz.pdf when you doubleclick it.
Or you can add "/e,c:\scripts" to the explorer.exe.


Here´s a link so you may understand me:

So I want to pin an application with the arguments to the pinbar.


Thanks and cheers
Checkzen
 
Oh!!

Pinned items are simply a shortcut located in c:\Documents and Settings\User\Application Data\Microsoft\Internet Explorer\Quick Launch. The properties of which can be accessed like so.

Code:
strPinnedFile = "c:\Documents and Settings\Default User\Application Data\Microsoft\Internet Explorer\Quick Launch\adobe.lnk"

Set objLink = objShell.CreateShortcut(strPinnedFile)   
objLink.TargetPath = """C:\Program Files\adobe\reader.exe"" arg1 arg2"
objLink.Save

-Geates


"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Hmm, my WebAccess isn´t working atm.
I´ll try it tommorow.

Anyway, I´ve tried to place an application in the path you´ve stated here a few days ago.
The icon doesn´t get pinned to the taskbar.
Do you have an idea why?


Cheers
Checkzen
 
Hello again :- )

Is there any way I can change the script so I can do it like this? :

Open cmd -> "C:\pin.vbs" "C:\paint.exe /e" -german -pin

?


Cheers
Checkzen
 
Certainly. There are several ways to do this. Because I misunderstood what you originally asked, your own code to assign arguments would work just fine works just fine.

I say this because, based on this thread, you will likely ALWAYS
execute the script using the same order of arguments (PfadEXE will always be the first arg). Therefore, they can be hard-coded (hard-coding is not the best of solutions but is beyond practical in this case).

IF...

you pass absolute values as argument (same argument order)

script.vbs "c:\program.exe" 1 0
script.vbs "c:\program.exe" 0 1
Code:
PfadEXE = objArgs(0)
Sprache = objArgs(1)
PinModus = objArgs(2)

you pass non-absolute values to represent absolute values (same argument order)

script.vbs "c:\program.exe" -german -pin
script.vbs "c:\program.exe" -english -unpin
Code:
PfadEXE = objArgs(0)

Sprache = 1                                   'Default to German
if (objArgs(1) = "-english") then Sprache = 0  'Only change if the second argument (objArgs(1)) = "-english"

PinModus = 1                                  'Default to Pin
if (objArgs(2) = "-unpin") then PinModus = 0   'Only change if the third argument (objArgs(2)) = "-unpin"

you want to pass non-absolute values to represent absolute values in a random order (no identifier arguments) NOTE: the first argument will always be the same, so start assigning with the second argument

script.vbs "c:\program.exe" -english -pin
script.vbs "c:\program.exe" -unpin -germain
script.vbs "c:\program.exe" -foo -bar

Code:
PfadEXE = objArgs(0)
if (objArgs.count > 1) then
    for i = 1 to objArgs.count - 1
        select case lcase(objArgs(i))
            case "-german" : Sprache = 1
            case "-english" : Sprache = 0
            case "-pin" : PinModus = 1
            case "-unpin" : PinModus = 0
            case else : msgbox "Invalid argument:" & objArgs(i) : wscript.quit
        end select
    next
end if

you want to pass non-absolute values to represent absolute values in a random order (with identifier arguments)

However, if the order was different every time, you would need pass "identifiers" (eg -o) arguments to appropriately assign the "real" arguments. NOTE: Because arguments can be any value, there is no way to determine the validity of an argument. "invalid argument" cases must be defined within the scope of the argument being tested (perhaps, beneficially, this allows you to specify different actions with different invalid arguments.)

script.vbs -program "c:\program.exe" -language "english" -action "pin"
script.vbs -action "pin" -program "c:\program.exe" -language "german"
script.vbs -action "delete" -program "c:\program.exe" -language "hebrew"

Code:
if (objArgs.count > 1) then
    for i = 1 to objArgs.count - 1
        select case lcase(objArgs(i))
            case "-language" :
                select case lcase(objArgs(i + 1)
                    case "english" : Sprache = 0
                    case "german" : Sprache = 1
                    case else : msgbox "Invalid language" : wscript.quit
                end select
            case "-action" :
                select case lcase(objArgs(i + 1)
                    case "pin" : PinModus = 1
                    case "unpin" : PinModus = 0
                    case else : msgbox "Invalid action" : wscript.quit
                end select
            case "-program" : PfadEXE = objArgs(i + 1)
        end select
    next
end if

Perhaps, a lot more than than what was request so, to more precisely answer you question, Yes. Use option #2

-Geates

NOTE: I changed argobj to objArgs to coincide with my coding style. They can be changed back, though

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Hey there again :- )

Thanks a lot for trying to help me so hard.
But I´m sorry to say you still didn´t get what I mean.

Maybe I´m wrong, if so, please give me an example what to write in the cmd so the pinned application has an arument like "-e".
You can add arguments with rightclicking the application, go to properties and add any argument (like "-e") behind the "target-path".

I´ve attached a screenshot so you may understand me better.
how-do-i-allocate-more-memory-to-eclipse-02.gif

In this case the shortcut has the arguments "-Xms512m" and "-Xmx1024m"

That´s what I´m looking for.



Thanks :- )


Cheers
Checkzen
 
 http://www.avajava.com/tutorials/eclipse/how-do-i-allocate-more-memory-to-eclipse/how-do-i-allocate-more-memory-to-eclipse-02.gif
We're on the same page but reading different paragraphs. The code I laid out above seems extensive and not conducive to you question but it is. Take your cmd example.

"C:\pin.vbs" "C:\paint.exe /e" -german -pin

If we break it down, the arguments are

"C:\paint.exe /e"
-german
-pin

The -german and -pin arguments are script control options. The first argument is the one you want for the target path.

IF the argument you need is ALWAYS the first one, the script is fairly simple. However, you will still need to use an argument handler in order to read the arguments you pass.

"C:\pin.vbs" "C:\paint.exe /e" -german -pin

Code:
'Argument Handler
PfadEXE = objArgs(0)                       [green]PfadEXE = "C:\paint.exe /e"[/green]
if (objArgs.count > 1) then
    for i = 1 to objArgs.count - 1
        select case lcase(objArgs(i))
            case "-german" : Sprache = 1
            case "-english" : Sprache = 0
            case "-pin" : PinModus = 1
            case "-unpin" : PinModus = 0
            case else : msgbox "Invalid argument:" & objArgs(i) : wscript.quit
        end select
    next
end if

strPinnedFile = "c:\Documents and Settings\Default User\Application Data\Microsoft\Internet Explorer\Quick Launch\paint.lnk"
Set objLink = objShell.CreateShortcut(strPinnedFile)   
[green]objLink.TargetPath = PfadEXE[/green]
objLink.Save

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Argh :/
I´m can´t run the script since I get a runtime-error (mismatch) in line 2.
It says "Types mismatch: 'argobj'.. also tried it with 'objargs'.
Same error.
Code: 800a000d



Cheers
Checkzen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top