Solved

VBScript fails when launched via HKLM...Run key

Posted on 2013-05-13
2
406 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 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

17 Experts available now in Live!

Get 1:1 Help Now