Open Excel With Batch - windows

I am trying to open an excel file for processing using batch. The code I run on batch is correctly opening the file. The problem is when I try to trigger the same batch file remotely using Jenkins(I have a windows slave). The Jenkins job gets stuck infinitely there after running the command. It does nothing, just shows a message on the screen that says: "A program running on this computer is trying to display a message."[can't post image because of low reputation],
and nothing more.
On clicking view message you get a message that Excel cannot open this file because of the following reasons. which is, i know nothing but a false alarm. How can I modify batch command or Jenkins job or something else on the virtual machine to make the code run?
This is my current command:
"C:\Program Files\Microsoft Office\Office15\EXCEL" /r "C:\file_name.xlsm"

The solution that worked for me was to create a folder named "Desktop" in system32 and SysWow64 (windows 7 64 bit)
C:\Windows\System32\config\systemprofile
C:\Windows\SysWOW64\config\systemprofile
so the full path will be:
C:\Windows\SysWOW64\config\systemprofile\Desktop
C:\Windows\System32\config\systemprofile\Desktop
IIf this doesn't work, you can check the solution by Slav: Open Excel on Jenkins CI.
it pointed me in the right direction

Related

Running a batch file through command prompt - system cannot find the path specified

I am trying to uninstall Oracle on this Windows 7 (64 bit) machine by downloading a standalone tool from Oracle, I need to run a batch file that is supposed to uninstall but I am unable to run it.
I tried to open command prompt as administrator and I am trying to run this as below:
As you can clearly see from the screenshot, I am doing a "dir" on the directory and can clearly see the file right there. Not sure what's going on here.
I also tried to run the batch file by double clicking from Windows Explorer and a terminal window opens and closes quickly but the batch file is not doing what it is supposed to do (it is clearly not executing from Windows Explorer).
Can anyone help me with this?
As theB pointed out above in a comment, this worked for me:
Open the bat file in notepad. I'll bet it starts with #echo off, and
that the error is actually coming from inside the batch file. The
error if the batch file itself wasn't found is 'X' is not recognized
as an internal or external command, operable program or batch file
'Run as Administrator' changes the current directory. See my answer here
Difference between "%~dp0" and ".\"?

VBS script does not work properly from Task Scheduler in Windows 10

I have a windows server designed to perform mail merges for postal letters.
A outside server generates xls data sheets and SFTPS them to my windows server, along with a JSON file with further instructions:
The Letter to merge with (docx file)
An E-mail address to send a PDF of the merged letters.
The script works like this:
1. Constantly(every 60 seconds) monitor directory for JSON files. ->
2. If there is a JSON file, parse it. ->
3. Find XLS file related to that JSON file ->
4. Run VBA/ EXCEL macro to mail merge XLS and the letter into a PDF ->
5. Email PDF to appropriate contact ->
6. Move XLS file to Processed Folder
7. Move JSON file to PRocessed Folder
If I run it manually from the command line it works just fine. However, If I run it from Task Scheduler, either with "RUN" or automatically when the machine restarts or when a given user logs in the script fails. Steps 1, 2, and 3 work. The VBA code/ Macro fails to work.
I'm hoping this can be resolved through configuration of Task Scheduler. Here is my current setup:
Script runs from a bat file, the message script keeps a CMD window open that explains what the script is doing:
cscript C:\automerge\message.vbs
cscript C:\automerge\automerge.vbs >> C:\automerge\logs.log
Task Scheduler Settings:
Run only when user is logged on
Run with Highest Privileges
Configure for Windows 10 (tried using 7 and 8 too)
Trigger:
Trigger at logon - Enabled
Action:
Start a program
Details:
"C:\AutoMerge\JSON Watch.bat"
Conditions:
Start the task only if computer is on AC power
Stop if computer switches to battery power
Settings:
Allow Task to run on demand
If the running task does not end when requested, force it to stop
Can anyone give me advice on how to change the scheduled task or batch file to get this to work?
Try executing like this instead of calling the batch file directly.
32-bit
Action: "%SYSTEMROOT%\system32\cmd.exe /c C:\AutoMerge\JSON Watch.bat"
or 64-bit
Action: "%SYSTEMROOT%\SysWOW64\cmd.exe /c C:\AutoMerge\JSON Watch.bat"
If it is 64-bit... update your cscript to execute %SYSTEMROOT%\SysWOW64\cscript.exe
Turns out Noodles was right it was something in the code.
I created a file system object and used it to get a File.Name. Then I passed this File.Name(without the path) to a function that parses the JSON in the file. This worked just fine when I manually ran it.
JSONExists(File.Name)
In order to run properly from Task Scheduler I had to make sure it passed the entire file name including the path.
FPath = "C:\Automerge\"
JSONExists(FPath & File.Name)
I'm not exactly sure why I need the whole path with Task Scheduler and not when I run manually, but at least now I have a good rule of thumb.

Invalid number of parameters in Batch but not in cmd

I am trying to make a scheduled batch file to run with the volume shadow copy service to copy the outlook.pst file from microsoft outlook.
The commands work properly when i enter them in the command panel but when i setup the same code in a batch file it gives me an invalid number of parameters error in during the second line.
You have to use administrator access on cmd and the batch file for it to even work and i am doing that but i have no clue as to why i get an error only in the batch version but not in cmd?
I found this link helpful.
Its where i found the batch file which simplifies the process incase anyone is wondering.
Heres the code :
CALL MountLatestShadowCopy "C:\MyShadow\"
xcopy /y "C:\MyShadow\Users\%USERNAME%\Documents\Outlookove datoteke\*.pst" "\\hyp\backup"
RMDIR "C:\MyShadow"
pause
Anyone have any ideas as to the cause of my problems? Its supposed to simply copy the .pst file to a server for backup which i will run on a regular schedule.
Outlook is usually the first thing people open when they turn on their computers so i have to use volume shadow copy otherwise getting a copy might be hard on certain computers.
Thanks for the help in advance!

vb6 read and write a text file in win 7

I am trying to execute a .exe file (created by VB6) on Windows 7.
What the application will do is to simply create a text file, and then read the text for a text file.
All the functions are being tested successfully on Windows XP. When I execute the .exe file on Win 7, the functions act as usual but the file I created doesn't exist on the specific path (C:\test.txt). The most weird thing is that I can still read the content from the text file (through the .exe file) despite being unable to find the text file on file explorer.
Then I discovered that I have to choose [run as Administrator] to execute the .exe file, so that the file (test.txt) will be created on the C: drive. I am very curious how the .exe file can still read the text file even it is not existed, and how can I force the .exe file to run as Administrator?
Here is the coding to write and read a file.
Open "C:\" & "test.txt" For Output As #1
Print #1, cDrive.Text
Close #1
Open "C:\" & "test.txt" For Input As #1
Input #1, msg
Close #1
cDrive.Text = msg
Exit Sub
To answer the third remark:
Windows Vista and Windows 7 User Access Control (UAC) introduced a feature called the VirtualStore which is designed to add an extra layer of security protection for applications installed under the Program Files folder. If you search for the file on you hdd you might find a second instance of the file in /User/AppData/Local/VirtualStore
So that's why it is still able to read text.txt allthough is doesn't excist in the location you mentioned.
I suggest that you run the program as an administrator by using the feature in the shortcut (after compiling and installing).
If you asked about it when in debug mode - I believe that if the user that you use to debug is an admin - it's enough.
I have no answer for your question "I am very curious how the .exe file can still read the text file even it is not existed"
You should not specify open as #1 directly, use FreeFile() function instead Look here for a sample.
Good luck
Drive C is being protected by Win7, you can still write to it, but you really shouldn't.
If you want to run the app as admin:
right click on the EXE
select PROPERTIES
go into COMPATABILITY tab
check RUN THIS PROGRAM AS ADMINISTRATOR check box
click OK
Now every time you run the app, it will run as administrator

Running Bat file on Win 7 machine

I have an executeable (Command line which requires arguments/parameters) i need to run on a Win 7 machine. I can run the executeable if i right click and choose run as administrator. Of course, it returns an error code that the required command line parameters were not found. In addition, the executable will create an error log if it has a problem, errors out, throws an exception, etc. I then created a batch file and added MyProgram.exe param to it, and right clicked that and chose run as administrator. I get nothing.....no return code, no error log. I created a shortcut on the desktop to the batch file and changed its advanced properties to run as administrator and still nothing. Anyone have any ideas? I need to run this executable with params from a batch file on a Win 7 machine. Thanx
Edited:
I guess maybe it could be a problem with my Batch file, since i am a novice at those as well. I simply had one line:
MyProgram.exe MyImportFile.txt 1 1
Try creating a shortcut on Desktop to cmd.exe
There you have your commandline. Right click your new shortcut, run as administrator.
Then run your bat file or your exe directly with your parameters.

Resources