Running Bat file on Win 7 machine - windows-7

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.

Related

Run as Administrator Bat File/ Cmd File Windows 10

I have the following cmd command:
C:\Users\spidey\AppData\Local\Programs\Python\Python39\python C:\Users\spidey\Documents\sleepScript\textdocument.py
Inside a .bat file. When I double click and run it, it runs well but when I try to right click and run as administrator it just opens the window and closes adruptly without completing the execution.
The end result of the command is a text file which is created in first case but not when I try to run it as administrator.
The reason for this to run as adminstrator is because I will be running it on cloud and so there it runs as administrator.
Here are the content of textdocument.py:
import datetime
file = open('read.txt', 'w')
file.write('Executed # ' + str(datetime.datetime.now()))
file.close()
Here is another update:
Tried to create a shortcut and setup it's advanced property as run as administrator. But that doesn't work as well.
After doing this, I tried to run the .bat file again as administrator but no effect.
As suggested in the comments, I shifted all the files to C: drive so that it's accesible to everyone. But unfortunately that didn't work as well window just opens and aprubtly closes without giving the end result. On the other hand normal running works here as well.
Here is the command:
C:\Python\Python39\python C:\uiPath\textdocument.py
After a long debugging, I realized that the command was actually running correctly. It's all that it was saving the file into the other default directory after adding in my python script:
os.chdir(path)
Where path is the path where I wanted it to store. Whereas in case of double clicking and running it, by default that path was set to the path where the file was located in.
The problem got fixed. Thank you everyone for the help!

need help in running a bat file but only after restart (log off/on not included)

i have a certain program that i want to run as windows boots up
but! i need it to be only after windows restart not log off and log on are out of the question - the system i have is running tests and and the app that i want to run is canceling those tests that`s why i need it to run only after windows restarts , so there is no chance that a tests would fail because of it
the .bat file points to the location of
tried shell:common startup but that open the .bat file even after i log off or log on
how do i do this ? i need this to be in a script/.bat file as well
You should add it here
C:\Users\<user name>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
But cause you mentioned after only restart then you will need to run an background script to handle that restart
Or we may..
The common command to restart windows via .bat or cmd file is shutdown -r
So we can create
reboot.bat ,script.bat ,mover.bat > for example in 'C:\test' directory
reboot.bat
move script.bat "C:\Users\<user name>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\script.bat"
shutdown -r
script.bat
: : stuff here..
C:\test\mover.bat
mover.bat
move "C:\Users\<user name>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\script.bat" script.bat
now that we have our scripts let's add them to our Environment variables
From the desktop, right click the Computer icon.
Choose Properties from the context menu.
Click the Advanced system settings link.
Click Environment Variables.
In the section System Variables, find the PATH environment variable
and select it.
Click Edit then add ; following by C:\test Click Ok, Ok etc and
restart your cmd if opened
To answer your question just type reboot.bat or reboot in CMD command-line
Which when you want to run your script after restart you have to type this to cmd or just..make a restart.bat file with this command for just one click
I used stack overflow for android to answer this without test cause i'm not windows but i'm just familiar with plus didn't have my PC at this moment but i hope that answer is clear and understandable

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 ".\"?

Running the cmd in windows command line as admin

Am opening windows cmd.exe as administrator and executing an installer(just call installer.exe) and it runs fine. But if I open the cmd.exe in normal mode ( not as administrator) but run the command as user administrator ( runas /profile /user:adminstrator installer.exe) am not able to execute the installer successfully.
The installer unpacks certain files in c:\users\ dir.
The error that I get is :
"Error running java -Dpython.console.encoding=UTF-8 -jar C:\users\<username>/tools/x.jar : Program ended with an error exit code. "
How can I solve this issue? Since am trying to automate executing this installer, opening the cmd.exe as admin is out of question. I would like to run the command as a normal user or if not possible, as an admin.
Am new to Windows. Any help is appreciated.
Thanks
You could create the .bat file with the line you want to run, then follow the procedures listed below to have it automatically run as an administrator.
Right click on the original file and click Create shortcut.
Right click on the shortcut and select the properties option.
Under the shortcut tab, click on the advanced button in the bottom right hand corner.
Check the box that says run as administrator
Click ok, and then ok.
Now when you double click on the batch file shortcut it will run as an administrator. You can delete the original if you wish to.

Open Excel With Batch

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

Resources