Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBScript fails when launched via HKLM...Run key

Posted on 2013-05-13
2
Medium Priority
?
414 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 2000 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Screencast - Getting to Know the Pipeline
Suggested Courses

773 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