Can't get VBS script working with win7 enviromental variable


  1. Posts : 21
    Windows 7 Ultimate x64
       #1

    Can't get VBS script working with win7 enviromental variable


    Hi

    I keep getting error msg when I substitute the path with environmental variable.
    Please advice, Thank you.


    such as
    Set objFolder = objShell.Namespace("C:\Users\Z z z\AppData\Roaming\uTorrent")
    Set objFolder = objShell.Namespace("%APPDATA%\Roaming\uTorrent")


    Set objFolder = objShell.Namespace("C:\Program Files (x86)\uTorrent")
    Set objFolder = objShell.Namespace("%PROGRAMFILES(X86)%\uTorrent")


    =====================

    whole script pin to taskbar


    Dim ObjFolder, ObjFolderItem, colVerbs, objverb, objshell
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace("%PROGRAMFILES(X86)%\uTorrent")
    Set objFolderItem = objFolder.ParseName("uTorrent.exe")
    Set colVerbs = objFolderItem.Verbs
    For Each objVerb in colVerbs
    If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then objVerb.DoIt
    Next
    WScript.Quit
      My Computer


  2. Posts : 10,485
    W7 Pro SP1 64bit
       #2

    The %APPDATA% variable includes the folder named Roaming.


    Maybe...

    Set objFolder = objShell.Namespace("%APPDATA%\Roaming\uTorrent")

    ...should be:

    Set objFolder = objShell.Namespace("%APPDATA%\uTorrent")
      My Computer


  3. Posts : 21
    Windows 7 Ultimate x64
    Thread Starter
       #3

    I tried the variable but unfortunately I still get an error message.

    But using the following exact path it work.

    Set objFolder = objShell.Namespace("C:\Users\Z z z\AppData\Roaming\uTorrent")
    Attached Thumbnails Attached Thumbnails Can't get VBS script working with win7 enviromental variable-untitled.jpg  
      My Computer


  4. Posts : 3,371
    W10 Pro desktop, W11 laptop, W11 Pro tablet (all 64-bit)
       #4

    Try using %%APPDATA%%. It's one % at the command line but %% in a script.
      My Computer


  5. Posts : 21
    Windows 7 Ultimate x64
    Thread Starter
       #5

    I tried

    Set objFolder = objShell.Namespace("%%APPDATA%%\uTorrent")


    still the same error msg
      My Computer


  6. Posts : 10,485
    W7 Pro SP1 64bit
       #6

    I don't know much about VBS, but %appdata% expands correctly in the code below:

    Code:
    Option Explicit
    Dim objWShell
    Set objWShell = WScript.CreateObject("WScript.Shell")
    Dim appData
    appData = objWShell.expandEnvironmentStrings("%APPDATA%")
    msgbox appdata ,0, "expanded"
    The source for most of that code can be found here:
    vbscript - How to Create Folders and Subfolders in %AppData% - Stack Overflow
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 03:42.
Find Us