I'm trying to create a script to copy a secure exe file to the C directory from a flash drive that is assigned the drive letter D. Then to run the exe, delete the exe, then shut down the PC. I have technicians who need to do this in order to make a biometric reader function properly. They keep screwing up the process and I would like to automate the process to save me a headache. The file is secure and cannot be leaked to our customers due to licensing. I already tried a batch script, but the exe doesn't seem to launch correctly.
Here's what I had:
COPY "D:\Biometric\software.exe" "C:\software.exe"
Pause
pushd C:\
Start "C:\software.exe"
Pause
pushd C:\
erase "software.exe" /F /Q
Pause
c:\windows\system32\shutdown -s -f -t 00
I've never tried VBScript, and I figured maybe that might get me the results I need, any help would be appreciated.
Start considers the first set of quotes it finds to be the window's title, so what you have in your code essentially says "set the window's title to 'C:\software.exe' and then execute the start command on nothing."
Insert an extra set of quotes to make the start command work.
start "" "C:\software.exe"
Related
I have a batch file, whose purpose is to copy a directory from a network location and place it in the C: location of the user's system if it doesn't already exist. The problem is when the main user attempts this, the above message is displayed and the application subsequently errors out. BUT, when I run on my machine, to try and debug, it works just as it should with no problems.
I've seen a lot out there on this, but none where it works depending on the user. Also, most are about only working with network drives and not locals.
Here is the code. I am not the author of this .bat so let me know if something doesn't look quite right.
#echo off
echo Starting Application...
rem copy files over to the users local computer to prevent .dll problems when running App
C:
CD \
if not exist "C:\App" mkdir c:\App
CD App
robocopy "\\server\shared\fuller\Apps\ThisApp" c:\App /S robocopy.log
echo You may close this window or it will close by itself when the program is done.
ThisApp1.exe
I've tried using popd and pushd in various spots, but I'm not sure where I would put those, or even if it's applicable to this situation.
Put this line as the 2nd line (right after #echo off)
pushd %~dp0 & REM needed in case 'Run as Administrator' or executed from network drive
https://ss64.com/nt/pushd.html
Note that 'Run as Administrator' changes the current directory... this will put it back to where it was.
We use a batch file as a deployment script for installation of software in a new system. Quite often the batch script will randomly pause until a keypress is present (i.e. the console window is active and a physical key is pressed).
I'm just wondering if anyone has ever come across this? The pause happens at different stages and times while executing the script.
The code format is as below:
cd <folder1>
"Setup.exe"
cd..
cd <folder2>
"Setup.exe"
cd..
cd <folder3>
"Setup.exe"
cd..
...
I guess it's similar to this question. In my case, the batch script is the only substantial process running, otherwise the computer would sit idle.
So I tried and tried but couldn't figure out this one for some reason.
how can I run a task from a desired directory instead of System32 directory where cmd.exe is.
so, when I schedule a task and try to run it ..
command prompt suppose to go to "c:\users\aaa\bbb\ccc" and then pass the argument.
Instead, It's starts at c:\Windows\System32 and fails.
Could anybody help me with this please?
I really appreciate it.
Thank you.
EDIT --
so, now I have a run.bat file with following content in it ...
C:\Users\aaa\bbb\ccc\dd (location to my testrunner.bat file)
testrunner.bat Scripts/all.suite website-address ie (command for the task I wanna perform)
net stop schedule (since window is poping up and going away way to fast, I added this to stop it (not working))
type run.bat
#echo off
cd C:\Users\aaa\bbb\ccc\dd
rem this will show all files in dir
rem is the file you're expecting listed?
dir
rem notice how you can make comments with a leading rem(ark)
#echo starting scripts\all.suite
rem you have to change this to have the full path using Windows X:\dir\dir conventions
c:\home\Scripts\all.suite website-address
#echo done running scripts\all.suite website-address
#echo shutting down
net stop schedule
So its still not clear exactly to me your goal. The reason I added the cd c:\... command is that will **C**hange **D**irectory to the path specified.
This is what you need so you can "run a task from a desired directory instead of System32".
Copy everything from the first #echo off to the last net stop and using notepad, paste it into a file, fix command names and paths website-urls, etc, then save that file to c:\temp\testrunner.bat.
Open a cmd.exe window and test that the script works. Just paste c:\temp\testrunner.bat on to cmd-line and hit enter. If that works, then made an entry in the scheduler to run c:\temp\testrunner.bat . I don't know the specifics of running a script for scheduler, so look for clues on the input screen. Is the an option to run 'now'?
If the .bat file doesn't work from the command-line, then you have to fix the file before you try running it in the scheduler. As your command Scripts/all.suite website-address is a little vague, you'll do better to post a new question asking for help to fix the .bat file and use a sample command that people will be able to use on their PCs at home.
IHTH.
We need to disconnect and re-map a network drive on Windows 7, using a set of scripts (or an app) that runs off the same network path.
That is, I need something that loads itself into RAM before it runs, so it continues to run after the drive is disconnected.
Any ideas?
Please note that 16-bit apps are NOT supported in 64 bit systems (this explains why the Novell utility failed).
You would need a vbs file running throughout a logon session to remap drives if it's disconnected by user. Need to make this script to run when domain user logs on - e.g. Logon Script in AD or GPO. There are many ways to do it.
You could even disable "Remove Network drives" feature from Explorer GUI via GPO or Reg key (net use command still works).
Or you can tweak solution by Julius for this SO question to fit your need. But consider performance impact of the vbs - only check every n minute(s) in an infinite loop.
We do something similar. We have a batch file on the network that maps the drives a user needs. We update the batch file from time to time, and users run it from a shortcut that we've placed on their desktop:
C:\WINDOWS\system32\cmd.exe /c (#echo off&if not exist \\172.x.x.x\Login (echo Unable to access server&pause) else (md c:\TMP > NUL 2>&1 © \\172.x.x.x\Login\MapDrives.bat C:\TMP /y > NUL 2>&1 &call C:\TMP\MapDrives.bat&del C:\TMP\MapDrives.bat&rd c:\TMP))
You can see that it checks to see if they can access the server, and if they can, it creates a folder C:\TMP, copies the MapDrives.bat file locally, then runs it. Since it is running locally, it can remap network drives without terminating it own execution. And we can update the batch file on the server without pushing it to each user's computer.
If you don't want to create a shortcut with the long command line above, it might work to create a second batch file on the server (e.g., RunMe.bat) that users run from the server. You could place all of the code from the shortcut in the RunMe.bat and accomplish the same thing. Of course, you'd want to add one more line of code to change to the local drive (so Windows doesn't hold open a handle to the network drive). Something like this:
#echo off
C:
if not exist \\172.x.x.x\Login\MapDrives.bat (
echo Unable to access server
pause
) else (
md c:\TMP > NUL 2>&1
copy \\172.x.x.x1\Login\MapDrives.bat C:\TMP /y > NUL 2>&1
C:\TMP\MapDrives.bat
)
I kept the if not exist ... because you might place the RunMe.bat in a different location than the MapDrives.bat, so it still makes sense to verify the user can access the file. Because I didn't use call C:\TMP\MapDrives.bat, it transfers control to the local batch file and any handles to the server should be closed so the drive can be remapped. This means however, that you cannot place more commands after the C:\TMP\MapDrives.bat command.
I'm trying to make a batch file that executes a simple command:
shutdown -h
I've created a shutdown.bat file with that exact line in it, yet when I run it, all it does is spam the command prompt like crazy.
I've looked at batch file sites, #echo off seems popular, but doesn't that just hide output while the commands are executed just the same?
It turns out that adding a change directory command to the root of the drive fixes the problem. The final text that I ended up using in the .bat file was:
cd c:\
shutdown /h
I believe I am very late for this but just in case someone else comes across this.
The issue was indeed with the name of the bat file. You were calling shutdown -h and the bat file was called shutdown.bat hence the bat file was calling itself causing the loop of the command prompts. To fix this you either rename the bat file or specify the directory where shutdown is located.
Would love to say I figured this out but I simply googled it.
The code you need is
%windir%System32rundll32.exe powrprof.dll,SetSuspendState
If you go to start -> run and then type this in it should work.
So if you have hibernate enabled in the poweroptions this should also work in a batch file.
Hope this helped you
Edit:
P.s. click the white little V under the arrows (left of this answer) to accept the answer ;)
For shutdown:
c:\windows\system32\shutdown -s -f -t 00
(or do ...shutdown -p -f).
E.g.: set the time -t 1000 and save and run it.
To abort just c:\windows\system32\shutdown -a in different batch file.
Very important point to note: if you locate this batch file in your startup then it will execute the s/h/r immediately. E.g. you create a logoff batch file and you locate it in startup
it will logoff the pc within the given time/immediately. However, when you hold shift when logging then it will abort the logoff batch file otherwise you pc will logoff again and again. You don't have to do this I am not sure if it works on every PC.
Create a user and try it there in case you could not log in. good luck
For restart:
c:\windows\system32\shutdown -r -t 00
For hibernate:
c:\windows\system32\shutdown /h
Reference: https://www.instructables.com/id/Shutdown-restart-or-hibernate-your-computer-on-a/