Solved

VBScript fails when launched via HKLM...Run key

Posted on 2013-05-13
2
405 Views
Last Modified: 2013-05-14
Hello - I am at a loss and am hoping someone might know how to resolve the issue I am having.  The script below is being used to launch an application .exe - hiding the CMD window from the users.  It is being triggered from the registry key "HKLM\Software\Microsoft\CurrentVersion\Run".  This is so that it runs when anyone logs on.

The script works perfectly well as admin or non-admin user when launched manually.  However, it always fails on the "objShell.Run" line when the registry key is used stating that it cannot find the file specified.  I have attempted a 5 second timeout and that did not help either.

The .exe and the .vbs are located in the same sub-directory of "C:\Program Files".

Any ideas would be greatly appreciated!!!

'==== start script ====

Set objShell       = CreateObject("wscript.shell")
Set objFSO       = Createobject("scripting.filesystemobject")
strScriptPath       = objFSO.getabsolutepathname("")
strFileName      = "\AppName.exe"

strCommand = chr(34) & strScriptPath & strFileName & chr(34)

objShell.Run strCommand,0

'==== end script ====
0
Comment
Question by:tneubauertocg
2 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 39163303
Hi, if AppName.exe is in the same folder as the script, then use

strScriptPath       = objFSO.GetParentFolderName(WScript.ScriptFullName)

Regards,

Rob.
0
 

Author Closing Comment

by:tneubauertocg
ID: 39164770
Worked like a charm - thank you!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 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

20 Experts available now in Live!

Get 1:1 Help Now