Solved

.vbs script to run a file

Posted on 2009-05-18
8
444 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
  • 4
  • 2
  • 2
8 Comments
 
LVL 7

Expert Comment

by:Hubasan
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 7

Accepted Solution

by:
Hubasan earned 500 total points
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:deleyd
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now