Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

.vbs script to run a file

Posted on 2009-05-18
8
Medium Priority
?
459 Views
Last Modified: 2012-05-07
I'd like a simple .vbs script that launches a file "MyAutoHotkeyScript.ahk"

The script below I found which originally launched "calc.exe" . I replaced "calc.exe" with the full path/filename of MyAutoHotkeyScript.ahk, but nothing happens.

(P.S. I know nothing about .vbs script files. Where's some good documentation for beginners? [I'm good at other languages.])
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
 
errResult = objWMIService.Create("C:\\Users\\Public\\_zProgramFiles\\AutoHotKey\\MyAutoHotkeyScript.ahk", null, null, intCalcID)

Open in new window

0
Comment
Question by:deleyd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 7

Expert Comment

by:Hubasan
ID: 24412529
Hi deleyd,

just replace sPath variable with the path to your script. This will only work if, when you double-click on your .ahk script, it launches in default script program.

Here try this:
Set oWS = CreateObject("WScript.Shell")
 
sPath = "C:\Windows\notepad.exe"
 
errResult = oWS.Run(sPath,,False)

Open in new window

0
 
LVL 7

Expert Comment

by:Hubasan
ID: 24412545
As for learning how to script, here is a good start for Visual Basic Scripting:

http://www.microsoft.com/technet/scriptcenter/guide/sagsas_overview.mspx?mfr=true
0
 

Author Comment

by:deleyd
ID: 24414467
I tried this but it can't find the file.

Also tried doubling the backslashes,
sPath = "C:\\Documents and Settings\\Owner\\My Documents\\_zProgramFiles\\AutoHotKey\\idletime.ahk"
but it still complained it couldn't find the file.


Set oWS = CreateObject("WScript.Shell")
sPath = "C:\Documents and Settings\Owner\My Documents\_zProgramFiles\AutoHotKey\idletime.ahk"
errResult = oWS.Run(sPath,,False)

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 7

Accepted Solution

by:
Hubasan earned 2000 total points
ID: 24414514
Here try this one:

I have added additional double quotes since your path has spaces in it:
Set oWS = CreateObject("WScript.Shell")
sPath = chr(34) & "C:\Documents and Settings\Owner\My Documents\_zProgramFiles\AutoHotKey\idletime.ahk" & Chr(34)
errResult = oWS.Run(sPath,,False)

Open in new window

0
 

Author Comment

by:deleyd
ID: 24414732
I see, chr(34) is the clever way of adding another double-quote.

What character is used to comment out a line in a .vbs script file?
0
 
LVL 7

Expert Comment

by:Hubasan
ID: 24414891
You can use apostrophe character. On US keyboard it would be right of the colon/semi-colon key.
Example:

'this line is comented out
0
 
LVL 7

Expert Comment

by:crokeefe28
ID: 24416054
try this
Set objApp = CreateObject("Wscript.Shell") 
objApp.Run "C:\Users\Public\_zProgramFiles\AutoHotKey\MyAutoHotkeyScript.ahk"

Open in new window

0
 
LVL 7

Expert Comment

by:crokeefe28
ID: 24416064
by chance....does the app run in a command windows?  If so, then try this:



Set objApp = CreateObject("Wscript.Shell") 
objApp.Run "cmd /c C:\Users\Public\_zProgramFiles\AutoHotKey\MyAutoHotkeyScript.ahk"

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question