Run exe file created from VB Script with no interaction

Hi

I have created an exe file (converted from vbscript to protect any changes in code, by mistake or otherwise). This script (vbscript) can be used with "cscript from command prompt and pipe the results in a text file in the same location from where it ran. After changing to exe, now this starts with WSH by default and when tries to run using cscript parameter gives error:
"Input Error: There is no script engine for file extension ".exe".
I am tried using batch script to call exe and pipe result in txt, did not help.
Here is what I need, any help is much appreciated.
VBScript gives output in command prompt when run in cscript and result can be piped into a text file.
Vbscript converted to exe
Now run this exe (by any script or method), should not be interactive, quietly runs or show progress on screen and display message when complete and result is saved in text file (result from vbscript/exe)

Thanks for help
mohi09Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michael PfisterCommented:
What did you use to convert the VBS to an EXE? If it doesn't h ave the option to use cscript instead of wscript, you may need to write to the output file in your script.
maybe running a

cscript //H:CScript
helps, but this is just a guess.

If you need to write to a text file from VBScript, see http://www.computerperformance.co.uk/vbscript/vbscript_file_opentextfile.htm
0
mohi09Author Commented:
Hi

I used vbsEdit tool which have option to convert vbscript to an exe.
When I exceute this it starts, could not force to start with cscript. With cscript I can give parameter to pipe the result in text file.
If there is any code I add vbscript itself before converting to exe which can do this two steps:
Write to a text file from same location where it run and
Run quietly and notify when complete.
Thanks
0
RobSampsonCommented:
Hi, you can try adding this block of code to the top of your code before compiling it:

'==============
If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then
    strPath = Wscript.ScriptFullName
    strCommand = "%comspec% /c cscript  """ & strPath & """"
   Set objShell = CreateObject("Wscript.Shell")
    objShell.Run(strCommand), 1, True
    Wscript.Quit
End If

' Rest of normal code goes here

'==============

Then, when you run it just by double-clicking the EXE, it will detect which engine it's using, and force it to use CScript. I'm not sure though, that the pipe will work just yet, we may need to build that into the block above as well...

Regards,

Rob.
0
mohi09Author Commented:
Hi
That is good but it is not piping the result to text file. Now what did is added the code to write in text file to avoid the piping stuff. With this I don't need to switch the script host. I want to create and write the text file to the same location from where the exe is execute. if it is on desktop then the text file should be on the desktop. Right now I am doing to the fixed path in root which is not desirable depending on the machine this script need to run

strFile = "UserList.txt"
strWritePath = "C:\" & strFile
strDirectory = "C:\"
Set objFSO1 = CreateObject("Scripting.FileSystemObject")
If objFSO1.FileExists(strWritePath) Then
Set objFolder = objFSO1.GetFile(strWritePath)
Else
    Set objFile = objFSO1.CreateTextFile(strDirectory & strFile)
      objFile = ""
End If
Set fso = CreateObject("Scripting.FileSystemObject")
Set textFile = fso.OpenTextFile(strWritePath, OPEN_FILE_FOR_WRITING)
 
=============
Code
============
 
textFile.WriteLine("User : " & objUser.sAMAccountName ") 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RobSampsonCommented:
Hi, I don't think you need to test if the file exists first, seeing as you're opening it for writing anyway, it will just overwrite the file, so instead, we can just use CreateTextFile, forcing it to overwrite in the first place.

Anyway, I've added strCurrentDir, which points to the folder that the script is running from.

Regards,

Rob.
Const OPEN_FILE_FOR_WRITING = 1
strCurrentDir = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
strFile = "UserList.txt"
strWritePath = strCurrentDir & "\" & strFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set textFile = objFSO.CreateTextFile(strWritePath, OPEN_FILE_FOR_WRITING, True)
 
'=============
'Code
'============
 
textFile.WriteLine("User : " & objUser.sAMAccountName)

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.