1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

How to make a VBS commmand to open a file

Discussion in 'Software Development' started by simr, Dec 16, 2013.

Thread Status:
Not open for further replies.
Advertisement
  1. simr

    simr Thread Starter

    Joined:
    May 12, 2013
    Messages:
    994
    Hi, I would like to create a .vbs file using VBScript, and the task should be that if a certain file/folder is selected then a specific file should be executed. For instance, if file/folder X is selected then a certain sound effect or message box or any other file that I put in to the code should be activated/executed/automatically opened.

    Does anybody know how to create such a VBScipt code?

    Is it also possible to create a batch file or Command Prompt - command that could do it?

    Thank you in advance! :)
     
  2. simr

    simr Thread Starter

    Joined:
    May 12, 2013
    Messages:
    994
    Thank you MelisaStewart!

    If you can elaborate and explain a little more, I would appreciate it, since I don't fully understand what you mean.

    Thanks again.
     
  3. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    So from what I understand you want to run the VBS script and have the user to be prompted with a dialogue to select a file/folder before taking the appropriate action? Is there any particular reason you want this to be done using a stand-alone VBS script instead of a VBA macro instead which is normally run from MS Office applications and is more versatile in my opinion

    If you can provide a few more details on how you plan on using the code in a real-world scenario it would make it easier to offer suggestions. Also please indicate what operating system you are using.


    Rollin
     
  4. simr

    simr Thread Starter

    Joined:
    May 12, 2013
    Messages:
    994
    Thank you Rollin!

    I have a Vista.

    Let me give you an example of what I want to do with the VBS file. One of the things I'd like to do is create a VBS file, Batch file using a Command Prompt line or a HTA file (using HTML application) which will make that when someone opens folder X or file Y, a message box should appear, or a sound effect should happen (from a pre-arranged audio file) or a video/music file should start playing, or really any effect that I want to happen should occur as a result of said folder/file being double clicked on.

    Another example of what I'd like to do is to create a file (again VBS, Batch or HTA) that will change the target of a shortcut when I click on the VBS/Batch/HTA file. An example of a shortcut target change would be from:
    "C:\Windows\nircmd.exe standby"
    to
    "C:\Windows\nircmd.exe hibernate"
    In other words, the shortcut uses the same program but the function changes. Or for that matter, to change the whole address to something else entirely.

    One more example, I'd like to know what the VBS/Batch/HTA code is that causes a file/folder/program to close when another one is opened, i.e. opening file/folder/program A will close file/folder/program B.

    Thank you again!
     
  5. Triple6

    Triple6 Moderator

    Joined:
    Dec 26, 2002
    Messages:
    52,805
    First Name:
    Rob
    Ignore that post, it's just a brainless spammer.
     
  6. simr

    simr Thread Starter

    Joined:
    May 12, 2013
    Messages:
    994
    Well I was indeed struggling to understand what MelisaStewart was saying in his (now deleted) post.
    I see now that I wasn't the only one with difficulty understanding it.
    (Perhaps MelisaStewart can write in now and clarify what he meant there.)
     
  7. Triple6

    Triple6 Moderator

    Joined:
    Dec 26, 2002
    Messages:
    52,805
    First Name:
    Rob
    Spammers are banned, they will not be returning to clarify anything.
     
  8. TonyB25

    TonyB25 Banned

    Joined:
    Dec 31, 1969
    Messages:
    2,540
    In order for something to happen when a file or folder is selected, it would have to be running as a service and intercept calls to Explorer.exe. I don't think you can do that with a simple script file.
     
  9. simr

    simr Thread Starter

    Joined:
    May 12, 2013
    Messages:
    994
    What about with HTA?
    And what about changing the target of a shortcut?
     
  10. TonyB25

    TonyB25 Banned

    Joined:
    Dec 31, 1969
    Messages:
    2,540
    I don't know what HTA is. Making a shortcut won't intercept Explorer calls or run as a service. What you want to do is probably more complicated than you're thinking.
     
  11. simr

    simr Thread Starter

    Joined:
    May 12, 2013
    Messages:
    994
    HTA stands for HTML Application, it's how you make HTML pages for the web, but you could also make functions for your PC which doesn't involve the web using HTA.
     
  12. simr

    simr Thread Starter

    Joined:
    May 12, 2013
    Messages:
    994
    You can for instance change multiple file names with a simple Command line even though those files aren't running. Apparently there are things you can do to files that aren't running. I assume that the same is true for VBScript.
     
  13. TonyB25

    TonyB25 Banned

    Joined:
    Dec 31, 1969
    Messages:
    2,540
    Changing file names is different from performing an action when a file is accessed. To do that, the program has to be running at all times so it can monitor what folders are being opened.
     
  14. simr

    simr Thread Starter

    Joined:
    May 12, 2013
    Messages:
    994
    What about doing this? I assume that this is just like changing file names.
    Thank you TonyB25!
     
  15. TonyB25

    TonyB25 Banned

    Joined:
    Dec 31, 1969
    Messages:
    2,540
    You change the shortcut path by right-clicking on a file, and clicking Properties, and then changing the path. At what point is your custom program supposed to take over? How is it monitoring Windows to know someone right-clicked on that shortcut?
     
  16. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1115437

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice